Exemple #1
0
func setValueOrID(d *schema.ResourceData, key string, value string, id string) {
	if cloudstack.IsID(d.Get(key).(string)) {
		// If the given id is an empty string, check if the configured value matches
		// the UnlimitedResourceID in which case we set id to UnlimitedResourceID
		if id == "" && d.Get(key).(string) == cloudstack.UnlimitedResourceID {
			id = cloudstack.UnlimitedResourceID
		}

		d.Set(key, id)
	} else {
		d.Set(key, value)
	}
}
Exemple #2
0
func retrieveTemplateID(cs *cloudstack.CloudStackClient, zoneid, value string) (id string, e *retrieveError) {
	// If the supplied value isn't a ID, try to retrieve the ID ourselves
	if cloudstack.IsID(value) {
		return value, nil
	}

	log.Printf("[DEBUG] Retrieving ID of template: %s", value)

	id, err := cs.Template.GetTemplateID(value, "executable", zoneid)
	if err != nil {
		return id, &retrieveError{name: "template", value: value, err: err}
	}

	return id, nil
}
Exemple #3
0
func retrieveID(cs *cloudstack.CloudStackClient, name string, value string, opts ...cloudstack.OptionFunc) (id string, e *retrieveError) {
	// If the supplied value isn't a ID, try to retrieve the ID ourselves
	if cloudstack.IsID(value) {
		return value, nil
	}

	log.Printf("[DEBUG] Retrieving ID of %s: %s", name, value)

	// Ignore counts, since an error is returned if there is no exact match
	var err error
	switch name {
	case "disk_offering":
		id, _, err = cs.DiskOffering.GetDiskOfferingID(value)
	case "service_offering":
		id, _, err = cs.ServiceOffering.GetServiceOfferingID(value)
	case "network_offering":
		id, _, err = cs.NetworkOffering.GetNetworkOfferingID(value)
	case "project":
		id, _, err = cs.Project.GetProjectID(value)
	case "vpc_offering":
		id, _, err = cs.VPC.GetVPCOfferingID(value)
	case "zone":
		id, _, err = cs.Zone.GetZoneID(value)
	case "os_type":
		p := cs.GuestOS.NewListOsTypesParams()
		p.SetDescription(value)
		l, e := cs.GuestOS.ListOsTypes(p)
		if e != nil {
			err = e
			break
		}
		if l.Count == 1 {
			id = l.OsTypes[0].Id
			break
		}
		err = fmt.Errorf("Could not find ID of OS Type: %s", value)
	default:
		return id, &retrieveError{name: name, value: value,
			err: fmt.Errorf("Unknown request: %s", name)}
	}

	if err != nil {
		return id, &retrieveError{name: name, value: value, err: err}
	}

	return id, nil
}
Exemple #4
0
func retrieveID(
	cs *cloudstack.CloudStackClient,
	name string,
	value string,
	opts ...cloudstack.OptionFunc) (id string, e *retrieveError) {
	// If the supplied value isn't a ID, try to retrieve the ID ourselves
	if cloudstack.IsID(value) {
		return value, nil
	}

	log.Printf("[DEBUG] Retrieving ID of %s: %s", name, value)

	var err error
	switch name {
	case "disk_offering":
		id, err = cs.DiskOffering.GetDiskOfferingID(value)
	case "virtual_machine":
		id, err = cs.VirtualMachine.GetVirtualMachineID(value, opts...)
	case "service_offering":
		id, err = cs.ServiceOffering.GetServiceOfferingID(value)
	case "network_offering":
		id, err = cs.NetworkOffering.GetNetworkOfferingID(value)
	case "project":
		id, err = cs.Project.GetProjectID(value)
	case "vpc_offering":
		id, err = cs.VPC.GetVPCOfferingID(value)
	case "vpc":
		id, err = cs.VPC.GetVPCID(value, opts...)
	case "network":
		id, err = cs.Network.GetNetworkID(value, opts...)
	case "zone":
		id, err = cs.Zone.GetZoneID(value)
	case "ip_address":
		p := cs.Address.NewListPublicIpAddressesParams()
		p.SetIpaddress(value)
		for _, fn := range opts {
			if e := fn(cs, p); e != nil {
				err = e
				break
			}
		}
		l, e := cs.Address.ListPublicIpAddresses(p)
		if e != nil {
			err = e
			break
		}
		if l.Count == 1 {
			id = l.PublicIpAddresses[0].Id
			break
		}
		err = fmt.Errorf("Could not find ID of IP address: %s", value)
	case "os_type":
		p := cs.GuestOS.NewListOsTypesParams()
		p.SetDescription(value)
		l, e := cs.GuestOS.ListOsTypes(p)
		if e != nil {
			err = e
			break
		}
		if l.Count == 1 {
			id = l.OsTypes[0].Id
			break
		}
		err = fmt.Errorf("Could not find ID of OS Type: %s", value)
	default:
		return id, &retrieveError{name: name, value: value,
			err: fmt.Errorf("Unknown request: %s", name)}
	}

	if err != nil {
		return id, &retrieveError{name: name, value: value, err: err}
	}

	return id, nil
}