Skip to content

Commit 7f11150

Browse files
authored
fix(iaas): update examples and fix the payload for boot volumes (#1436)
relates to STACKITCLI-404
1 parent 6fd51b3 commit 7f11150

2 files changed

Lines changed: 22 additions & 39 deletions

File tree

docs/stackit_server_create.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,26 @@ stackit server create [flags]
1313
### Examples
1414

1515
```
16-
Create a server from an image with id xxx
17-
$ stackit server create --machine-type t1.1 --name server1 --image-id xxx
18-
19-
Create a server with labels from an image with id xxx
20-
$ stackit server create --machine-type t1.1 --name server1 --image-id xxx --labels key=value,foo=bar
21-
22-
Create a server with a boot volume
23-
$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64
16+
Create a server with a boot volume with source type image
17+
$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64
2418
2519
Create a server with a boot volume from an existing volume
26-
$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type volume
20+
$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type volume
2721
2822
Create a server with a keypair
29-
$ stackit server create --machine-type t1.1 --name server1 --image-id xxx --keypair-name example
30-
31-
Create a server with a network
32-
$ stackit server create --machine-type t1.1 --name server1 --image-id xxx --network-id yyy
23+
$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --keypair-name example
3324
3425
Create a server with a network interface
35-
$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --network-interface-ids yyy
26+
$ stackit server create --machine-type g2i.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --network-interface-ids yyy
3627
3728
Create a server with an attached volume
38-
$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --volumes yyy
29+
$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --volumes zzz
3930
4031
Create a server with user data (cloud-init)
41-
$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --user-data @path/to/file.yaml
32+
$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --user-data @path/to/file.yaml
4233
4334
Create a server with provisioned agent
44-
$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --network-id yyy --agent-provisioning-policy ALWAYS
35+
$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --agent-provisioning-policy ALWAYS
4536
```
4637

4738
### Options
@@ -56,7 +47,6 @@ stackit server create [flags]
5647
--boot-volume-source-id string ID of the source object of boot volume. It can be either an image or volume ID
5748
--boot-volume-source-type string Type of the source object of boot volume. It can be either 'image' or 'volume'
5849
-h, --help Help for "stackit server create"
59-
--image-id string The image ID to be used for an ephemeral disk on the server. Either 'image-id' or 'boot-volume-...' flags are required
6050
--keypair-name string The name of the SSH keypair used during the server creation
6151
--labels stringToString Labels are key-value string pairs which can be attached to a server. E.g. '--labels key1=value1,key2=value2,...' (default [])
6252
--machine-type string Name of the type of the machine for the server. Possible values are documented in https://docs.stackit.cloud/products/compute-engine/server/basics/machine-types/

internal/cmd/server/create/create.go

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,44 +76,32 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
7676
Args: args.NoArgs,
7777
Example: examples.Build(
7878
examples.NewExample(
79-
`Create a server from an image with id xxx`,
80-
`$ stackit server create --machine-type t1.1 --name server1 --image-id xxx`,
81-
),
82-
examples.NewExample(
83-
`Create a server with labels from an image with id xxx`,
84-
`$ stackit server create --machine-type t1.1 --name server1 --image-id xxx --labels key=value,foo=bar`,
85-
),
86-
examples.NewExample(
87-
`Create a server with a boot volume`,
88-
`$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64`,
79+
`Create a server with a boot volume with source type image`,
80+
`$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64`,
8981
),
9082
examples.NewExample(
9183
`Create a server with a boot volume from an existing volume`,
92-
`$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type volume`,
84+
`$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type volume`,
9385
),
9486
examples.NewExample(
9587
`Create a server with a keypair`,
96-
`$ stackit server create --machine-type t1.1 --name server1 --image-id xxx --keypair-name example`,
97-
),
98-
examples.NewExample(
99-
`Create a server with a network`,
100-
`$ stackit server create --machine-type t1.1 --name server1 --image-id xxx --network-id yyy`,
88+
`$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --keypair-name example`,
10189
),
10290
examples.NewExample(
10391
`Create a server with a network interface`,
104-
`$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --network-interface-ids yyy`,
92+
`$ stackit server create --machine-type g2i.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --network-interface-ids yyy`,
10593
),
10694
examples.NewExample(
10795
`Create a server with an attached volume`,
108-
`$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --volumes yyy`,
96+
`$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --volumes zzz`,
10997
),
11098
examples.NewExample(
11199
`Create a server with user data (cloud-init)`,
112-
`$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --user-data @path/to/file.yaml`,
100+
`$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --user-data @path/to/file.yaml`,
113101
),
114102
examples.NewExample(
115103
`Create a server with provisioned agent`,
116-
`$ stackit server create --machine-type t1.1 --name server1 --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --network-id yyy --agent-provisioning-policy ALWAYS`,
104+
`$ stackit server create --machine-type g2i.1 --name server1 --network-id yyy --boot-volume-source-id xxx --boot-volume-source-type image --boot-volume-size 64 --agent-provisioning-policy ALWAYS`,
117105
),
118106
),
119107
RunE: func(cmd *cobra.Command, args []string) error {
@@ -194,6 +182,11 @@ func configureFlags(cmd *cobra.Command) {
194182
cmd.MarkFlagsMutuallyExclusive(imageIdFlag, bootVolumeSourceTypeFlag)
195183
cmd.MarkFlagsMutuallyExclusive(networkIdFlag, networkInterfaceIdsFlag)
196184
cmd.MarkFlagsOneRequired(networkIdFlag, networkInterfaceIdsFlag)
185+
186+
// hide image-id flag from help command to prevent users from using it alone which leads to errors, because it works only with small images
187+
// instead of using image-id alone, boot-volume flags can be used with type image
188+
cobra.CheckErr(cmd.Flags().MarkHidden(imageIdFlag))
189+
197190
cobra.CheckErr(err)
198191
}
199192

@@ -306,7 +299,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *iaas.APICli
306299
}
307300
}
308301

309-
if model.BootVolumePerformanceClass != nil || model.BootVolumeSize != nil || model.BootVolumeDeleteOnTermination != nil {
302+
if model.BootVolumePerformanceClass != nil || model.BootVolumeSize != nil || model.BootVolumeDeleteOnTermination != nil || (model.BootVolumeSourceId != "" && model.BootVolumeSourceType != "") {
310303
payload.BootVolume = &iaas.BootVolume{
311304
PerformanceClass: model.BootVolumePerformanceClass,
312305
Size: model.BootVolumeSize,

0 commit comments

Comments
 (0)