本文整理匯總了Golang中github.com/Azure/azure-sdk-for-go/arm/compute.VirtualMachinesClient.List方法的典型用法代碼示例。如果您正苦於以下問題:Golang VirtualMachinesClient.List方法的具體用法?Golang VirtualMachinesClient.List怎麽用?Golang VirtualMachinesClient.List使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/Azure/azure-sdk-for-go/arm/compute.VirtualMachinesClient
的用法示例。
在下文中一共展示了VirtualMachinesClient.List方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: virtualMachines
// virtualMachines returns a mapping of instance IDs to VirtualMachines and
// errors, for each of the specified instance IDs.
func (v *azureVolumeSource) virtualMachines(instanceIds []instance.Id) (map[instance.Id]*maybeVirtualMachine, error) {
vmsClient := compute.VirtualMachinesClient{v.env.compute}
var result compute.VirtualMachineListResult
if err := v.env.callAPI(func() (autorest.Response, error) {
var err error
result, err = vmsClient.List(v.env.resourceGroup)
return result.Response, err
}); err != nil {
return nil, errors.Annotate(err, "listing virtual machines")
}
all := make(map[instance.Id]*compute.VirtualMachine)
if result.Value != nil {
for _, vm := range *result.Value {
vmCopy := vm
all[instance.Id(to.String(vm.Name))] = &vmCopy
}
}
results := make(map[instance.Id]*maybeVirtualMachine)
for _, id := range instanceIds {
result := &maybeVirtualMachine{vm: all[id]}
if result.vm == nil {
result.err = errors.NotFoundf("instance %v", id)
}
results[id] = result
}
return results, nil
}
示例2: allInstances
// allInstances returns all of the instances in the given resource group,
// and optionally ensures that each instance's addresses are up-to-date.
func (env *azureEnviron) allInstances(
resourceGroup string,
refreshAddresses bool,
) ([]instance.Instance, error) {
env.mu.Lock()
vmClient := compute.VirtualMachinesClient{env.compute}
nicClient := network.InterfacesClient{env.network}
pipClient := network.PublicIPAddressesClient{env.network}
env.mu.Unlock()
// Due to how deleting instances works, we have to get creative about
// listing instances. We list NICs and return an instance for each
// unique value of the jujuMachineNameTag tag.
//
// The machine provisioner will call AllInstances so it can delete
// unknown instances. StopInstances must delete VMs before NICs and
// public IPs, because a VM cannot have less than 1 NIC. Thus, we can
// potentially delete a VM but then fail to delete its NIC.
nicsResult, err := nicClient.List(resourceGroup)
if err != nil {
if nicsResult.Response.Response != nil && nicsResult.StatusCode == http.StatusNotFound {
// This will occur if the resource group does not
// exist, e.g. in a fresh hosted environment.
return nil, nil
}
return nil, errors.Trace(err)
}
if nicsResult.Value == nil || len(*nicsResult.Value) == 0 {
return nil, nil
}
// Create an azureInstance for each VM.
result, err := vmClient.List(resourceGroup)
if err != nil {
return nil, errors.Annotate(err, "listing virtual machines")
}
vmNames := make(set.Strings)
var azureInstances []*azureInstance
if result.Value != nil {
azureInstances = make([]*azureInstance, len(*result.Value))
for i, vm := range *result.Value {
inst := &azureInstance{vm, env, nil, nil}
azureInstances[i] = inst
vmNames.Add(to.String(vm.Name))
}
}
// Create additional azureInstances for NICs without machines. See
// comments above for rationale. This needs to happen before calling
// setInstanceAddresses, so we still associate the NICs/PIPs.
for _, nic := range *nicsResult.Value {
vmName, ok := toTags(nic.Tags)[jujuMachineNameTag]
if !ok || vmNames.Contains(vmName) {
continue
}
vm := compute.VirtualMachine{
Name: to.StringPtr(vmName),
Properties: &compute.VirtualMachineProperties{
ProvisioningState: to.StringPtr("Partially Deleted"),
},
}
inst := &azureInstance{vm, env, nil, nil}
azureInstances = append(azureInstances, inst)
vmNames.Add(to.String(vm.Name))
}
if len(azureInstances) > 0 && refreshAddresses {
if err := setInstanceAddresses(
pipClient, resourceGroup, azureInstances, nicsResult,
); err != nil {
return nil, errors.Trace(err)
}
}
instances := make([]instance.Instance, len(azureInstances))
for i, inst := range azureInstances {
instances[i] = inst
}
return instances, nil
}