Skip to content

Commit 11b1ba0

Browse files
committed
Support of 'scw tag --bootscript' option (#149)
1 parent c88f21a commit 11b1ba0

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ Tag a snapshot into an image.
753753
Options:
754754

755755
-h, --help=false Print usage
756+
--bootscript="" Assign a bootscript
756757
```
757758

758759

@@ -1130,6 +1131,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
11301131

11311132
#### Features
11321133

1134+
* Support of `scw tag --bootscript=""` option ([#149](https://github.com/scaleway/scaleway-cli/issues/149)
11331135
* `scw info` now prints user/organization info from the API ([#130](https://github.com/scaleway/scaleway-cli/issues/130)
11341136
* Added helpers to manipulate new `user_data` API ([#150](https://github.com/scaleway/scaleway-cli/issues/150))
11351137
* Support of `scw rm -f/--force` option ([#158](https://github.com/scaleway/scaleway-cli/issues/158))

pkg/api/api.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,11 @@ type ScalewaySnapshotDefinition struct {
506506

507507
// ScalewayImageDefinition represents a Scaleway image definition
508508
type ScalewayImageDefinition struct {
509-
SnapshotIDentifier string `json:"root_volume"`
510-
Name string `json:"name,omitempty"`
511-
Organization string `json:"organization"`
512-
Arch string `json:"arch"`
509+
SnapshotIDentifier string `json:"root_volume"`
510+
Name string `json:"name,omitempty"`
511+
Organization string `json:"organization"`
512+
Arch string `json:"arch"`
513+
DefaultBootscript *string `json:"default_bootscript,omitempty"`
513514
}
514515

515516
// ScalewayRoleDefinition represents a Scaleway Token UserId Role
@@ -1007,13 +1008,16 @@ func (s *ScalewayAPI) PostSnapshot(volumeID string, name string) (string, error)
10071008
}
10081009

10091010
// PostImage creates a new image
1010-
func (s *ScalewayAPI) PostImage(volumeID string, name string) (string, error) {
1011+
func (s *ScalewayAPI) PostImage(volumeID string, name string, bootscript string) (string, error) {
10111012
definition := ScalewayImageDefinition{
10121013
SnapshotIDentifier: volumeID,
10131014
Name: name,
10141015
Organization: s.Organization,
10151016
Arch: "arm",
10161017
}
1018+
if bootscript != "" {
1019+
definition.DefaultBootscript = &bootscript
1020+
}
10171021

10181022
resp, err := s.PostResponse("images", definition)
10191023
if err != nil {

pkg/cli/cmd_tag.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ var cmdTag = &Command{
1515

1616
func init() {
1717
cmdTag.Flag.BoolVar(&tagHelp, []string{"h", "-help"}, false, "Print usage")
18+
cmdTag.Flag.StringVar(&tagBootscript, []string{"-bootscript"}, "", "Assign bootscript")
1819
}
1920

2021
// Flags
21-
var tagHelp bool // -h, --help flag
22+
var tagHelp bool // -h, --help flag
23+
var tagBootscript string // --bootscript flag
2224

2325
func runTag(cmd *Command, rawArgs []string) error {
2426
if tagHelp {
@@ -29,8 +31,9 @@ func runTag(cmd *Command, rawArgs []string) error {
2931
}
3032

3133
args := commands.TagArgs{
32-
Snapshot: rawArgs[0],
33-
Name: rawArgs[1],
34+
Snapshot: rawArgs[0],
35+
Name: rawArgs[1],
36+
Bootscript: tagBootscript,
3437
}
3538
ctx := cmd.GetContext(rawArgs)
3639
return commands.RunTag(ctx, args)

pkg/commands/tag.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import "fmt"
88

99
// TagArgs are flags for the `RunTag` function
1010
type TagArgs struct {
11-
Snapshot string
12-
Name string
11+
Snapshot string
12+
Bootscript string
13+
Name string
1314
}
1415

1516
// RunTag is the handler for 'scw tag'
@@ -20,7 +21,12 @@ func RunTag(ctx CommandContext, args TagArgs) error {
2021
return fmt.Errorf("cannot fetch snapshot: %v", err)
2122
}
2223

23-
image, err := ctx.API.PostImage(snapshot.Identifier, args.Name)
24+
bootscriptID := ""
25+
if args.Bootscript != "" {
26+
bootscriptID = ctx.API.GetBootscriptID(args.Bootscript)
27+
}
28+
29+
image, err := ctx.API.PostImage(snapshot.Identifier, args.Name, bootscriptID)
2430
if err != nil {
2531
return fmt.Errorf("cannot create image: %v", err)
2632
}

0 commit comments

Comments
 (0)