Fixing a corner case while retrieving a template UUID
Added some logic to the go-cloudstack package to support a more customised call to GetTemplateID in order to get the correct/expected UUID.
This commit is contained in:
parent
bb7ef8db67
commit
bb88adb5a3
|
@ -95,18 +95,18 @@ func resourceCloudStackInstanceCreate(d *schema.ResourceData, meta interface{})
|
|||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the template UUID
|
||||
templateid, e := retrieveUUID(cs, "template", d.Get("template").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Retrieve the zone object
|
||||
zone, _, err := cs.Zone.GetZoneByName(d.Get("zone").(string))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Retrieve the template UUID
|
||||
templateid, e := retrieveTemplateUUID(cs, zone.Id, d.Get("template").(string))
|
||||
if e != nil {
|
||||
return e.Error()
|
||||
}
|
||||
|
||||
// Create a new parameter struct
|
||||
p := cs.VirtualMachine.NewDeployVirtualMachineParams(serviceofferingid, templateid, zone.Id)
|
||||
|
||||
|
|
|
@ -40,8 +40,6 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
|
|||
uuid, err = cs.VPC.GetVPCOfferingID(value)
|
||||
case "vpc":
|
||||
uuid, err = cs.VPC.GetVPCID(value)
|
||||
case "template":
|
||||
uuid, err = cs.Template.GetTemplateID(value, "executable")
|
||||
case "network":
|
||||
uuid, err = cs.Network.GetNetworkID(value)
|
||||
case "zone":
|
||||
|
@ -71,6 +69,22 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
|
|||
return uuid, nil
|
||||
}
|
||||
|
||||
func retrieveTemplateUUID(cs *cloudstack.CloudStackClient, zoneid, value string) (uuid string, e *retrieveError) {
|
||||
// If the supplied value isn't a UUID, try to retrieve the UUID ourselves
|
||||
if isUUID(value) {
|
||||
return value, nil
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Retrieving UUID of template: %s", value)
|
||||
|
||||
uuid, err := cs.Template.GetTemplateID(value, "executable", zoneid)
|
||||
if err != nil {
|
||||
return uuid, &retrieveError{name: "template", value: value, err: err}
|
||||
}
|
||||
|
||||
return uuid, nil
|
||||
}
|
||||
|
||||
func isUUID(s string) bool {
|
||||
re := regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)
|
||||
return re.MatchString(s)
|
||||
|
|
Loading…
Reference in New Issue