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()
|
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
|
// Retrieve the zone object
|
||||||
zone, _, err := cs.Zone.GetZoneByName(d.Get("zone").(string))
|
zone, _, err := cs.Zone.GetZoneByName(d.Get("zone").(string))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// Create a new parameter struct
|
||||||
p := cs.VirtualMachine.NewDeployVirtualMachineParams(serviceofferingid, templateid, zone.Id)
|
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)
|
uuid, err = cs.VPC.GetVPCOfferingID(value)
|
||||||
case "vpc":
|
case "vpc":
|
||||||
uuid, err = cs.VPC.GetVPCID(value)
|
uuid, err = cs.VPC.GetVPCID(value)
|
||||||
case "template":
|
|
||||||
uuid, err = cs.Template.GetTemplateID(value, "executable")
|
|
||||||
case "network":
|
case "network":
|
||||||
uuid, err = cs.Network.GetNetworkID(value)
|
uuid, err = cs.Network.GetNetworkID(value)
|
||||||
case "zone":
|
case "zone":
|
||||||
|
@ -71,6 +69,22 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
|
||||||
return uuid, nil
|
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 {
|
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}$`)
|
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)
|
return re.MatchString(s)
|
||||||
|
|
Loading…
Reference in New Issue