Skip to content

Commit

Permalink
doc(instance): improve documentation of the create image command (#1106)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone authored Jun 19, 2020
1 parent 1569d2b commit 70cafdc
Show file tree
Hide file tree
Showing 5 changed files with 3,606 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ EXAMPLES:
scw instance image create name=foobar root-volume=11111111-1111-1111-1111-111111111111 arch=x86_64

ARGS:
[name=<generated>] Name of the image
snapshot-id UUID of the snapshot
arch Architecture of the image (x86_64 | arm)
[default-bootscript] Default bootscript of the image
[additional-volumes.{key}.id] UUID of the volume
[additional-volumes.{key}.name] Name of the volume
[additional-volumes.{key}.size] Disk size of the volume
[additional-volumes.{key}.volume-type] Type of the volume (l_ssd | b_ssd)
[additional-volumes.{key}.organization-id] Organization ID of the volume
[public] True to create a public image
[organization-id] Organization ID to use. If none is passed will use default organization ID from the config
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)
[name=<generated>] Name of the image
snapshot-id UUID of the snapshot that will be used as root volume in the image
arch Architecture of the image (x86_64 | arm)
[default-bootscript] Default bootscript of the image
[additional-snapshots.{key}.id] UUID of the snapshot to add
[additional-snapshots.{key}.name] Name of the additional snapshot
[additional-snapshots.{key}.size] Size of the additional snapshot
[additional-snapshots.{key}.volume-type] Underlying volume type of the additional snapshot (l_ssd | b_ssd)
[additional-snapshots.{key}.organization-id] Organization ID that own the additional snapshot
[public] True to create a public image
[organization-id] Organization ID to use. If none is passed will use default organization ID from the config
[zone=fr-par-1] Zone to target. If none is passed will use default zone from the config (fr-par-1 | nl-ams-1)

FLAGS:
-h, --help help for create
Expand Down
20 changes: 15 additions & 5 deletions internal/namespaces/instance/v1/custom_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,22 @@ func imageCreateBuilder(c *core.Command) *core.Command {
OrganizationID string
}

c.ArgSpecs.GetByName("extra-volumes.{key}.id").Name = "additional-volumes.{key}.id"
c.ArgSpecs.GetByName("extra-volumes.{key}.name").Name = "additional-volumes.{key}.name"
c.ArgSpecs.GetByName("extra-volumes.{key}.size").Name = "additional-volumes.{key}.size"
c.ArgSpecs.GetByName("extra-volumes.{key}.volume-type").Name = "additional-volumes.{key}.volume-type"
c.ArgSpecs.GetByName("extra-volumes.{key}.organization").Name = "additional-volumes.{key}.organization-id"
c.ArgSpecs.GetByName("extra-volumes.{key}.id").Short = "UUID of the snapshot to add"
c.ArgSpecs.GetByName("extra-volumes.{key}.id").Name = "additional-snapshots.{key}.id"

c.ArgSpecs.GetByName("extra-volumes.{key}.name").Short = "Name of the additional snapshot"
c.ArgSpecs.GetByName("extra-volumes.{key}.name").Name = "additional-snapshots.{key}.name"

c.ArgSpecs.GetByName("extra-volumes.{key}.size").Short = "Size of the additional snapshot"
c.ArgSpecs.GetByName("extra-volumes.{key}.size").Name = "additional-snapshots.{key}.size"

c.ArgSpecs.GetByName("extra-volumes.{key}.volume-type").Short = "Underlying volume type of the additional snapshot"
c.ArgSpecs.GetByName("extra-volumes.{key}.volume-type").Name = "additional-snapshots.{key}.volume-type"

c.ArgSpecs.GetByName("extra-volumes.{key}.organization").Short = "Organization ID that own the additional snapshot"
c.ArgSpecs.GetByName("extra-volumes.{key}.organization").Name = "additional-snapshots.{key}.organization-id"

c.ArgSpecs.GetByName("root-volume").Short = "UUID of the snapshot that will be used as root volume in the image"
c.ArgSpecs.GetByName("root-volume").Name = "snapshot-id"

renameOrganizationIDArgSpec(c.ArgSpecs)
Expand Down
20 changes: 20 additions & 0 deletions internal/namespaces/instance/v1/custom_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ func Test_ImageCreate(t *testing.T) {
deleteSnapshot("Snapshot"),
),
}))

t.Run("Use additional snapshots", core.Test(&core.TestConfig{
Commands: GetCommands(),
BeforeFunc: core.BeforeFuncCombine(
core.ExecStoreBeforeCmd("Server", "scw instance server create image=ubuntu_focal root-volume=local:10GB additional-volumes.0=local:10GB -w"),
core.ExecStoreBeforeCmd("SnapshotA", `scw instance snapshot create -w name=cli-test-image-create-snapshotA volume-id={{ (index .Server.Volumes "0").ID }}`),
core.ExecStoreBeforeCmd("SnapshotB", `scw instance snapshot create -w name=cli-test-image-create-snapshotB volume-id={{ (index .Server.Volumes "1").ID }}`),
),
Cmd: "scw instance image create snapshot-id={{ .SnapshotA.ID }} extra-volumes.0.id={{ .SnapshotB.ID }} arch=x86_64",
Check: core.TestCheckCombine(
core.TestCheckGolden(),
core.TestCheckExitCode(0),
),
AfterFunc: core.AfterFuncCombine(
deleteServer("Server"),
core.ExecAfterCmd("scw instance image delete {{ .CmdResult.Image.ID }}"),
core.ExecAfterCmd("scw instance snapshot delete {{ .SnapshotA.ID }}"),
core.ExecAfterCmd("scw instance snapshot delete {{ .SnapshotB.ID }}"),
),
}))
}

func Test_ImageDelete(t *testing.T) {
Expand Down
Loading

0 comments on commit 70cafdc

Please sign in to comment.