Skip to content

Commit 5060406

Browse files
fix boot storage cannot be created from private template
1 parent 0cf1de8 commit 5060406

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

builder/gridscale/builder.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (pack
8585
ui: ui,
8686
},
8787
&stepCreateBootStorage{
88-
client: client,
89-
config: &b.config,
90-
ui: ui,
88+
client: client,
89+
templateClient: client,
90+
config: &b.config,
91+
ui: ui,
9192
},
9293
&stepLinkServerBootStorage{
9394
client: client,

builder/gridscale/step_create_boot_storage.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
)
1212

1313
type stepCreateBootStorage struct {
14-
client gsclient.StorageOperator
15-
config *Config
16-
ui packer.Ui
14+
client gsclient.StorageOperator
15+
templateClient gsclient.TemplateOperator
16+
config *Config
17+
ui packer.Ui
1718
}
1819

1920
func (s *stepCreateBootStorage) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
@@ -39,21 +40,31 @@ func (s *stepCreateBootStorage) Run(ctx context.Context, state multistep.StateBa
3940
state.Put("error", err)
4041
return multistep.ActionHalt
4142
}
42-
if sshKeyUUID == "" && c.Comm.SSHPassword == "" {
43-
ui.Error("No SSH key UUID and no SSH password are provided.")
44-
state.Put("error", "No SSH key UUID and no SSH password are provided.")
45-
return multistep.ActionHalt
46-
}
4743
storage_template := gsclient.StorageTemplate{
48-
Hostname: c.Hostname,
4944
TemplateUUID: c.BaseTemplateUUID,
5045
}
51-
if sshKeyUUID != "" {
52-
storage_template.Sshkeys = []string{sshKeyUUID}
46+
template, err := s.templateClient.GetTemplate(context.Background(), c.BaseTemplateUUID)
47+
if err != nil {
48+
ui.Error(fmt.Sprintf("Error getting template: %s", err))
49+
state.Put("error", err)
50+
return multistep.ActionHalt
5351
}
54-
if c.Comm.SSHPassword != "" {
55-
storage_template.Password = c.Comm.SSHPassword
56-
storage_template.PasswordType = gsclient.PlainPasswordType
52+
// Check if template is public, if so, either ssh key or password and hostname is required.
53+
// If template is private, ssh key or password will be ignored.
54+
if !template.Properties.Private {
55+
storage_template.Hostname = c.Hostname
56+
if sshKeyUUID == "" && c.Comm.SSHPassword == "" {
57+
ui.Error("No SSH key UUID and no SSH password are provided.")
58+
state.Put("error", "No SSH key UUID and no SSH password are provided.")
59+
return multistep.ActionHalt
60+
}
61+
if sshKeyUUID != "" {
62+
storage_template.Sshkeys = []string{sshKeyUUID}
63+
}
64+
if c.Comm.SSHPassword != "" {
65+
storage_template.Password = c.Comm.SSHPassword
66+
storage_template.PasswordType = gsclient.PlainPasswordType
67+
}
5768
}
5869
storageCreateReq.Template = &storage_template
5970
}

0 commit comments

Comments
 (0)