Merge pull request #6487 from sermilrod/Honour-cloudstack-projectid
Honour cloudstack projectid
This commit is contained in:
commit
451cbd8aa9
|
@ -27,26 +27,27 @@ type Config struct {
|
|||
HTTPGetOnly bool `mapstructure:"http_get_only"`
|
||||
SSLNoVerify bool `mapstructure:"ssl_no_verify"`
|
||||
|
||||
CIDRList []string `mapstructure:"cidr_list"`
|
||||
CreateSecurityGroup bool `mapstructure:"create_security_group"`
|
||||
DiskOffering string `mapstructure:"disk_offering"`
|
||||
DiskSize int64 `mapstructure:"disk_size"`
|
||||
Expunge bool `mapstructure:"expunge"`
|
||||
Hypervisor string `mapstructure:"hypervisor"`
|
||||
InstanceName string `mapstructure:"instance_name"`
|
||||
Keypair string `mapstructure:"keypair"`
|
||||
Network string `mapstructure:"network"`
|
||||
Project string `mapstructure:"project"`
|
||||
PublicIPAddress string `mapstructure:"public_ip_address"`
|
||||
SecurityGroups []string `mapstructure:"security_groups"`
|
||||
ServiceOffering string `mapstructure:"service_offering"`
|
||||
SourceISO string `mapstructure:"source_iso"`
|
||||
SourceTemplate string `mapstructure:"source_template"`
|
||||
TemporaryKeypairName string `mapstructure:"temporary_keypair_name"`
|
||||
UseLocalIPAddress bool `mapstructure:"use_local_ip_address"`
|
||||
UserData string `mapstructure:"user_data"`
|
||||
UserDataFile string `mapstructure:"user_data_file"`
|
||||
Zone string `mapstructure:"zone"`
|
||||
CIDRList []string `mapstructure:"cidr_list"`
|
||||
CreateSecurityGroup bool `mapstructure:"create_security_group"`
|
||||
DiskOffering string `mapstructure:"disk_offering"`
|
||||
DiskSize int64 `mapstructure:"disk_size"`
|
||||
Expunge bool `mapstructure:"expunge"`
|
||||
Hypervisor string `mapstructure:"hypervisor"`
|
||||
InstanceName string `mapstructure:"instance_name"`
|
||||
Keypair string `mapstructure:"keypair"`
|
||||
Network string `mapstructure:"network"`
|
||||
Project string `mapstructure:"project"`
|
||||
PublicIPAddress string `mapstructure:"public_ip_address"`
|
||||
SecurityGroups []string `mapstructure:"security_groups"`
|
||||
ServiceOffering string `mapstructure:"service_offering"`
|
||||
PreventFirewallChanges bool `mapstructure:"prevent_firewall_changes"`
|
||||
SourceISO string `mapstructure:"source_iso"`
|
||||
SourceTemplate string `mapstructure:"source_template"`
|
||||
TemporaryKeypairName string `mapstructure:"temporary_keypair_name"`
|
||||
UseLocalIPAddress bool `mapstructure:"use_local_ip_address"`
|
||||
UserData string `mapstructure:"user_data"`
|
||||
UserDataFile string `mapstructure:"user_data_file"`
|
||||
Zone string `mapstructure:"zone"`
|
||||
|
||||
TemplateName string `mapstructure:"template_name"`
|
||||
TemplateDisplayText string `mapstructure:"template_display_text"`
|
||||
|
|
|
@ -117,6 +117,11 @@ func (s *stepSetupNetworking) Run(_ context.Context, state multistep.StateBag) m
|
|||
// Store the port 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 != "" {
|
||||
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")
|
||||
|
||||
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 {
|
||||
|
@ -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.Project)
|
||||
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, projectID string) (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 projectID != "" {
|
||||
p.SetProjectid(projectID)
|
||||
}
|
||||
|
||||
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(
|
||||
|
|
|
@ -117,6 +117,9 @@ builder.
|
|||
- `instance_name` (string) - The name of the instance. Defaults to
|
||||
"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.
|
||||
|
||||
- `public_ip_address` (string) - The public IP address or it's ID used for
|
||||
|
|
Loading…
Reference in New Issue