From f3296b5400af6fbd8bc430fd6fb7ae79c246f962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Fri, 7 Feb 2020 10:31:03 +0100 Subject: [PATCH 1/2] feat(instance): Add examples in instances commands --- .../instance/v1/custom_security_group.go | 36 +++++++++++++ .../namespaces/instance/v1/custom_server.go | 50 +++++++++++++++++++ 2 files changed, 86 insertions(+) diff --git a/internal/namespaces/instance/v1/custom_security_group.go b/internal/namespaces/instance/v1/custom_security_group.go index 83a198e470..173127f254 100644 --- a/internal/namespaces/instance/v1/custom_security_group.go +++ b/internal/namespaces/instance/v1/custom_security_group.go @@ -243,6 +243,12 @@ func securityGroupClearCommand() *core.Command { Resource: "security-group", Verb: "clear", ArgsType: reflect.TypeOf(instanceResetSecurityGroupArgs{}), + Examples: []*core.Example{ + { + Short: "Remove all rules of the given security group", + Request: `{"security_group_id": "f8a5139c-6487-492d-a402-a9b9ffa21602"}`, + }, + }, Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) { args := argsI.(*instanceResetSecurityGroupArgs) @@ -324,6 +330,36 @@ func securityGroupUpdateCommand() *core.Command { Name: "organization-default", }, }, + Examples: []*core.Example{ + { + Short: "Change the name of the given security group", + Request: `{"security_group_id": "da1550ea-af6c-4441-9ddc-7565c5e8a7dc", "name": "foobar"}`, + }, + { + Short: "Change the description of the given security group", + Request: `{"security_group_id": "69e03584-613b-49b9-87ec-a57d540a91d6", "description": "foobar"}`, + }, + { + Short: "Enable stateful security group", + Request: `{"security_group_id": "ceadfe27-d186-4c50-bc4f-ff84f14cce4d", "stateful": true}`, + }, + { + Short: "Disable stateful security group", + Request: `{"security_group_id": "2d5c6dfb-3e1d-4642-be57-906768122df8", "stateful": false}`, + }, + { + Short: "Set the default inbound policy as drop", + Request: `{"security_group_id": "8b81fab4-17df-4cef-a795-6c4b8d7a77f9", "inbound_default_policy": "drop"}`, + }, + { + Short: "Set the default outbound policy as drop", + Request: `{"security_group_id": "d1023839-9d81-49a1-b9b3-489ca9eea7f7", "outbound_default_policy": "drop"}`, + }, + { + Short: "Set the given security group as the default for the organization", + Request: `{"security_group_id": "56fd1cff-1daa-46b8-a9f7-aecf1fa17009", "organization_default": true}`, + }, + }, Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) { req := argsI.(*instance.UpdateSecurityGroupRequest) diff --git a/internal/namespaces/instance/v1/custom_server.go b/internal/namespaces/instance/v1/custom_server.go index 37525b7eaa..2b6aade3da 100644 --- a/internal/namespaces/instance/v1/custom_server.go +++ b/internal/namespaces/instance/v1/custom_server.go @@ -197,6 +197,16 @@ func serverStartCommand() *core.Command { Run: getRunServerAction(instance.ServerActionPoweron), WaitFunc: waitForServerFunc(), ArgSpecs: serverActionArgSpecs, + Examples: []*core.Example{ + { + Short: "Start a server in the default zone with a given id", + Request: `{"server_id": "4fbb5119-4542-489c-9443-aa8b574bb6ad"}`, + }, + { + Short: "Start a server in fr-par-1 zone with a given id", + Request: `{"zone":"fr-par-1", "server_id": "3f38e99f-07bd-458a-9512-b1d15433a102"}`, + }, + }, } } @@ -210,6 +220,16 @@ func serverStopCommand() *core.Command { Run: getRunServerAction(instance.ServerActionPoweroff), WaitFunc: waitForServerFunc(), ArgSpecs: serverActionArgSpecs, + Examples: []*core.Example{ + { + Short: "Stop a server in the default zone with a given id", + Request: `{"server_id": "db21e0d5-f0f0-4535-8815-88b80abac8a9"}`, + }, + { + Short: "Stop a server in fr-par-1 zone with a given id", + Request: `{"zone":"fr-par-1", "server_id": "1a147062-b8f8-410c-91f7-c150f356e38f"}`, + }, + }, } } @@ -223,6 +243,16 @@ func serverStandbyCommand() *core.Command { Run: getRunServerAction(instance.ServerActionStopInPlace), WaitFunc: waitForServerFunc(), ArgSpecs: serverActionArgSpecs, + Examples: []*core.Example{ + { + Short: "Put in standby a server in the default zone with a given id", + Request: `{"server_id": "d9439f78-df31-411b-b292-8ef56dd2920c"}`, + }, + { + Short: "Put in standby a server in fr-par-1 zone with a given id", + Request: `{"zone":"fr-par-1", "server_id": "d36cfc02-5d79-417f-a785-79da256c53d0"}`, + }, + }, } } @@ -236,6 +266,16 @@ func serverRebootCommand() *core.Command { Run: getRunServerAction(instance.ServerActionReboot), WaitFunc: waitForServerFunc(), ArgSpecs: serverActionArgSpecs, + Examples: []*core.Example{ + { + Short: "Reboot a server in the default zone with a given id", + Request: `{"server_id": "887274a9-dd80-41ff-aab9-764e935b77b8"}`, + }, + { + Short: "Reboot a server in fr-par-1 zone with a given id", + Request: `{"zone":"fr-par-1", "server_id": "bde358bc-298f-43b5-9093-683645fbae95"}`, + }, + }, } } @@ -300,6 +340,16 @@ func serverDeleteCommand() *core.Command { Short: "Force shutdown of the instance server before deleting it", }, }, + Examples: []*core.Example{ + { + Short: "Delete a server in the default zone with a given id", + Request: `{"server_id": "c5a72f0e-d768-414f-95d3-f58a07e83147"}`, + }, + { + Short: "Delete a server in fr-par-1 zone with a given id", + Request: `{"zone":"fr-par-1", "server_id": "6bc6479d-5cda-4a25-b279-67e44b606eac"}`, + }, + }, SeeAlsos: []*core.SeeAlso{ { Command: "scw instance server stop", From 43891ac125a0357f7943ae79e3a445ccf8e6253e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Fri, 7 Feb 2020 15:09:29 +0100 Subject: [PATCH 2/2] Fix --- .../instance/v1/custom_security_group.go | 30 ++++++++----------- .../namespaces/instance/v1/custom_server.go | 20 ++++++------- 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/internal/namespaces/instance/v1/custom_security_group.go b/internal/namespaces/instance/v1/custom_security_group.go index 173127f254..66c87ac692 100644 --- a/internal/namespaces/instance/v1/custom_security_group.go +++ b/internal/namespaces/instance/v1/custom_security_group.go @@ -246,7 +246,7 @@ func securityGroupClearCommand() *core.Command { Examples: []*core.Example{ { Short: "Remove all rules of the given security group", - Request: `{"security_group_id": "f8a5139c-6487-492d-a402-a9b9ffa21602"}`, + Request: `{"security_group_id": "11111111-1111-1111-1111-111111111111"}`, }, }, Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) { @@ -332,32 +332,28 @@ func securityGroupUpdateCommand() *core.Command { }, Examples: []*core.Example{ { - Short: "Change the name of the given security group", - Request: `{"security_group_id": "da1550ea-af6c-4441-9ddc-7565c5e8a7dc", "name": "foobar"}`, - }, - { - Short: "Change the description of the given security group", - Request: `{"security_group_id": "69e03584-613b-49b9-87ec-a57d540a91d6", "description": "foobar"}`, + Short: "Set the default outbound policy as drop", + Request: `{"security_group_id": "11111111-1111-1111-1111-111111111111", "outbound_default_policy": "drop"}`, }, { - Short: "Enable stateful security group", - Request: `{"security_group_id": "ceadfe27-d186-4c50-bc4f-ff84f14cce4d", "stateful": true}`, + Short: "Set the given security group as the default for the organization", + Request: `{"security_group_id": "11111111-1111-1111-1111-111111111111", "organization_default": true}`, }, { - Short: "Disable stateful security group", - Request: `{"security_group_id": "2d5c6dfb-3e1d-4642-be57-906768122df8", "stateful": false}`, + Short: "Change the name of the given security group", + Request: `{"security_group_id": "11111111-1111-1111-1111-111111111111", "name": "foobar"}`, }, { - Short: "Set the default inbound policy as drop", - Request: `{"security_group_id": "8b81fab4-17df-4cef-a795-6c4b8d7a77f9", "inbound_default_policy": "drop"}`, + Short: "Change the description of the given security group", + Request: `{"security_group_id": "11111111-1111-1111-1111-111111111111", "description": "foobar"}`, }, { - Short: "Set the default outbound policy as drop", - Request: `{"security_group_id": "d1023839-9d81-49a1-b9b3-489ca9eea7f7", "outbound_default_policy": "drop"}`, + Short: "Enable stateful security group", + Request: `{"security_group_id": "11111111-1111-1111-1111-111111111111", "stateful": true}`, }, { - Short: "Set the given security group as the default for the organization", - Request: `{"security_group_id": "56fd1cff-1daa-46b8-a9f7-aecf1fa17009", "organization_default": true}`, + Short: "Set the default inbound policy as drop", + Request: `{"security_group_id": "11111111-1111-1111-1111-111111111111", "inbound_default_policy": "drop"}`, }, }, Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) { diff --git a/internal/namespaces/instance/v1/custom_server.go b/internal/namespaces/instance/v1/custom_server.go index 2b6aade3da..609c34a150 100644 --- a/internal/namespaces/instance/v1/custom_server.go +++ b/internal/namespaces/instance/v1/custom_server.go @@ -200,11 +200,11 @@ func serverStartCommand() *core.Command { Examples: []*core.Example{ { Short: "Start a server in the default zone with a given id", - Request: `{"server_id": "4fbb5119-4542-489c-9443-aa8b574bb6ad"}`, + Request: `{"server_id": "11111111-1111-1111-1111-111111111111"}`, }, { Short: "Start a server in fr-par-1 zone with a given id", - Request: `{"zone":"fr-par-1", "server_id": "3f38e99f-07bd-458a-9512-b1d15433a102"}`, + Request: `{"zone":"fr-par-1", "server_id": "11111111-1111-1111-1111-111111111111"}`, }, }, } @@ -223,11 +223,11 @@ func serverStopCommand() *core.Command { Examples: []*core.Example{ { Short: "Stop a server in the default zone with a given id", - Request: `{"server_id": "db21e0d5-f0f0-4535-8815-88b80abac8a9"}`, + Request: `{"server_id": "11111111-1111-1111-1111-111111111111"}`, }, { Short: "Stop a server in fr-par-1 zone with a given id", - Request: `{"zone":"fr-par-1", "server_id": "1a147062-b8f8-410c-91f7-c150f356e38f"}`, + Request: `{"zone":"fr-par-1", "server_id": "11111111-1111-1111-1111-111111111111"}`, }, }, } @@ -246,11 +246,11 @@ func serverStandbyCommand() *core.Command { Examples: []*core.Example{ { Short: "Put in standby a server in the default zone with a given id", - Request: `{"server_id": "d9439f78-df31-411b-b292-8ef56dd2920c"}`, + Request: `{"server_id": "11111111-1111-1111-1111-111111111111"}`, }, { Short: "Put in standby a server in fr-par-1 zone with a given id", - Request: `{"zone":"fr-par-1", "server_id": "d36cfc02-5d79-417f-a785-79da256c53d0"}`, + Request: `{"zone":"fr-par-1", "server_id": "11111111-1111-1111-1111-111111111111"}`, }, }, } @@ -269,11 +269,11 @@ func serverRebootCommand() *core.Command { Examples: []*core.Example{ { Short: "Reboot a server in the default zone with a given id", - Request: `{"server_id": "887274a9-dd80-41ff-aab9-764e935b77b8"}`, + Request: `{"server_id": "11111111-1111-1111-1111-111111111111"}`, }, { Short: "Reboot a server in fr-par-1 zone with a given id", - Request: `{"zone":"fr-par-1", "server_id": "bde358bc-298f-43b5-9093-683645fbae95"}`, + Request: `{"zone":"fr-par-1", "server_id": "11111111-1111-1111-1111-111111111111"}`, }, }, } @@ -343,11 +343,11 @@ func serverDeleteCommand() *core.Command { Examples: []*core.Example{ { Short: "Delete a server in the default zone with a given id", - Request: `{"server_id": "c5a72f0e-d768-414f-95d3-f58a07e83147"}`, + Request: `{"server_id": "11111111-1111-1111-1111-111111111111"}`, }, { Short: "Delete a server in fr-par-1 zone with a given id", - Request: `{"zone":"fr-par-1", "server_id": "6bc6479d-5cda-4a25-b279-67e44b606eac"}`, + Request: `{"zone":"fr-par-1", "server_id": "11111111-1111-1111-1111-111111111111"}`, }, }, SeeAlsos: []*core.SeeAlso{