yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/rds_postgre_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  type SpecItemInfoList struct {
    24  	SpecCode    string
    25  	Version     string
    26  	VersionName string
    27  	Cpu         int
    28  	Memory      int
    29  	MaxStorage  int
    30  	MinStorage  int
    31  	Qps         int
    32  	Pid         int
    33  	Type        string
    34  }
    35  
    36  type SpecInfoList struct {
    37  	Region           string
    38  	Zone             string
    39  	SpecItemInfoList []SpecItemInfoList
    40  }
    41  
    42  func (self *SRegion) DescribeProductConfig() ([]SpecInfoList, error) {
    43  	resp, err := self.postgresRequest("DescribeProductConfig", map[string]string{})
    44  	if err != nil {
    45  		return nil, errors.Wrapf(err, "DescribeProductConfig")
    46  	}
    47  	products := []SpecInfoList{}
    48  	err = resp.Unmarshal(&products, "SpecInfoList")
    49  	if err != nil {
    50  		return nil, errors.Wrapf(err, "resp.Unmarshal")
    51  	}
    52  	return products, nil
    53  }
    54  
    55  func (self *SRegion) ListPostgreSQLSkus() ([]SDBInstanceSku, error) {
    56  	skus := []SDBInstanceSku{}
    57  	products, err := self.DescribeProductConfig()
    58  	if err != nil {
    59  		return nil, errors.Wrapf(err, "DescribeProductConfig")
    60  	}
    61  	for _, product := range products {
    62  		sku := SDBInstanceSku{
    63  			Region:   self.Region,
    64  			Zone1:    product.Zone,
    65  			Engine:   api.DBINSTANCE_TYPE_POSTGRESQL,
    66  			Status:   api.DBINSTANCE_SKU_AVAILABLE,
    67  			Category: "双机高可用",
    68  		}
    69  
    70  		for _, spec := range product.SpecItemInfoList {
    71  			sku.EngineVersion = spec.Version
    72  			sku.Qps = spec.Qps
    73  			sku.Cpu = spec.Cpu
    74  			sku.MemoryMb = spec.Memory * 1024
    75  			sku.StorageMax = spec.MaxStorage
    76  			sku.StorageMin = spec.MinStorage
    77  			sku.StorageStep = 10
    78  
    79  			skus = append(skus, sku)
    80  		}
    81  	}
    82  	return skus, nil
    83  }