本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/management.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Await
func Await(client management.Client, async asyncFunc) error {
requestID, err := async()
if err != nil {
return err
}
return client.WaitForOperation(requestID, nil)
}
开发者ID:garimakhulbe,项目名称:azure-sdk-for-go,代码行数:7,代码来源:integration_test.go
示例2: ExecuteAsyncOperation
// ExecuteAsyncOperation blocks until the provided asyncOperation is
// no longer in the InProgress state. Any known retryiable transient
// errors are retried and additional retry rules can be specified.
// If the operation was successful, nothing is returned, otherwise
// an error is returned.
func ExecuteAsyncOperation(client management.Client, asyncOperation func() (management.OperationID, error), extraRules ...RetryRule) error {
if asyncOperation == nil {
return fmt.Errorf("Parameter not specified: %s", "asyncOperation")
}
retryPolicy := append(newDefaultRetryPolicy(), extraRules...)
for { // retry loop for azure errors, call continue for retryable errors
operationId, err := asyncOperation()
if err == nil && operationId != "" {
log.Printf("Waiting for operation: %s", operationId)
err = client.WaitForOperation(operationId, nil)
}
if err != nil {
log.Printf("Caught error (%T) during retryable operation: %v", err, err)
// need to remove the pointer receiver in Azure SDK to make these *'s go away
if azureError, ok := err.(management.AzureError); ok {
log.Printf("Error is Azure error, checking if we should retry...")
if shouldRetry, backoff := retryPolicy.ShouldRetry(azureError); shouldRetry {
log.Printf("Error needs to be retried, sleeping %v", backoff)
time.Sleep(backoff)
continue // retry asyncOperation
}
}
}
return err
}
}
开发者ID:lopaka,项目名称:packer-azure,代码行数:34,代码来源:operations.go
示例3: ExecuteAsyncOperation
// ExecuteAsyncOperation blocks until the provided asyncOperation is
// no longer in the InProgress state. Any known retryiable transient
// errors are retried and additional retry rules can be specified.
// If the operation was successful, nothing is returned, otherwise
// an error is returned.
func ExecuteAsyncOperation(client management.Client, asyncOperation func() (management.OperationID, error), extraRules ...RetryRule) error {
if asyncOperation == nil {
return fmt.Errorf("Parameter not specified: %s", "asyncOperation")
}
retryPolicy := append(newDefaultRetryPolicy(), extraRules...)
for { // retry loop for azure errors, call continue for retryable errors
operationId, err := asyncOperation()
if err == nil {
err = client.WaitForOperation(operationId, nil)
}
if err != nil {
// need to remove the pointer receiver in Azure SDK to make these *'s go away
if azureError, ok := err.(*management.AzureError); ok {
if shouldRetry, backoff := retryPolicy.ShouldRetry(*azureError); shouldRetry {
time.Sleep(backoff)
continue // retry asyncOperation
}
}
}
return err
}
}
开发者ID:HOSTINGLabs,项目名称:packer-azure,代码行数:30,代码来源:operations.go
示例4: getAffinityGroupLocation
func getAffinityGroupLocation(client management.Client, affinityGroup string) (string, error) {
const getAffinityGroupProperties = "affinitygroups/%s"
d, err := client.SendAzureGetRequest(fmt.Sprintf(getAffinityGroupProperties, affinityGroup))
if err != nil {
return "", err
}
var afGroup struct {
Location string
}
err = xml.Unmarshal(d, &afGroup)
return afGroup.Location, err
}
开发者ID:lopaka,项目名称:packer-azure,代码行数:14,代码来源:step_validate.go
示例5: checkVirtualNetworkConfiguration
func checkVirtualNetworkConfiguration(client management.Client, vnetname, subnetname, location string) error {
const getVNetConfig = "services/networking/media"
d, err := client.SendAzureGetRequest(getVNetConfig)
if err != nil {
return err
}
var vnetConfig struct {
VNets []struct {
Name string `xml:"name,attr"`
AffinityGroup string `xml:",attr"`
Location string `xml:",attr"`
Subnets []struct {
Name string `xml:"name,attr"`
AddressPrefix string
} `xml:"Subnets>Subnet"`
} `xml:"VirtualNetworkConfiguration>VirtualNetworkSites>VirtualNetworkSite"`
}
err = xml.Unmarshal(d, &vnetConfig)
if err != nil {
return err
}
for _, vnet := range vnetConfig.VNets {
if vnet.Name == vnetname {
if vnet.AffinityGroup != "" {
vnet.Location, err = getAffinityGroupLocation(client, vnet.AffinityGroup)
if err != nil {
return err
}
}
if vnet.Location != location {
return fmt.Errorf("VNet %q is not in location %q, but in %q", vnet.Name, location, vnet.Location)
}
for _, sn := range vnet.Subnets {
if sn.Name == subnetname {
return nil
}
}
}
}
return fmt.Errorf("Could not find vnet %q and subnet %q in network configuration: %v", vnetname, subnetname, vnetConfig)
}
开发者ID:lopaka,项目名称:packer-azure,代码行数:45,代码来源:step_validate.go
示例6: GetTestStorageAccount
func GetTestStorageAccount(t *testing.T, client management.Client) storage.StorageServiceResponse {
t.Log("Retrieving storage account")
sc := storage.NewClient(client)
var sa storage.StorageServiceResponse
ssl, err := sc.ListStorageServices()
if err != nil {
t.Fatal(err)
}
rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
if len(ssl.StorageServices) == 0 {
t.Log("No storage accounts found, creating a new one")
lc := location.NewClient(client)
ll, err := lc.ListLocations()
if err != nil {
t.Fatal(err)
}
loc := ll.Locations[rnd.Intn(len(ll.Locations))].Name
t.Logf("Location for new storage account: %s", loc)
name := GenerateName()
op, err := sc.CreateStorageService(storage.StorageAccountCreateParameters{
ServiceName: name,
Label: base64.StdEncoding.EncodeToString([]byte(name)),
Location: loc,
AccountType: storage.AccountTypeStandardLRS})
if err != nil {
t.Fatal(err)
}
if err := client.WaitForOperation(op, nil); err != nil {
t.Fatal(err)
}
sa, err = sc.GetStorageService(name)
} else {
sa = ssl.StorageServices[rnd.Intn(len(ssl.StorageServices))]
}
t.Logf("Selected storage account '%s' in location '%s'",
sa.ServiceName, sa.StorageServiceProperties.Location)
return sa
}
开发者ID:garimakhulbe,项目名称:azure-sdk-for-go,代码行数:43,代码来源:integration_test.go
注:本文中的github.com/Azure/azure-sdk-for-go/management.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论