make packer builder honour projectid setting if provided
This commit is contained in:
parent
eae0556dc5
commit
a41a4658ee
|
@ -47,7 +47,9 @@ func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu
|
|||
p.SetDisplayname("Created by Packer")
|
||||
|
||||
if keypair, ok := state.GetOk("keypair"); ok {
|
||||
p.SetKeypair(keypair.(string))
|
||||
kp := keypair.(string)
|
||||
ui.Message(fmt.Sprintf("Found keypair: %s", kp))
|
||||
p.SetKeypair(kp)
|
||||
}
|
||||
|
||||
if securitygroups, ok := state.GetOk("security_groups"); ok {
|
||||
|
@ -120,6 +122,7 @@ func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu
|
|||
}
|
||||
|
||||
ui.Message("Instance has been created!")
|
||||
ui.Message(fmt.Sprintf("Instance ID: %s", instance.Id))
|
||||
|
||||
// In debug-mode, we output the password
|
||||
if s.Debug {
|
||||
|
|
|
@ -51,7 +51,7 @@ func (s *stepCreateTemplate) Run(_ context.Context, state multistep.StateBag) mu
|
|||
}
|
||||
|
||||
ui.Message("Retrieving the ROOT volume ID...")
|
||||
volumeID, err := getRootVolumeID(client, instanceID)
|
||||
volumeID, err := getRootVolumeID(client, instanceID, config)
|
||||
if err != nil {
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
|
@ -89,13 +89,16 @@ func (s *stepCreateTemplate) Cleanup(state multistep.StateBag) {
|
|||
// Nothing to cleanup for this step.
|
||||
}
|
||||
|
||||
func getRootVolumeID(client *cloudstack.CloudStackClient, instanceID string) (string, error) {
|
||||
func getRootVolumeID(client *cloudstack.CloudStackClient, instanceID string, config *Config) (string, error) {
|
||||
// Retrieve the virtual machine object.
|
||||
p := client.Volume.NewListVolumesParams()
|
||||
|
||||
// Set the type and virtual machine ID
|
||||
p.SetType("ROOT")
|
||||
p.SetVirtualmachineid(instanceID)
|
||||
if config.Project != "" {
|
||||
p.SetProjectid(config.Project)
|
||||
}
|
||||
|
||||
volumes, err := client.Volume.ListVolumes(p)
|
||||
if err != nil {
|
||||
|
|
|
@ -60,6 +60,12 @@ func (s *stepKeypair) Run(_ context.Context, state multistep.StateBag) multistep
|
|||
ui.Say(fmt.Sprintf("Creating temporary keypair: %s ...", s.TemporaryKeyPairName))
|
||||
|
||||
p := client.SSH.NewCreateSSHKeyPairParams(s.TemporaryKeyPairName)
|
||||
|
||||
cfg := state.Get("config").(*Config)
|
||||
if cfg.Project != "" {
|
||||
p.SetProjectid(cfg.Project)
|
||||
}
|
||||
|
||||
keypair, err := client.SSH.CreateSSHKeyPair(p)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error creating temporary keypair: %s", err)
|
||||
|
@ -120,12 +126,16 @@ func (s *stepKeypair) Cleanup(state multistep.StateBag) {
|
|||
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
client := state.Get("client").(*cloudstack.CloudStackClient)
|
||||
cfg := state.Get("config").(*Config)
|
||||
|
||||
p := client.SSH.NewDeleteSSHKeyPairParams(s.TemporaryKeyPairName)
|
||||
if cfg.Project != "" {
|
||||
p.SetProjectid(cfg.Project)
|
||||
}
|
||||
|
||||
ui.Say(fmt.Sprintf("Deleting temporary keypair: %s ...", s.TemporaryKeyPairName))
|
||||
|
||||
_, err := client.SSH.DeleteSSHKeyPair(client.SSH.NewDeleteSSHKeyPairParams(
|
||||
s.TemporaryKeyPairName,
|
||||
))
|
||||
_, err := client.SSH.DeleteSSHKeyPair(p)
|
||||
if err != nil {
|
||||
ui.Error(err.Error())
|
||||
ui.Error(fmt.Sprintf(
|
||||
|
|
Loading…
Reference in New Issue