本文整理匯總了Golang中github.com/rightscale/rsc/cm15.Api.InstanceLocator方法的典型用法代碼示例。如果您正苦於以下問題:Golang Api.InstanceLocator方法的具體用法?Golang Api.InstanceLocator怎麽用?Golang Api.InstanceLocator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/rightscale/rsc/cm15.Api
的用法示例。
在下文中一共展示了Api.InstanceLocator方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: serverArray
// Makes a GET call on the given server array and returns all its current instances.
func serverArray(client *cm15.Api, name string) []*cm15.Instance {
serverArrayLocator := client.ServerArrayLocator("/api/server_arrays")
serverArrays, err := serverArrayLocator.Index(rsapi.ApiParams{"view": "default", "filter": []string{"name==" + name}})
if err != nil {
fail("Failed to retrieve server array: %v\n", err.Error())
}
if len(serverArrays) == 0 {
fail("Could not find server array with name: %v\n", name)
} else if len(serverArrays) != 1 {
fail("More than one server array found with name: %v\n", name)
}
array := serverArrays[0]
var instancesHref string
for _, l := range array.Links {
if l["rel"] == "current_instances" {
instancesHref = l["href"]
break
}
}
instanceLocator := client.InstanceLocator(instancesHref)
instances, err := instanceLocator.Index(rsapi.ApiParams{})
if err != nil {
fail("Failed to retrieve current instances of the server array: %v\n", err.Error())
}
if len(instances) == 0 {
fail("No instances found in server array: %v\n", name)
}
return instances
}
示例2: instanceRetrieve
func instanceRetrieve(client *cm15.Api, instanceLocator string) *cm15.Instance {
locator := client.InstanceLocator(instanceLocator)
instance, err := locator.Show(rsapi.ApiParams{})
if err != nil {
fmt.Println("failed to find instance: %s", err)
}
return instance
}
示例3: serverArraysRetrieve
func serverArraysRetrieve(client *cm15.Api, serverArraysLocator string) []ServerArray {
arrayLocator := client.ServerArrayLocator(serverArraysLocator)
serverArrays, err := arrayLocator.Index(rsapi.ApiParams{"view": "instance_detail"})
if err != nil {
fmt.Println("failed to find servers: %s", err)
}
var serverArrayList = make([]ServerArray, len(serverArrays))
for i := 0; i < len(serverArrays); i++ {
nextInstanceLocator := extractHref(serverArrays[i].Links, "next_instance")
currentInstancesLocator := extractHref(serverArrays[i].Links, "current_instances")
var volumes []Volume
sa := ServerArray{Name: serverArrays[i].Name, Locked: false}
nextInstance := instanceRetrieve(client, nextInstanceLocator)
templateLocator := extractHref(nextInstance.Links, "server_template")
template := templateRetrieve(client, templateLocator)
sa.Template = template.Name
templates[templateLocator] = template.Name
alertSpecs := alertsRetrieve(client, extractHref(serverArrays[i].Links, "alert_specs"))
alerts = append(alerts, alertSpecs...)
sa.NextInstance = inputsRetrieve(client, extractHref(nextInstance.Links, "inputs"))
instanceLocator := client.InstanceLocator(currentInstancesLocator)
instances, err := instanceLocator.Index(rsapi.ApiParams{})
if err != nil {
fmt.Println("failed to find instances: %s", err)
}
if len(instances) != 0 {
currentInstanceLocator := extractHref(instances[0].Links, "self")
currentInstance := instanceRetrieve(client, currentInstanceLocator)
sa.CurrentInstance = inputsRetrieve(client, extractHref(currentInstance.Links, "inputs"))
sa.Locked = currentInstance.Locked
}
for _, instance := range instances {
v := extractVolumesInfo(client, extractHref(instance.Links, "self")+"/volume_attachments")
volumes = append(volumes, v...)
}
if len(volumes) != 0 {
sa.Volumes = volumes
}
serverArrayList[i] = sa
}
return serverArrayList
}