From 060ae5718babdded52c8ad014f849c4f688587c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=88=E8=BD=A9?= Date: Thu, 3 Jan 2019 16:19:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=AD=A5=E8=85=BE?= =?UTF-8?q?=E8=AE=AF=E4=BA=91storage=20type=E6=95=B0=E6=8D=AE=E4=B8=8D?= =?UTF-8?q?=E5=87=86=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/util/qcloud/shell/storage.go | 20 ++++++++++++++++ pkg/util/qcloud/zone.go | 39 +++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 pkg/util/qcloud/shell/storage.go diff --git a/pkg/util/qcloud/shell/storage.go b/pkg/util/qcloud/shell/storage.go new file mode 100644 index 0000000000..8ba917d896 --- /dev/null +++ b/pkg/util/qcloud/shell/storage.go @@ -0,0 +1,20 @@ +package shell + +import ( + "yunion.io/x/onecloud/pkg/util/qcloud" + "yunion.io/x/onecloud/pkg/util/shellutils" +) + +func init() { + type StorageListOptions struct { + ZONE string `help:"ID or Name of zone"` + } + shellutils.R(&StorageListOptions{}, "storage-list", "List storages", func(cli *qcloud.SRegion, args *StorageListOptions) error { + storages, err := cli.GetDiskConfigSet(args.ZONE) + if err != nil { + return err + } + printList(storages, 0, 0, 0, []string{}) + return nil + }) +} diff --git a/pkg/util/qcloud/zone.go b/pkg/util/qcloud/zone.go index 6f3f2f9f7d..5e0aa2a8ca 100644 --- a/pkg/util/qcloud/zone.go +++ b/pkg/util/qcloud/zone.go @@ -93,11 +93,44 @@ func (self *SZone) GetIRegion() cloudprovider.ICloudRegion { return self.region } +type SDiskConfigSet struct { + Available bool + DeviceClass string + DiskChargeType string + DiskType string + DiskUsage string + InstanceFamily string + MaxDiskSize int + MinDiskSize int + Zone string +} + +func (self *SRegion) GetDiskConfigSet(zoneName string) ([]SDiskConfigSet, error) { + params := map[string]string{} + params["Region"] = self.Region + params["Zones.0"] = zoneName + params["InquiryType"] = "INQUIRY_CBS_CONFIG" + body, err := self.cbsRequest("DescribeDiskConfigQuota", params) + if err != nil { + return nil, err + } + diskConfigSet := []SDiskConfigSet{} + return diskConfigSet, body.Unmarshal(&diskConfigSet, "DiskConfigSet") +} + func (self *SZone) fetchStorages() error { self.istorages = []cloudprovider.ICloudStorage{} - for _, storageType := range []string{"CLOUD_BASIC", "CLOUD_PREMIUM", "CLOUD_SSD"} { - storage := SStorage{zone: self, storageType: storageType} - self.istorages = append(self.istorages, &storage) + diskConfigSet, err := self.region.GetDiskConfigSet(self.Zone) + if err != nil { + return err + } + storageTypes := []string{} + for _, diskConfig := range diskConfigSet { + if diskConfig.Available && !utils.IsInStringArray(diskConfig.DiskType, storageTypes) { + storageTypes = append(storageTypes, diskConfig.DiskType) + storage := SStorage{zone: self, storageType: diskConfig.DiskType} + self.istorages = append(self.istorages, &storage) + } } for _, localstorageType := range []string{"LOCAL_BASIC", "LOCAL_SSD"} { storage := SLocalStorage{zone: self, storageType: localstorageType}