本文整理汇总了Golang中github.com/Azure/azure-sdk-for-go/arm/storage.AccountsClient类的典型用法代码示例。如果您正苦于以下问题:Golang AccountsClient类的具体用法?Golang AccountsClient怎么用?Golang AccountsClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AccountsClient类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: getStorageAccountLocked
func (env *azureEnviron) getStorageAccountLocked(refresh bool) (*storage.Account, error) {
if !refresh && env.storageAccount != nil {
return env.storageAccount, nil
}
client := storage.AccountsClient{env.storage}
var account storage.Account
if err := env.callAPI(func() (autorest.Response, error) {
var err error
account, err = client.GetProperties(env.resourceGroup, env.storageAccountName)
return account.Response, err
}); err != nil {
if account.Response.Response != nil && account.Response.StatusCode == http.StatusNotFound {
return nil, errors.NewNotFound(err, fmt.Sprintf("storage account not found"))
}
return nil, errors.Annotate(err, "getting storage account")
}
env.storageAccount = &account
return env.storageAccount, nil
}
开发者ID:bac,项目名称:juju,代码行数:19,代码来源:environ.go
示例2: getStorageAccountKey
// getStorageAccountKey returns the key for the storage account.
func getStorageAccountKey(
callAPI callAPIFunc,
client armstorage.AccountsClient,
resourceGroup, accountName string,
) (*armstorage.AccountKey, error) {
logger.Debugf("getting keys for storage account %q", accountName)
var listKeysResult armstorage.AccountListKeysResult
if err := callAPI(func() (autorest.Response, error) {
var err error
listKeysResult, err = client.ListKeys(resourceGroup, accountName)
return listKeysResult.Response, err
}); err != nil {
if listKeysResult.Response.Response != nil && listKeysResult.StatusCode == http.StatusNotFound {
return nil, errors.NewNotFound(err, "storage account keys not found")
}
return nil, errors.Annotate(err, "listing storage account keys")
}
if listKeysResult.Keys == nil {
return nil, errors.NotFoundf("storage account keys")
}
// We need a storage key with full permissions.
var fullKey *armstorage.AccountKey
for _, key := range *listKeysResult.Keys {
logger.Debugf("storage account key: %#v", key)
// At least some of the time, Azure returns the permissions
// in title-case, which does not match the constant.
if strings.ToUpper(string(key.Permissions)) != string(armstorage.FULL) {
continue
}
fullKey = &key
break
}
if fullKey == nil {
return nil, errors.NotFoundf(
"storage account key with %q permission",
armstorage.FULL,
)
}
return fullKey, nil
}
开发者ID:bac,项目名称:juju,代码行数:42,代码来源:storage.go
示例3: createStorageAccount
func createStorageAccount(
client storage.AccountsClient,
accountType storage.AccountType,
resourceGroup string,
location string,
tags map[string]string,
accountNameGenerator func() string,
) (string, string, error) {
logger.Debugf("creating storage account (finding available name)")
const maxAttempts = 10
for remaining := maxAttempts; remaining > 0; remaining-- {
accountName := accountNameGenerator()
logger.Debugf("- checking storage account name %q", accountName)
result, err := client.CheckNameAvailability(
storage.AccountCheckNameAvailabilityParameters{
Name: to.StringPtr(accountName),
// Azure is a little inconsistent with when Type is
// required. It's required here.
Type: to.StringPtr("Microsoft.Storage/storageAccounts"),
},
)
if err != nil {
return "", "", errors.Annotate(err, "checking account name availability")
}
if !to.Bool(result.NameAvailable) {
logger.Debugf(
"%q is not available (%v): %v",
accountName, result.Reason, result.Message,
)
continue
}
createParams := storage.AccountCreateParameters{
Location: to.StringPtr(location),
Tags: toTagsPtr(tags),
Properties: &storage.AccountPropertiesCreateParameters{
AccountType: accountType,
},
}
logger.Debugf("- creating %q storage account %q", accountType, accountName)
// TODO(axw) account creation can fail if the account name is
// available, but contains profanity. We should retry a set
// number of times even if creating fails.
if _, err := client.Create(resourceGroup, accountName, createParams); err != nil {
return "", "", errors.Trace(err)
}
logger.Debugf("- listing storage account keys")
listKeysResult, err := client.ListKeys(resourceGroup, accountName)
if err != nil {
return "", "", errors.Annotate(err, "listing storage account keys")
}
return accountName, to.String(listKeysResult.Key1), nil
}
return "", "", errors.New("could not find available storage account name")
}
开发者ID:makyo,项目名称:juju,代码行数:54,代码来源:environ.go
注:本文中的github.com/Azure/azure-sdk-for-go/arm/storage.AccountsClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论