Merge pull request #6487 from sermilrod/Honour-cloudstack-projectid
Honour cloudstack projectid
This commit is contained in:
commit
451cbd8aa9
|
@ -40,6 +40,7 @@ type Config struct {
|
||||||
PublicIPAddress string `mapstructure:"public_ip_address"`
|
PublicIPAddress string `mapstructure:"public_ip_address"`
|
||||||
SecurityGroups []string `mapstructure:"security_groups"`
|
SecurityGroups []string `mapstructure:"security_groups"`
|
||||||
ServiceOffering string `mapstructure:"service_offering"`
|
ServiceOffering string `mapstructure:"service_offering"`
|
||||||
|
PreventFirewallChanges bool `mapstructure:"prevent_firewall_changes"`
|
||||||
SourceISO string `mapstructure:"source_iso"`
|
SourceISO string `mapstructure:"source_iso"`
|
||||||
SourceTemplate string `mapstructure:"source_template"`
|
SourceTemplate string `mapstructure:"source_template"`
|
||||||
TemporaryKeypairName string `mapstructure:"temporary_keypair_name"`
|
TemporaryKeypairName string `mapstructure:"temporary_keypair_name"`
|
||||||
|
|
|
@ -117,6 +117,11 @@ func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) m
|
||||||
// Store the port forward ID.
|
// Store the port forward ID.
|
||||||
state.Put("port_forward_id", forward.Id)
|
state.Put("port_forward_id", forward.Id)
|
||||||
|
|
||||||
|
if config.PreventFirewallChanges {
|
||||||
|
ui.Message("Networking has been setup (without firewall changes)!")
|
||||||
|
return multistep.ActionContinue
|
||||||
|
}
|
||||||
|
|
||||||
if network.Vpcid != "" {
|
if network.Vpcid != "" {
|
||||||
ui.Message("Creating network ACL rule...")
|
ui.Message("Creating network ACL rule...")
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,9 @@ func (s *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) mu
|
||||||
p.SetDisplayname("Created by Packer")
|
p.SetDisplayname("Created by Packer")
|
||||||
|
|
||||||
if keypair, ok := state.GetOk("keypair"); ok {
|
if keypair, ok := state.GetOk("keypair"); ok {
|
||||||
p.SetKeypair(keypair.(string))
|
kp := keypair.(string)
|
||||||
|
ui.Message(fmt.Sprintf("Using keypair: %s", kp))
|
||||||
|
p.SetKeypair(kp)
|
||||||
}
|
}
|
||||||
|
|
||||||
if securitygroups, ok := state.GetOk("security_groups"); ok {
|
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("Instance has been created!")
|
||||||
|
ui.Message(fmt.Sprintf("Instance ID: %s", instance.Id))
|
||||||
|
|
||||||
// In debug-mode, we output the password
|
// In debug-mode, we output the password
|
||||||
if s.Debug {
|
if s.Debug {
|
||||||
|
|
|
@ -51,7 +51,7 @@ func (s *stepCreateTemplate) Run(_ context.Context, state multistep.StateBag) mu
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.Message("Retrieving the ROOT volume ID...")
|
ui.Message("Retrieving the ROOT volume ID...")
|
||||||
volumeID, err := getRootVolumeID(client, instanceID)
|
volumeID, err := getRootVolumeID(client, instanceID, config.Project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
|
@ -89,13 +89,16 @@ func (s *stepCreateTemplate) Cleanup(state multistep.StateBag) {
|
||||||
// Nothing to cleanup for this step.
|
// Nothing to cleanup for this step.
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRootVolumeID(client *cloudstack.CloudStackClient, instanceID string) (string, error) {
|
func getRootVolumeID(client *cloudstack.CloudStackClient, instanceID, projectID string) (string, error) {
|
||||||
// Retrieve the virtual machine object.
|
// Retrieve the virtual machine object.
|
||||||
p := client.Volume.NewListVolumesParams()
|
p := client.Volume.NewListVolumesParams()
|
||||||
|
|
||||||
// Set the type and virtual machine ID
|
// Set the type and virtual machine ID
|
||||||
p.SetType("ROOT")
|
p.SetType("ROOT")
|
||||||
p.SetVirtualmachineid(instanceID)
|
p.SetVirtualmachineid(instanceID)
|
||||||
|
if projectID != "" {
|
||||||
|
p.SetProjectid(projectID)
|
||||||
|
}
|
||||||
|
|
||||||
volumes, err := client.Volume.ListVolumes(p)
|
volumes, err := client.Volume.ListVolumes(p)
|
||||||
if err != nil {
|
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))
|
ui.Say(fmt.Sprintf("Creating temporary keypair: %s ...", s.TemporaryKeyPairName))
|
||||||
|
|
||||||
p := client.SSH.NewCreateSSHKeyPairParams(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)
|
keypair, err := client.SSH.CreateSSHKeyPair(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error creating temporary keypair: %s", err)
|
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)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
client := state.Get("client").(*cloudstack.CloudStackClient)
|
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))
|
ui.Say(fmt.Sprintf("Deleting temporary keypair: %s ...", s.TemporaryKeyPairName))
|
||||||
|
|
||||||
_, err := client.SSH.DeleteSSHKeyPair(client.SSH.NewDeleteSSHKeyPairParams(
|
_, err := client.SSH.DeleteSSHKeyPair(p)
|
||||||
s.TemporaryKeyPairName,
|
|
||||||
))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ui.Error(err.Error())
|
ui.Error(err.Error())
|
||||||
ui.Error(fmt.Sprintf(
|
ui.Error(fmt.Sprintf(
|
||||||
|
|
|
@ -117,6 +117,9 @@ builder.
|
||||||
- `instance_name` (string) - The name of the instance. Defaults to
|
- `instance_name` (string) - The name of the instance. Defaults to
|
||||||
"packer-UUID" where UUID is dynamically generated.
|
"packer-UUID" where UUID is dynamically generated.
|
||||||
|
|
||||||
|
- `prevent_firewall_changes` (boolean) - Set to `true` to prevent network ACLs
|
||||||
|
or firewall rules creation. Defaults to `false`.
|
||||||
|
|
||||||
- `project` (string) - The name or ID of the project to deploy the instance to.
|
- `project` (string) - The name or ID of the project to deploy the instance to.
|
||||||
|
|
||||||
- `public_ip_address` (string) - The public IP address or it's ID used for
|
- `public_ip_address` (string) - The public IP address or it's ID used for
|
||||||
|
|
Loading…
Reference in New Issue