Merge pull request #6487 from sermilrod/Honour-cloudstack-projectid

Honour cloudstack projectid
This commit is contained in:
Sander van Harmelen 2018-07-16 13:53:06 +02:00 committed by GitHub
commit 451cbd8aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 26 deletions

View File

@ -27,26 +27,27 @@ type Config struct {
HTTPGetOnly bool `mapstructure:"http_get_only"` HTTPGetOnly bool `mapstructure:"http_get_only"`
SSLNoVerify bool `mapstructure:"ssl_no_verify"` SSLNoVerify bool `mapstructure:"ssl_no_verify"`
CIDRList []string `mapstructure:"cidr_list"` CIDRList []string `mapstructure:"cidr_list"`
CreateSecurityGroup bool `mapstructure:"create_security_group"` CreateSecurityGroup bool `mapstructure:"create_security_group"`
DiskOffering string `mapstructure:"disk_offering"` DiskOffering string `mapstructure:"disk_offering"`
DiskSize int64 `mapstructure:"disk_size"` DiskSize int64 `mapstructure:"disk_size"`
Expunge bool `mapstructure:"expunge"` Expunge bool `mapstructure:"expunge"`
Hypervisor string `mapstructure:"hypervisor"` Hypervisor string `mapstructure:"hypervisor"`
InstanceName string `mapstructure:"instance_name"` InstanceName string `mapstructure:"instance_name"`
Keypair string `mapstructure:"keypair"` Keypair string `mapstructure:"keypair"`
Network string `mapstructure:"network"` Network string `mapstructure:"network"`
Project string `mapstructure:"project"` Project string `mapstructure:"project"`
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"`
SourceISO string `mapstructure:"source_iso"` PreventFirewallChanges bool `mapstructure:"prevent_firewall_changes"`
SourceTemplate string `mapstructure:"source_template"` SourceISO string `mapstructure:"source_iso"`
TemporaryKeypairName string `mapstructure:"temporary_keypair_name"` SourceTemplate string `mapstructure:"source_template"`
UseLocalIPAddress bool `mapstructure:"use_local_ip_address"` TemporaryKeypairName string `mapstructure:"temporary_keypair_name"`
UserData string `mapstructure:"user_data"` UseLocalIPAddress bool `mapstructure:"use_local_ip_address"`
UserDataFile string `mapstructure:"user_data_file"` UserData string `mapstructure:"user_data"`
Zone string `mapstructure:"zone"` UserDataFile string `mapstructure:"user_data_file"`
Zone string `mapstructure:"zone"`
TemplateName string `mapstructure:"template_name"` TemplateName string `mapstructure:"template_name"`
TemplateDisplayText string `mapstructure:"template_display_text"` TemplateDisplayText string `mapstructure:"template_display_text"`

View File

@ -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...")

View File

@ -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 {

View File

@ -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 {

View File

@ -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(

View File

@ -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