cloudstack: Updated after review (2)

This commit is contained in:
Rickard von Essen 2017-07-27 21:32:47 +02:00
parent 2fea167294
commit 858f1227af
No known key found for this signature in database
GPG Key ID: E0C0327388876CBA
1 changed files with 25 additions and 17 deletions

View File

@ -62,26 +62,34 @@ func (s *stepPrepareConfig) Run(state multistep.StateBag) multistep.StepAction {
} }
} }
if config.PublicIPAddress != "" && !isUUID(config.PublicIPAddress) { if config.PublicIPAddress != "" {
// Save the public IP address before replacing it with it's UUID. if isUUID(config.PublicIPAddress) {
state.Put("ipaddress", config.PublicIPAddress) ip, _, err := client.Address.GetPublicIpAddressByID(config.PublicIPAddress)
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Failed to retrieve IP address: %s", err))
}
state.Put("ipaddress", ip.Ipaddress)
} else {
// Save the public IP address before replacing it with it's UUID.
state.Put("ipaddress", config.PublicIPAddress)
p := client.Address.NewListPublicIpAddressesParams() p := client.Address.NewListPublicIpAddressesParams()
p.SetIpaddress(config.PublicIPAddress) p.SetIpaddress(config.PublicIPAddress)
if config.Project != "" { if config.Project != "" {
p.SetProjectid(config.Project) p.SetProjectid(config.Project)
} }
ipAddrs, err := client.Address.ListPublicIpAddresses(p) ipAddrs, err := client.Address.ListPublicIpAddresses(p)
if err != nil { if err != nil {
errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, err}) errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, err})
} }
if err == nil && ipAddrs.Count != 1 { if err == nil && ipAddrs.Count != 1 {
errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, ipAddrs}) errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, ipAddrs})
} }
if err == nil && ipAddrs.Count == 1 { if err == nil && ipAddrs.Count == 1 {
config.PublicIPAddress = ipAddrs.PublicIpAddresses[0].Id config.PublicIPAddress = ipAddrs.PublicIpAddresses[0].Id
}
} }
} }