Skip to content

Commit e83d25f

Browse files
committed
add info cmd
1 parent 14ca705 commit e83d25f

File tree

14 files changed

+922
-658
lines changed

14 files changed

+922
-658
lines changed

api/api_curio.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/filecoin-project/go-address"
99
"github.com/filecoin-project/go-state-types/abi"
1010

11+
ltypes "github.com/filecoin-project/curio/api/types"
1112
storiface "github.com/filecoin-project/curio/lib/storiface"
1213

1314
"github.com/filecoin-project/lotus/api"
@@ -19,10 +20,11 @@ type Curio interface {
1920
// MethodGroup: Curio
2021
//The common method group contains administration methods
2122

22-
Version(context.Context) ([]int, error) //perm:admin
23-
Shutdown(context.Context) error //perm:admin
24-
Cordon(context.Context) error //perm:admin
25-
Uncordon(context.Context) error //perm:admin
23+
Version(context.Context) ([]int, error) //perm:admin
24+
Shutdown(context.Context) error //perm:admin
25+
Cordon(context.Context) error //perm:admin
26+
Uncordon(context.Context) error //perm:admin
27+
Info(ctx context.Context) (*ltypes.NodeInfo, error) //perm:read
2628

2729
// MethodGroup: Deal
2830
//The deal method group contains method for adding deals to sector

api/proxy_gen.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/types/types.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package types
2+
3+
import "time"
4+
5+
type NodeInfo struct {
6+
ID int
7+
CPU int
8+
RAM int64
9+
GPU float64
10+
HostPort string
11+
LastContact time.Time
12+
Unschedulable bool
13+
14+
Name string
15+
StartupTime time.Time
16+
Tasks string
17+
Layers string
18+
Miners string
19+
}

build/openrpc/curio.json

Lines changed: 99 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
"deprecated": false,
313313
"externalDocs": {
314314
"description": "Github remote link",
315-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L323"
315+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L327"
316316
}
317317
},
318318
{
@@ -335,7 +335,91 @@
335335
"deprecated": false,
336336
"externalDocs": {
337337
"description": "Github remote link",
338-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L334"
338+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L338"
339+
}
340+
},
341+
{
342+
"name": "Filecoin.Info",
343+
"description": "```go\nfunc (s *CurioStruct) Info(p0 context.Context) (*ltypes.NodeInfo, error) {\n\tif s.Internal.Info == nil {\n\t\treturn nil, ErrNotSupported\n\t}\n\treturn s.Internal.Info(p0)\n}\n```",
344+
"summary": "",
345+
"paramStructure": "by-position",
346+
"params": [],
347+
"result": {
348+
"name": "*ltypes.NodeInfo",
349+
"description": "*ltypes.NodeInfo",
350+
"summary": "",
351+
"schema": {
352+
"examples": [
353+
{
354+
"ID": 123,
355+
"CPU": 123,
356+
"RAM": 9,
357+
"GPU": 1,
358+
"HostPort": "string value",
359+
"LastContact": "0001-01-01T00:00:00Z",
360+
"Unschedulable": true,
361+
"Name": "string value",
362+
"StartupTime": "0001-01-01T00:00:00Z",
363+
"Tasks": "string value",
364+
"Layers": "string value",
365+
"Miners": "string value"
366+
}
367+
],
368+
"additionalProperties": false,
369+
"properties": {
370+
"CPU": {
371+
"title": "number",
372+
"type": "number"
373+
},
374+
"GPU": {
375+
"type": "number"
376+
},
377+
"HostPort": {
378+
"type": "string"
379+
},
380+
"ID": {
381+
"title": "number",
382+
"type": "number"
383+
},
384+
"LastContact": {
385+
"format": "date-time",
386+
"type": "string"
387+
},
388+
"Layers": {
389+
"type": "string"
390+
},
391+
"Miners": {
392+
"type": "string"
393+
},
394+
"Name": {
395+
"type": "string"
396+
},
397+
"RAM": {
398+
"title": "number",
399+
"type": "number"
400+
},
401+
"StartupTime": {
402+
"format": "date-time",
403+
"type": "string"
404+
},
405+
"Tasks": {
406+
"type": "string"
407+
},
408+
"Unschedulable": {
409+
"type": "boolean"
410+
}
411+
},
412+
"type": [
413+
"object"
414+
]
415+
},
416+
"required": true,
417+
"deprecated": false
418+
},
419+
"deprecated": false,
420+
"externalDocs": {
421+
"description": "Github remote link",
422+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L349"
339423
}
340424
},
341425
{
@@ -371,7 +455,7 @@
371455
"deprecated": false,
372456
"externalDocs": {
373457
"description": "Github remote link",
374-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L345"
458+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L360"
375459
}
376460
},
377461
{
@@ -425,7 +509,7 @@
425509
"deprecated": false,
426510
"externalDocs": {
427511
"description": "Github remote link",
428-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L356"
512+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L371"
429513
}
430514
},
431515
{
@@ -448,7 +532,7 @@
448532
"deprecated": false,
449533
"externalDocs": {
450534
"description": "Github remote link",
451-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L367"
535+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L382"
452536
}
453537
},
454538
{
@@ -487,7 +571,7 @@
487571
"deprecated": false,
488572
"externalDocs": {
489573
"description": "Github remote link",
490-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L378"
574+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L393"
491575
}
492576
},
493577
{
@@ -526,7 +610,7 @@
526610
"deprecated": false,
527611
"externalDocs": {
528612
"description": "Github remote link",
529-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L389"
613+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L404"
530614
}
531615
},
532616
{
@@ -720,7 +804,7 @@
720804
"deprecated": false,
721805
"externalDocs": {
722806
"description": "Github remote link",
723-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L400"
807+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L415"
724808
}
725809
},
726810
{
@@ -852,7 +936,7 @@
852936
"deprecated": false,
853937
"externalDocs": {
854938
"description": "Github remote link",
855-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L411"
939+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L426"
856940
}
857941
},
858942
{
@@ -986,7 +1070,7 @@
9861070
"deprecated": false,
9871071
"externalDocs": {
9881072
"description": "Github remote link",
989-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L422"
1073+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L437"
9901074
}
9911075
},
9921076
{
@@ -1040,7 +1124,7 @@
10401124
"deprecated": false,
10411125
"externalDocs": {
10421126
"description": "Github remote link",
1043-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L433"
1127+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L448"
10441128
}
10451129
},
10461130
{
@@ -1074,7 +1158,7 @@
10741158
"deprecated": false,
10751159
"externalDocs": {
10761160
"description": "Github remote link",
1077-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L444"
1161+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L459"
10781162
}
10791163
},
10801164
{
@@ -1151,7 +1235,7 @@
11511235
"deprecated": false,
11521236
"externalDocs": {
11531237
"description": "Github remote link",
1154-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L455"
1238+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L470"
11551239
}
11561240
},
11571241
{
@@ -1174,7 +1258,7 @@
11741258
"deprecated": false,
11751259
"externalDocs": {
11761260
"description": "Github remote link",
1177-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L466"
1261+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L481"
11781262
}
11791263
},
11801264
{
@@ -1212,7 +1296,7 @@
12121296
"deprecated": false,
12131297
"externalDocs": {
12141298
"description": "Github remote link",
1215-
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L477"
1299+
"url": "https://github.com/filecoin-project/curio/blob/master/api/proxy_gen.go#L492"
12161300
}
12171301
}
12181302
]

cmd/curio/cli.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ var cliCmd = &cli.Command{
201201
return nil
202202
},
203203
Subcommands: []*cli.Command{
204+
infoCmd,
204205
storageCmd,
205206
logCmd,
206207
waitApiCmd,

cmd/curio/info.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/dustin/go-humanize"
7+
"github.com/urfave/cli/v2"
8+
9+
"github.com/filecoin-project/curio/cmd/curio/internal/translations"
10+
"github.com/filecoin-project/curio/cmd/curio/rpc"
11+
)
12+
13+
type nodeInfo struct {
14+
Version string
15+
Schedulable bool
16+
}
17+
18+
var infoCmd = &cli.Command{
19+
Name: "info",
20+
Usage: translations.T("Get Curio node info"),
21+
Action: func(cctx *cli.Context) error {
22+
api, closer, err := rpc.GetCurioAPI(cctx)
23+
if err != nil {
24+
return err
25+
}
26+
defer closer()
27+
28+
info, err := api.Info(cctx.Context)
29+
if err != nil {
30+
return err
31+
}
32+
fmt.Printf("Node Info:\n")
33+
fmt.Printf("ID: %d\n", info.ID)
34+
fmt.Printf("Name: %s\n", info.Name)
35+
fmt.Printf("CPU: %d\n", info.CPU)
36+
fmt.Printf("RAM: %s\n", humanize.Bytes(uint64(info.RAM)))
37+
fmt.Printf("GPU: %.2f\n", info.GPU)
38+
fmt.Printf("Schedulable: %t\n", !info.Unschedulable)
39+
fmt.Printf("HostPort: %s\n", info.HostPort)
40+
fmt.Printf("Tasks: %s\n", info.Tasks)
41+
fmt.Printf("Layers: %s\n", info.Layers)
42+
fmt.Printf("Miners: %s\n", info.Miners)
43+
fmt.Printf("LastContact: %s\n", info.LastContact)
44+
fmt.Printf("StartupTime: %s\n", info.StartupTime)
45+
return nil
46+
},
47+
}

0 commit comments

Comments
 (0)