yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/qcloud/rds_sqlserver_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 SqlServerSpecInfoList struct {
    24  	Cpu             int
    25  	MachineType     string
    26  	MachineTypeName string
    27  	MaxStorage      int
    28  	Memory          int
    29  	MinStorage      int
    30  	PayModeStatus   string
    31  	Pid             int
    32  	PostPid         []int
    33  	Qps             int
    34  	RoPid           int
    35  	SpecId          int
    36  	SuitInfo        string
    37  	Version         string
    38  	VersionName     string
    39  }
    40  
    41  func (self *SRegion) DescribeSqlServerProductConfig(zoneId string) ([]SqlServerSpecInfoList, error) {
    42  	resp, err := self.sqlserverRequest("DescribeProductConfig", map[string]string{"Zone": zoneId})
    43  	if err != nil {
    44  		return nil, errors.Wrapf(err, "DescribeProductConfig")
    45  	}
    46  	specs := []SqlServerSpecInfoList{}
    47  	err = resp.Unmarshal(&specs, "SpecInfoList")
    48  	if err != nil {
    49  		return nil, errors.Wrapf(err, "resp.Unmarshal")
    50  	}
    51  	return specs, nil
    52  }
    53  
    54  func (self *SRegion) ListSQLServerSkus() ([]SDBInstanceSku, error) {
    55  	zones, err := self.GetIZones()
    56  	if err != nil {
    57  		return nil, errors.Wrapf(err, "GetIZones")
    58  	}
    59  	skus := []SDBInstanceSku{}
    60  	for _, zone := range zones {
    61  		products, err := self.DescribeSqlServerProductConfig(zone.GetId())
    62  		if err != nil {
    63  			return nil, errors.Wrapf(err, "DescribeSqlServerProductConfig")
    64  		}
    65  		for _, product := range products {
    66  			sku := SDBInstanceSku{
    67  				Region:        self.Region,
    68  				Zone1:         zone.GetId(),
    69  				Engine:        api.DBINSTANCE_TYPE_SQLSERVER,
    70  				EngineVersion: product.Version,
    71  			}
    72  			skus = append(skus, sku)
    73  		}
    74  	}
    75  	return skus, nil
    76  }