yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/rds_mariadb_sku.go (about) 1 // Copyright 2019 Yunion 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package qcloud 16 17 import ( 18 "yunion.io/x/pkg/errors" 19 20 api "yunion.io/x/cloudmux/pkg/apis/compute" 21 ) 22 23 var ( 24 SUPPORTED_ENGINE_VERSION = []string{"5.7", "10.0", "10.1"} 25 ) 26 27 type SaleZoneInfo struct { 28 Zone string 29 ZoneId string 30 ZoneName string 31 } 32 33 type SAvailableChoice struct { 34 MasterZone SaleZoneInfo 35 SlaveZones []SaleZoneInfo 36 } 37 38 type SRegionSaleInfo struct { 39 AvailableChoice []SAvailableChoice 40 Region string 41 RegionId string 42 RegionName string 43 ZoneList []SaleZoneInfo 44 } 45 46 func (self *SRegion) DescribeSaleInfo() ([]SRegionSaleInfo, error) { 47 resp, err := self.mariadbRequest("DescribeSaleInfo", map[string]string{}) 48 if err != nil { 49 return nil, errors.Wrapf(err, "DescribeSaleInfo") 50 } 51 saleInfo := []SRegionSaleInfo{} 52 err = resp.Unmarshal(&saleInfo, "RegionList") 53 if err != nil { 54 return nil, errors.Wrapf(err, "resp.Unmarshal") 55 } 56 return saleInfo, nil 57 } 58 59 type SInstanceSpec struct { 60 Cpu int 61 Machine string 62 MaxStorage int 63 Memory int 64 MinStorage int 65 NodeCount int 66 Pid int 67 Qps int 68 SuitInfo string 69 } 70 71 type SInstanceSpecs struct { 72 Machine string 73 SpecInfos []SInstanceSpec 74 } 75 76 func (self *SRegion) DescribeDBInstanceSpecs() ([]SInstanceSpecs, error) { 77 resp, err := self.mariadbRequest("DescribeDBInstanceSpecs", map[string]string{}) 78 if err != nil { 79 return nil, errors.Wrapf(err, "DescribeDBInstanceSpecs") 80 } 81 specs := []SInstanceSpecs{} 82 err = resp.Unmarshal(&specs, "Specs") 83 if err != nil { 84 return nil, errors.Wrapf(err, "resp.Unmarshal") 85 } 86 return specs, nil 87 } 88 89 func (self *SRegion) ListMariadbSkus() ([]SDBInstanceSku, error) { 90 skus := []SDBInstanceSku{} 91 92 saleRegions, err := self.DescribeSaleInfo() 93 if err != nil { 94 return nil, errors.Wrapf(err, "DescribeSaleInfo") 95 } 96 97 for _, saleRegion := range saleRegions { 98 if saleRegion.Region == self.Region { 99 specs, err := self.DescribeDBInstanceSpecs() 100 if err != nil { 101 return nil, errors.Wrapf(err, "DescribeDBInstanceSpecs") 102 } 103 for _, spec := range specs { 104 for _, info := range spec.SpecInfos { 105 sku := SDBInstanceSku{ 106 Region: self.Region, 107 Engine: api.DBINSTANCE_TYPE_MARIADB, 108 Cpu: info.Cpu, 109 StorageMax: info.MaxStorage, 110 StorageMin: info.MinStorage, 111 StorageStep: 10, 112 MemoryMb: info.Memory * 1024, 113 Qps: info.Qps, 114 Description: info.SuitInfo, 115 Category: "标准版", 116 Status: api.DBINSTANCE_SKU_AVAILABLE, 117 } 118 if info.NodeCount == 3 { 119 sku.Category = "金融版" 120 } 121 for _, engineVersion := range SUPPORTED_ENGINE_VERSION { 122 sku.EngineVersion = engineVersion 123 sku.Zone2 = "" 124 for _, zone := range saleRegion.AvailableChoice { 125 sku.Zone1 = zone.MasterZone.Zone 126 for _, slaveZone := range zone.SlaveZones { 127 sku.Zone2 = slaveZone.Zone 128 skus = append(skus, sku) 129 } 130 } 131 } 132 } 133 } 134 } 135 } 136 return skus, nil 137 }