MCPcopy Create free account
hub / github.com/apache/cloudstack-terraform-provider / retrieveID

Function retrieveID

cloudstack/resources.go:60–106  ·  view source on GitHub ↗
(cs *cloudstack.CloudStackClient, name string, value string, opts ...cloudstack.OptionFunc)

Source from the content-addressed store, hash-verified

58}
59
60func retrieveID(cs *cloudstack.CloudStackClient, name string, value string, opts ...cloudstack.OptionFunc) (id string, e *retrieveError) {
61 // If the supplied value isn't a ID, try to retrieve the ID ourselves
62 if cloudstack.IsID(value) {
63 return value, nil
64 }
65
66 log.Printf("[DEBUG] Retrieving ID of %s: %s", name, value)
67
68 // Ignore counts, since an error is returned if there is no exact match
69 var err error
70 switch name {
71 case "disk_offering":
72 id, _, err = cs.DiskOffering.GetDiskOfferingID(value)
73 case "service_offering":
74 id, _, err = cs.ServiceOffering.GetServiceOfferingID(value)
75 case "network_offering":
76 id, _, err = cs.NetworkOffering.GetNetworkOfferingID(value)
77 case "project":
78 id, _, err = cs.Project.GetProjectID(value)
79 case "vpc_offering":
80 id, _, err = cs.VPC.GetVPCOfferingID(value)
81 case "zone":
82 id, _, err = cs.Zone.GetZoneID(value)
83 case "os_type":
84 p := cs.GuestOS.NewListOsTypesParams()
85 p.SetDescription(value)
86 l, e := cs.GuestOS.ListOsTypes(p)
87 if e != nil {
88 err = e
89 break
90 }
91 if l.Count == 1 {
92 id = l.OsTypes[0].Id
93 break
94 }
95 err = fmt.Errorf("Could not find ID of OS Type: %s", value)
96 default:
97 return id, &retrieveError{name: name, value: value,
98 err: fmt.Errorf("Unknown request: %s", name)}
99 }
100
101 if err != nil {
102 return id, &retrieveError{name: name, value: value, err: err}
103 }
104
105 return id, nil
106}
107
108func retrieveTemplateID(cs *cloudstack.CloudStackClient, zoneid, value string) (id string, e *retrieveError) {
109 // If the supplied value isn't a ID, try to retrieve the ID ourselves

Calls

no outgoing calls