Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed May 22, 2020
1 parent 7aa1064 commit d18c5c8
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions internal/namespaces/baremetal/v1alpha1/custom_server_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ func serverInstallBuilder(c *core.Command) *core.Command {
c.ArgsType = reflect.TypeOf(baremetalInstallServerRequestCustom{})

c.ArgSpecs.AddBefore("ssh-key-ids.{index}", &core.ArgSpec{
Name: "all-ssh-keys",
Short: "Add all SSH keys on your baremetal instance",
Default: core.DefaultValueSetter("false"),
Name: "all-ssh-keys",
Short: "Add all SSH keys on your baremetal instance (cannot be used with ssh-key-ids)",
Default: core.DefaultValueSetter("false"),
OneOfGroup: "ssh",
})

c.Run = func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
c.ArgSpecs.DeleteByName("ssh-key-ids.{index}")

c.ArgSpecs.AddBefore("all-ssh-keys", &core.ArgSpec{
Name: "ssh-key-ids.{index}",
Short: `SSH key IDs authorized on the server (cannot be used with all-ssh-keys)`,
Required: true,
Positional: false,
OneOfGroup: "ssh",
})

c.Interceptor = func(ctx context.Context, argsI interface{}, runner core.CommandRunner) (interface{}, error) {
tmpRequest := argsI.(*baremetalInstallServerRequestCustom)
request := &baremetal.InstallServerRequest{
Zone: tmpRequest.Zone,
Expand All @@ -39,6 +47,7 @@ func serverInstallBuilder(c *core.Command) *core.Command {

// SSH keys management
if tmpRequest.AllSSHKeys {
client := core.ExtractClient(ctx)
accountapi := account.NewAPI(client)
orgId, _ := client.GetDefaultOrganizationID()
listKeys, err := accountapi.ListSSHKeys(&account.ListSSHKeysRequest{
Expand All @@ -56,7 +65,7 @@ func serverInstallBuilder(c *core.Command) *core.Command {
request.SSHKeyIDs = tmpRequest.SSHKeyIDs
}

return api.InstallServer(request)
return runner(ctx, request)
}

c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
Expand Down

0 comments on commit d18c5c8

Please sign in to comment.