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 76efc9b788..fe45963a9c 100644 --- a/pkg/util/qcloud/zone.go +++ b/pkg/util/qcloud/zone.go @@ -94,11 +94,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}