cloudstack: Updated after review (2)
This commit is contained in:
parent
2fea167294
commit
858f1227af
|
@ -62,26 +62,34 @@ func (s *stepPrepareConfig) Run(state multistep.StateBag) multistep.StepAction {
|
|||
}
|
||||
}
|
||||
|
||||
if config.PublicIPAddress != "" && !isUUID(config.PublicIPAddress) {
|
||||
// Save the public IP address before replacing it with it's UUID.
|
||||
state.Put("ipaddress", config.PublicIPAddress)
|
||||
if config.PublicIPAddress != "" {
|
||||
if isUUID(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.SetIpaddress(config.PublicIPAddress)
|
||||
p := client.Address.NewListPublicIpAddressesParams()
|
||||
p.SetIpaddress(config.PublicIPAddress)
|
||||
|
||||
if config.Project != "" {
|
||||
p.SetProjectid(config.Project)
|
||||
}
|
||||
if config.Project != "" {
|
||||
p.SetProjectid(config.Project)
|
||||
}
|
||||
|
||||
ipAddrs, err := client.Address.ListPublicIpAddresses(p)
|
||||
if err != nil {
|
||||
errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, err})
|
||||
}
|
||||
if err == nil && ipAddrs.Count != 1 {
|
||||
errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, ipAddrs})
|
||||
}
|
||||
if err == nil && ipAddrs.Count == 1 {
|
||||
config.PublicIPAddress = ipAddrs.PublicIpAddresses[0].Id
|
||||
ipAddrs, err := client.Address.ListPublicIpAddresses(p)
|
||||
if err != nil {
|
||||
errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, err})
|
||||
}
|
||||
if err == nil && ipAddrs.Count != 1 {
|
||||
errs = packer.MultiErrorAppend(errs, &retrieveErr{"IP address", config.PublicIPAddress, ipAddrs})
|
||||
}
|
||||
if err == nil && ipAddrs.Count == 1 {
|
||||
config.PublicIPAddress = ipAddrs.PublicIpAddresses[0].Id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue