Merge pull request #3324 from vmfarms/master

Allow special "unlimited" resource ID and add project param to templates
This commit is contained in:
Sander van Harmelen 2015-10-05 13:06:09 +02:00
commit 6fb61e3d98
2 changed files with 32 additions and 2 deletions

View File

@ -51,6 +51,12 @@ func resourceCloudStackTemplate() *schema.Resource {
ForceNew: true,
},
"project": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"zone": &schema.Schema{
Type: schema.TypeString,
Required: true,
@ -161,6 +167,17 @@ func resourceCloudStackTemplateCreate(d *schema.ResourceData, meta interface{})
p.SetPasswordenabled(v.(bool))
}
// If there is a project supplied, we retrieve and set the project id
if project, ok := d.GetOk("project"); ok {
// Retrieve the project UUID
projectid, e := retrieveUUID(cs, "project", project.(string))
if e != nil {
return e.Error()
}
// Set the default project ID
p.SetProjectid(projectid)
}
// Create the new template
r, err := cs.Template.RegisterTemplate(p)
if err != nil {
@ -219,9 +236,16 @@ func resourceCloudStackTemplateRead(d *schema.ResourceData, meta interface{}) er
d.Set("password_enabled", t.Passwordenabled)
d.Set("is_ready", t.Isready)
setValueOrUUID(d, "os_type", t.Ostypename, t.Ostypeid)
setValueOrUUID(d, "zone", t.Zonename, t.Zoneid)
setValueOrUUID(d, "project", t.Project, t.Projectid)
if t.Zoneid == "" {
setValueOrUUID(d, "zone", UnlimitedResourceID, UnlimitedResourceID)
} else {
setValueOrUUID(d, "zone", t.Zonename, t.Zoneid)
}
setValueOrUUID(d, "os_type", t.Ostypename, t.Ostypeid)
return nil
}

View File

@ -10,6 +10,9 @@ import (
"github.com/xanzy/go-cloudstack/cloudstack"
)
// CloudStack uses a "special" ID of -1 to define an unlimited resource
const UnlimitedResourceID = "-1"
type retrieveError struct {
name string
value string
@ -53,6 +56,9 @@ func retrieveUUID(cs *cloudstack.CloudStackClient, name, value string) (uuid str
case "network":
uuid, err = cs.Network.GetNetworkID(value)
case "zone":
if value == UnlimitedResourceID {
return value, nil
}
uuid, err = cs.Zone.GetZoneID(value)
case "ipaddress":
p := cs.Address.NewListPublicIpAddressesParams()