mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-19 10:46:58 +08:00
Merge pull request #2680 from swordqiu/hotfix/qj-auzre-create-bucket-fail
fix: azure create bucket failure due to empty storageClass
This commit is contained in:
@@ -906,9 +906,15 @@ func (self *SAzureClient) GetIProjects() ([]cloudprovider.ICloudProject, error)
|
||||
}
|
||||
|
||||
func (self *SAzureClient) GetStorageClasses(regionExtId string) ([]string, error) {
|
||||
iRegion, err := self.GetIRegionById(regionExtId)
|
||||
var iRegion cloudprovider.ICloudRegion
|
||||
var err error
|
||||
if regionExtId == "" {
|
||||
iRegion, err = self.getDefaultRegion()
|
||||
} else {
|
||||
iRegion, err = self.GetIRegionById(regionExtId)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "self.GetIRegionById")
|
||||
return nil, errors.Wrapf(err, "self.GetIRegionById %s", regionExtId)
|
||||
}
|
||||
skus, err := iRegion.(*SRegion).GetStorageAccountSkus()
|
||||
if err != nil {
|
||||
|
||||
@@ -27,7 +27,7 @@ type ClassicStorageProperties struct {
|
||||
ProvisioningState string
|
||||
Status string
|
||||
Endpoints []string
|
||||
AccountType string
|
||||
AccountType string `json:"accountType"`
|
||||
GeoPrimaryRegion string
|
||||
StatusOfPrimaryRegion string
|
||||
GeoSecondaryRegion string
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/log"
|
||||
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
@@ -175,7 +175,7 @@ func (self *SAzureProvider) GetIProjects() ([]cloudprovider.ICloudProject, error
|
||||
func (self *SAzureProvider) GetStorageClasses(regionId string) []string {
|
||||
sc, err := self.client.GetStorageClasses(regionId)
|
||||
if err != nil {
|
||||
log.Errorf("Fail to find storage classes")
|
||||
log.Errorf("Fail to find storage classes: %s", err)
|
||||
return nil
|
||||
}
|
||||
return sc
|
||||
|
||||
@@ -632,7 +632,7 @@ func (region *SRegion) GetIBuckets() ([]cloudprovider.ICloudBucket, error) {
|
||||
func (region *SRegion) CreateIBucket(name string, storageClassStr string, acl string) error {
|
||||
_, err := region.createStorageAccount(name, storageClassStr)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "region.createStorageAccount")
|
||||
return errors.Wrapf(err, "region.createStorageAccount name=%s storageClass=%s acl=%s", name, storageClassStr, acl)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -16,10 +16,12 @@ package azure
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -32,8 +34,6 @@ import (
|
||||
"yunion.io/x/pkg/errors"
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"encoding/base64"
|
||||
"strconv"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/multicloud"
|
||||
@@ -227,17 +227,24 @@ func (self *SRegion) getStorageAccountSkuByName(name string) (*SStorageAccountSk
|
||||
}
|
||||
|
||||
func (self *SRegion) createStorageAccount(name string, skuName string) (*SStorageAccount, error) {
|
||||
sku, err := self.getStorageAccountSkuByName(skuName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getStorageAccountSkuByName")
|
||||
storageKind := "Storage"
|
||||
if len(skuName) > 0 {
|
||||
sku, err := self.getStorageAccountSkuByName(skuName)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "getStorageAccountSkuByName")
|
||||
}
|
||||
skuName = sku.Name
|
||||
storageKind = sku.Kind
|
||||
} else {
|
||||
skuName = "Standard_GRS"
|
||||
}
|
||||
stoargeaccount := SStorageAccount{
|
||||
region: self,
|
||||
Sku: SSku{
|
||||
Name: sku.Name,
|
||||
},
|
||||
storageaccount := SStorageAccount{
|
||||
region: self,
|
||||
Location: self.Name,
|
||||
Kind: "Storage",
|
||||
Sku: SSku{
|
||||
Name: skuName,
|
||||
},
|
||||
Kind: storageKind,
|
||||
Properties: AccountProperties{
|
||||
IsHnsEnabled: true,
|
||||
AzureFilesAadIntegration: true,
|
||||
@@ -245,12 +252,13 @@ func (self *SRegion) createStorageAccount(name string, skuName string) (*SStorag
|
||||
Name: name,
|
||||
Type: "Microsoft.Storage/storageAccounts",
|
||||
}
|
||||
err = self.client.Create(jsonutils.Marshal(stoargeaccount), &stoargeaccount)
|
||||
|
||||
err := self.client.Create(jsonutils.Marshal(storageaccount), &storageaccount)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "Create")
|
||||
}
|
||||
self.client.invalidateIBuckets()
|
||||
return &stoargeaccount, nil
|
||||
return &storageaccount, nil
|
||||
}
|
||||
|
||||
func (self *SRegion) CreateStorageAccount(storageAccount string) (*SStorageAccount, error) {
|
||||
|
||||
@@ -43,7 +43,7 @@ func S3Shell() {
|
||||
type BucketCreateOptions struct {
|
||||
NAME string `help:"name of bucket to create"`
|
||||
Acl string `help:"ACL string" choices:"private|public-read|public-read-write"`
|
||||
StorageClass string `help:"StorageClass" choices:"STANDARD|IA|ARCHIVE"`
|
||||
StorageClass string `help:"StorageClass"`
|
||||
}
|
||||
shellutils.R(&BucketCreateOptions{}, "bucket-create", "Create bucket", func(cli cloudprovider.ICloudRegion, args *BucketCreateOptions) error {
|
||||
err := cli.CreateIBucket(args.NAME, args.StorageClass, args.Acl)
|
||||
|
||||
Reference in New Issue
Block a user