Skip to content

Commit f42a679

Browse files
feat: Start and Stop VM
1 parent 74675ee commit f42a679

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 22
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-da3f4038bb544acae375f44527f515dc58308f67822905258b155192041e65ed.yml
3-
openapi_spec_hash: 4c7f6f453c20eda7fd8689e8917c65f9
4-
config_hash: a7d0557c72de54fd6baded5b189777c3
1+
configured_endpoints: 24
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-6a8902e840cc8f443018c06b23884d3b42e45181c1ac156f5cf56cac84b717ee.yml
3+
openapi_spec_hash: d1535b5fdc9d097940928f0689c8baa1
4+
config_hash: 510018ffa6ad6a17875954f66fe69598

pkg/cmd/cmd.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ func init() {
101101
&instancesLogs,
102102
&instancesDelete,
103103
&instancesStandby,
104+
&instancesStart,
105+
&instancesStop,
104106
},
105107
},
106108
{

pkg/cmd/instance.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,30 @@ var instancesStandby = cli.Command{
173173
HideHelpCommand: true,
174174
}
175175

176+
var instancesStart = cli.Command{
177+
Name: "start",
178+
Usage: "Start a stopped instance",
179+
Flags: []cli.Flag{
180+
&requestflag.StringFlag{
181+
Name: "id",
182+
},
183+
},
184+
Action: handleInstancesStart,
185+
HideHelpCommand: true,
186+
}
187+
188+
var instancesStop = cli.Command{
189+
Name: "stop",
190+
Usage: "Stop instance (graceful shutdown)",
191+
Flags: []cli.Flag{
192+
&requestflag.StringFlag{
193+
Name: "id",
194+
},
195+
},
196+
Action: handleInstancesStop,
197+
HideHelpCommand: true,
198+
}
199+
176200
func handleInstancesCreate(ctx context.Context, cmd *cli.Command) error {
177201
client := hypeman.NewClient(getDefaultRequestOptions(cmd)...)
178202
unusedArgs := cmd.Args().Slice()
@@ -402,3 +426,75 @@ func handleInstancesStandby(ctx context.Context, cmd *cli.Command) error {
402426
transform := cmd.Root().String("transform")
403427
return ShowJSON("instances standby", json, format, transform)
404428
}
429+
430+
func handleInstancesStart(ctx context.Context, cmd *cli.Command) error {
431+
client := hypeman.NewClient(getDefaultRequestOptions(cmd)...)
432+
unusedArgs := cmd.Args().Slice()
433+
if !cmd.IsSet("id") && len(unusedArgs) > 0 {
434+
cmd.Set("id", unusedArgs[0])
435+
unusedArgs = unusedArgs[1:]
436+
}
437+
if len(unusedArgs) > 0 {
438+
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
439+
}
440+
options, err := flagOptions(
441+
cmd,
442+
apiquery.NestedQueryFormatBrackets,
443+
apiquery.ArrayQueryFormatComma,
444+
ApplicationJSON,
445+
)
446+
if err != nil {
447+
return err
448+
}
449+
var res []byte
450+
options = append(options, option.WithResponseBodyInto(&res))
451+
_, err = client.Instances.Start(
452+
ctx,
453+
requestflag.CommandRequestValue[string](cmd, "id"),
454+
options...,
455+
)
456+
if err != nil {
457+
return err
458+
}
459+
460+
json := gjson.Parse(string(res))
461+
format := cmd.Root().String("format")
462+
transform := cmd.Root().String("transform")
463+
return ShowJSON("instances start", json, format, transform)
464+
}
465+
466+
func handleInstancesStop(ctx context.Context, cmd *cli.Command) error {
467+
client := hypeman.NewClient(getDefaultRequestOptions(cmd)...)
468+
unusedArgs := cmd.Args().Slice()
469+
if !cmd.IsSet("id") && len(unusedArgs) > 0 {
470+
cmd.Set("id", unusedArgs[0])
471+
unusedArgs = unusedArgs[1:]
472+
}
473+
if len(unusedArgs) > 0 {
474+
return fmt.Errorf("Unexpected extra arguments: %v", unusedArgs)
475+
}
476+
options, err := flagOptions(
477+
cmd,
478+
apiquery.NestedQueryFormatBrackets,
479+
apiquery.ArrayQueryFormatComma,
480+
ApplicationJSON,
481+
)
482+
if err != nil {
483+
return err
484+
}
485+
var res []byte
486+
options = append(options, option.WithResponseBodyInto(&res))
487+
_, err = client.Instances.Stop(
488+
ctx,
489+
requestflag.CommandRequestValue[string](cmd, "id"),
490+
options...,
491+
)
492+
if err != nil {
493+
return err
494+
}
495+
496+
json := gjson.Parse(string(res))
497+
format := cmd.Root().String("format")
498+
transform := cmd.Root().String("transform")
499+
return ShowJSON("instances stop", json, format, transform)
500+
}

0 commit comments

Comments
 (0)