Skip to content

Commit

Permalink
Update server / set new values (#70)
Browse files Browse the repository at this point in the history
Add serverSetCmd

Adds `gscloud server set` command.
  • Loading branch information
cyberpanda authored Aug 21, 2020
1 parent 0b75996 commit e48c149
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
29 changes: 28 additions & 1 deletion cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,29 @@ var serverCreateCmd = &cobra.Command{
},
}

var serverSetCmd = &cobra.Command{
Use: "set [ID] [flags]",
Example: `./gscloud server set ID --cores N`,
Short: "Update server",
Long: `Update properties of an existing server.`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
serverOp := rt.ServerOperator()
ctx := context.Background()
err := serverOp.UpdateServer(
ctx,
args[0],
gsclient.ServerUpdateRequest{
Cores: cores,
Memory: memory,
Name: serverName,
})
if err != nil {
log.Fatalf("Failed: %s", err)
}
},
}

func init() {
serverOffCmd.PersistentFlags().BoolVarP(&forceShutdown, "force", "f", false, "Force shutdown (no ACPI)")

Expand All @@ -185,6 +208,10 @@ func init() {
serverCreateCmd.PersistentFlags().StringVar(&hostName, "hostname", "", "Hostname")
serverCreateCmd.PersistentFlags().StringVar(&plainPassword, "password", "", "Plain-text password")

serverCmd.AddCommand(serverLsCmd, serverOnCmd, serverOffCmd, serverRmCmd, serverCreateCmd)
serverSetCmd.PersistentFlags().IntVar(&memory, "mem", 0, "Memory (GB)")
serverSetCmd.PersistentFlags().IntVar(&cores, "cores", 0, "No. of cores")
serverSetCmd.PersistentFlags().StringVar(&serverName, "name", "", "Name of the server")

serverCmd.AddCommand(serverLsCmd, serverOnCmd, serverOffCmd, serverRmCmd, serverCreateCmd, serverSetCmd)
rootCmd.AddCommand(serverCmd)
}
4 changes: 4 additions & 0 deletions cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (o mockServerOp) CreateServerStorage(ctx context.Context, id string, body g
return nil
}

func (o mockServerOp) UpdateServer(ctx context.Context, id string, body gsclient.ServerUpdateRequest) error {
return nil
}

func Test_ServerCommmandDelete(t *testing.T) {
r, w, _ := os.Pipe()
rt, _ = runtime.NewTestRuntime()
Expand Down
1 change: 1 addition & 0 deletions runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type ServerOperator interface {
GetTemplateByName(ctx context.Context, name string) (gsclient.Template, error)
CreateStorage(ctx context.Context, body gsclient.StorageCreateRequest) (gsclient.CreateResponse, error)
CreateServerStorage(ctx context.Context, id string, body gsclient.ServerStorageRelationCreateRequest) error
UpdateServer(ctx context.Context, id string, body gsclient.ServerUpdateRequest) error
}

// NetworkOperator interface that amalgamates all operations regarding network objects.
Expand Down

0 comments on commit e48c149

Please sign in to comment.