Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update generated apis #758

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 276 additions & 0 deletions internal/namespaces/baremetal/v1alpha1/baremetal_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ func GetGeneratedCommands() *core.Commands {
baremetalBmc(),
baremetalOffer(),
baremetalServerList(),
baremetalServerGet(),
baremetalServerCreate(),
baremetalServerUpdate(),
baremetalServerInstall(),
baremetalServerDelete(),
baremetalServerReboot(),
baremetalServerStart(),
baremetalServerStop(),
)
}
func baremetalRoot() *core.Command {
Expand Down Expand Up @@ -142,3 +150,271 @@ func baremetalServerList() *core.Command {
},
}
}

func baremetalServerGet() *core.Command {
return &core.Command{
Short: `Get server`,
Long: `Get the server associated with the given ID.`,
Namespace: "baremetal",
Resource: "server",
Verb: "get",
ArgsType: reflect.TypeOf(baremetal.GetServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `ID of the server`,
Required: true,
},
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.GetServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.GetServer(request)

},
}
}

func baremetalServerCreate() *core.Command {
return &core.Command{
Short: `Create server`,
Long: `Create a new server. Once the server is created, you probably want to install an OS.`,
Namespace: "baremetal",
Resource: "server",
Verb: "create",
ArgsType: reflect.TypeOf(baremetal.CreateServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "offer-id",
Short: `Offer ID of the new server`,
Required: true,
},
{
Name: "name",
Short: `Name of the server (≠hostname)`,
Required: true,
},
{
Name: "description",
Short: `Description associated to the server, max 255 characters`,
Required: true,
},
{
Name: "tags.{index}",
Short: `Tags to associate to the server`,
Required: false,
},
core.OrganizationIDArgSpec(),
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.CreateServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.CreateServer(request)

},
}
}

func baremetalServerUpdate() *core.Command {
return &core.Command{
Short: `Update server`,
Long: `Update the server associated with the given ID.`,
Namespace: "baremetal",
Resource: "server",
Verb: "update",
ArgsType: reflect.TypeOf(baremetal.UpdateServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `ID of the server to update`,
Required: true,
},
{
Name: "name",
Short: `Name of the server (≠hostname), not updated if null`,
Required: false,
},
{
Name: "description",
Short: `Description associated to the server, max 255 characters, not updated if null`,
Required: false,
},
{
Name: "tags",
Short: `Tags associated to the server, not updated if null`,
Required: false,
},
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.UpdateServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.UpdateServer(request)

},
}
}

func baremetalServerInstall() *core.Command {
return &core.Command{
Short: `Install server`,
Long: `Install an OS on the server associated with the given ID.`,
Namespace: "baremetal",
Resource: "server",
Verb: "install",
ArgsType: reflect.TypeOf(baremetal.InstallServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `Server ID to install`,
Required: true,
},
{
Name: "os-id",
Short: `ID of the OS to install on the server`,
Required: true,
},
{
Name: "hostname",
Short: `Hostname of the server`,
Required: true,
},
{
Name: "ssh-key-ids.{index}",
Short: `SSH key IDs authorized on the server`,
Required: true,
},
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.InstallServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.InstallServer(request)

},
}
}

func baremetalServerDelete() *core.Command {
return &core.Command{
Short: `Delete server`,
Long: `Delete the server associated with the given ID.`,
Namespace: "baremetal",
Resource: "server",
Verb: "delete",
ArgsType: reflect.TypeOf(baremetal.DeleteServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `ID of the server to delete`,
Required: true,
},
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.DeleteServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.DeleteServer(request)

},
}
}

func baremetalServerReboot() *core.Command {
return &core.Command{
Short: `Reboot server`,
Long: `Reboot the server associated with the given ID, use boot param to reboot in rescue.`,
Namespace: "baremetal",
Resource: "server",
Verb: "reboot",
ArgsType: reflect.TypeOf(baremetal.RebootServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `ID of the server to reboot`,
Required: true,
},
{
Name: "boot-type",
Short: `The type of boot`,
Required: false,
EnumValues: []string{"normal", "rescue"},
},
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.RebootServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.RebootServer(request)

},
}
}

func baremetalServerStart() *core.Command {
return &core.Command{
Short: `Start server`,
Long: `Start the server associated with the given ID.`,
Namespace: "baremetal",
Resource: "server",
Verb: "start",
ArgsType: reflect.TypeOf(baremetal.StartServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `ID of the server to start`,
Required: true,
},
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.StartServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.StartServer(request)

},
}
}

func baremetalServerStop() *core.Command {
return &core.Command{
Short: `Stop server`,
Long: `Stop the server associated with the given ID.`,
Namespace: "baremetal",
Resource: "server",
Verb: "stop",
ArgsType: reflect.TypeOf(baremetal.StopServerRequest{}),
ArgSpecs: core.ArgSpecs{
{
Name: "server-id",
Short: `ID of the server to stop`,
Required: true,
},
core.ZoneArgSpec(scw.ZoneFrPar2),
},
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
request := args.(*baremetal.StopServerRequest)

client := core.ExtractClient(ctx)
api := baremetal.NewAPI(client)
return api.StopServer(request)

},
}
}