@@ -3,12 +3,10 @@ package machine
33import (
44 "context"
55 "fmt"
6- "time"
76
87 "github.com/spf13/cobra"
98
109 "github.com/oasisprotocol/oasis-core/go/common/cbor"
11- "github.com/oasisprotocol/oasis-sdk/client-sdk/go/client"
1210 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/connection"
1311 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/rofl"
1412 "github.com/oasisprotocol/oasis-sdk/client-sdk/go/modules/roflmarket"
@@ -21,135 +19,6 @@ import (
2119)
2220
2321var (
24- showCmd = & cobra.Command {
25- Use : "show [<machine-name>]" ,
26- Short : "Show information about a machine" ,
27- Args : cobra .MaximumNArgs (1 ),
28- Run : func (_ * cobra.Command , args []string ) {
29- _ , deployment , npa := roflCommon .LoadManifestAndSetNPA (& roflCommon.ManifestOptions {
30- NeedAppID : true ,
31- NeedAdmin : false ,
32- })
33-
34- machine , machineName , machineID := resolveMachine (args , deployment )
35-
36- // Establish connection with the target network.
37- ctx := context .Background ()
38- conn , err := connection .Connect (ctx , npa .Network )
39- cobra .CheckErr (err )
40-
41- // Resolve provider address.
42- providerAddr , _ , err := common .ResolveLocalAccountOrAddress (npa .Network , machine .Provider )
43- if err != nil {
44- cobra .CheckErr (fmt .Sprintf ("Invalid provider address: %s" , err ))
45- }
46-
47- insDsc , err := conn .Runtime (npa .ParaTime ).ROFLMarket .Instance (ctx , client .RoundLatest , * providerAddr , machineID )
48- cobra .CheckErr (err )
49-
50- insCmds , err := conn .Runtime (npa .ParaTime ).ROFLMarket .InstanceCommands (ctx , client .RoundLatest , * providerAddr , machineID )
51- cobra .CheckErr (err )
52-
53- fmt .Printf ("Name: %s\n " , machineName )
54- fmt .Printf ("Provider: %s\n " , insDsc .Provider )
55- fmt .Printf ("ID: %s\n " , insDsc .ID )
56- fmt .Printf ("Offer: %s\n " , insDsc .Offer )
57- fmt .Printf ("Status: %s\n " , insDsc .Status )
58- fmt .Printf ("Creator: %s\n " , insDsc .Creator )
59- fmt .Printf ("Admin: %s\n " , insDsc .Admin )
60- switch insDsc .NodeID {
61- case nil :
62- fmt .Printf ("Node ID: <none>\n " )
63- default :
64- fmt .Printf ("Node ID: %s\n " , insDsc .NodeID )
65- }
66-
67- fmt .Printf ("Created at: %s\n " , time .Unix (int64 (insDsc .CreatedAt ), 0 ))
68- fmt .Printf ("Updated at: %s\n " , time .Unix (int64 (insDsc .UpdatedAt ), 0 ))
69- fmt .Printf ("Paid until: %s\n " , time .Unix (int64 (insDsc .PaidUntil ), 0 ))
70-
71- if len (insDsc .Metadata ) > 0 {
72- fmt .Printf ("Metadata:\n " )
73- for key , value := range insDsc .Metadata {
74- fmt .Printf (" %s: %s\n " , key , value )
75- }
76- }
77-
78- fmt .Printf ("Resources:\n " )
79-
80- fmt .Printf (" TEE: " )
81- switch insDsc .Resources .TEE {
82- case roflmarket .TeeTypeSGX :
83- fmt .Printf ("Intel SGX\n " )
84- case roflmarket .TeeTypeTDX :
85- fmt .Printf ("Intel TDX\n " )
86- default :
87- fmt .Printf ("[unknown: %d]\n " , insDsc .Resources .TEE )
88- }
89-
90- fmt .Printf (" Memory: %d MiB\n " , insDsc .Resources .Memory )
91- fmt .Printf (" vCPUs: %d\n " , insDsc .Resources .CPUCount )
92- fmt .Printf (" Storage: %d MiB\n " , insDsc .Resources .Storage )
93- if insDsc .Resources .GPU != nil {
94- fmt .Printf (" GPU:\n " )
95- if insDsc .Resources .GPU .Model != "" {
96- fmt .Printf (" Model: %s\n " , insDsc .Resources .GPU .Model )
97- } else {
98- fmt .Printf (" Model: <any>\n " )
99- }
100- fmt .Printf (" Count: %d\n " , insDsc .Resources .GPU .Count )
101- }
102-
103- switch insDsc .Deployment {
104- default :
105- fmt .Printf ("Deployment:\n " )
106- fmt .Printf (" App ID: %s\n " , insDsc .Deployment .AppID )
107-
108- if len (insDsc .Deployment .Metadata ) > 0 {
109- fmt .Printf (" Metadata:\n " )
110- for key , value := range insDsc .Deployment .Metadata {
111- fmt .Printf (" %s: %s\n " , key , value )
112- }
113- }
114- case nil :
115- fmt .Printf ("Deployment: <no current deployment>\n " )
116- }
117-
118- // Show commands.
119- fmt .Printf ("Commands:\n " )
120- if len (insCmds ) > 0 {
121- for _ , qc := range insCmds {
122- fmt .Printf (" - ID: %s\n " , qc .ID )
123-
124- var cmd scheduler.Command
125- err := cbor .Unmarshal (qc .Cmd , & cmd )
126- switch err {
127- case nil :
128- // Decodable scheduler command.
129- fmt .Printf (" Method: %s\n " , cmd .Method )
130- fmt .Printf (" Args:\n " )
131-
132- switch cmd .Method {
133- case scheduler .MethodDeploy :
134- showCommandArgs (npa , cmd .Args , scheduler.DeployRequest {})
135- case scheduler .MethodRestart :
136- showCommandArgs (npa , cmd .Args , scheduler.RestartRequest {})
137- case scheduler .MethodTerminate :
138- showCommandArgs (npa , cmd .Args , scheduler.TerminateRequest {})
139- default :
140- showCommandArgs (npa , cmd .Args , make (map [string ]interface {}))
141- }
142- default :
143- // Unknown command format.
144- fmt .Printf (" <unknown format: %X>\n " , qc .Cmd )
145- }
146- }
147- } else {
148- fmt .Printf (" <no queued commands>\n " )
149- }
150- },
151- }
152-
15322 restartCmd = & cobra.Command {
15423 Use : "restart [<machine-name>]" ,
15524 Short : "Restart a running machine or start a stopped one" ,
@@ -401,9 +270,6 @@ func showCommandArgs[V any](npa *common.NPASelection, raw []byte, args V) {
401270}
402271
403272func init () {
404- showCmd .Flags ().AddFlagSet (common .SelectorFlags )
405- showCmd .Flags ().AddFlagSet (roflCommon .DeploymentFlags )
406-
407273 restartCmd .Flags ().AddFlagSet (common .SelectorFlags )
408274 restartCmd .Flags ().AddFlagSet (common .RuntimeTxFlags )
409275 restartCmd .Flags ().AddFlagSet (roflCommon .DeploymentFlags )
0 commit comments