yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/aliyun/instancetype.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 aliyun
    16  
    17  import (
    18  	// "time"
    19  	"yunion.io/x/log"
    20  )
    21  
    22  // {"CpuCoreCount":1,"EniQuantity":1,"GPUAmount":0,"GPUSpec":"","InstanceTypeFamily":"ecs.t1","InstanceTypeId":"ecs.t1.xsmall","LocalStorageCategory":"","MemorySize":0.500000}
    23  // InstanceBandwidthRx":26214400,"InstanceBandwidthTx":26214400,"InstancePpsRx":4500000,"InstancePpsTx":4500000
    24  
    25  type SInstanceType struct {
    26  	BaselineCredit       int
    27  	CpuCoreCount         int
    28  	MemorySize           float32
    29  	EniQuantity          int // 实例规格支持网卡数量
    30  	GPUAmount            int
    31  	GPUSpec              string
    32  	InstanceTypeFamily   string
    33  	InstanceFamilyLevel  string
    34  	InstanceTypeId       string
    35  	LocalStorageCategory string
    36  	LocalStorageAmount   int
    37  	LocalStorageCapacity int64
    38  	InstanceBandwidthRx  int
    39  	InstanceBandwidthTx  int
    40  	InstancePpsRx        int
    41  	InstancePpsTx        int
    42  }
    43  
    44  func (self *SRegion) GetInstanceTypes() ([]SInstanceType, error) {
    45  	params := make(map[string]string)
    46  	params["RegionId"] = self.RegionId
    47  
    48  	body, err := self.ecsRequest("DescribeInstanceTypes", params)
    49  	if err != nil {
    50  		log.Errorf("GetInstanceTypes fail %s", err)
    51  		return nil, err
    52  	}
    53  
    54  	instanceTypes := make([]SInstanceType, 0)
    55  	err = body.Unmarshal(&instanceTypes, "InstanceTypes", "InstanceType")
    56  	if err != nil {
    57  		log.Errorf("Unmarshal instance type details fail %s", err)
    58  		return nil, err
    59  	}
    60  	return instanceTypes, nil
    61  }
    62  
    63  func (self *SInstanceType) memoryMB() int {
    64  	return int(self.MemorySize * 1024)
    65  }