yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/apsara/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 apsara
    16  
    17  import (
    18  	"yunion.io/x/log"
    19  	"yunion.io/x/pkg/errors"
    20  
    21  	api "yunion.io/x/cloudmux/pkg/apis/compute"
    22  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    23  	"yunion.io/x/cloudmux/pkg/multicloud"
    24  )
    25  
    26  // {"CpuCoreCount":1,"EniQuantity":1,"GPUAmount":0,"GPUSpec":"","InstanceTypeFamily":"ecs.t1","InstanceTypeId":"ecs.t1.xsmall","LocalStorageCategory":"","MemorySize":0.500000}
    27  // InstanceBandwidthRx":26214400,"InstanceBandwidthTx":26214400,"InstancePpsRx":4500000,"InstancePpsTx":4500000
    28  
    29  type SInstanceType struct {
    30  	multicloud.SResourceBase
    31  	ApsaraTags
    32  	BaselineCredit       int
    33  	CpuCoreCount         int
    34  	MemorySize           float32
    35  	EniQuantity          int // 实例规格支持网卡数量
    36  	GPUAmount            int
    37  	GPUSpec              string
    38  	InstanceTypeFamily   string
    39  	InstanceFamilyLevel  string
    40  	InstanceTypeId       string
    41  	LocalStorageCategory string
    42  	LocalStorageAmount   int
    43  	LocalStorageCapacity int64
    44  	InstanceBandwidthRx  int
    45  	InstanceBandwidthTx  int
    46  	InstancePpsRx        int
    47  	InstancePpsTx        int
    48  }
    49  
    50  func (self *SRegion) GetInstanceTypes() ([]SInstanceType, error) {
    51  	params := make(map[string]string)
    52  	params["RegionId"] = self.RegionId
    53  
    54  	body, err := self.client.ascmRequest("DescribeInstanceTypes", params)
    55  	if err != nil {
    56  		return nil, errors.Wrapf(err, "DescribeInstanceTypes")
    57  	}
    58  
    59  	instanceTypes := make([]SInstanceType, 0)
    60  	err = body.Unmarshal(&instanceTypes, "data")
    61  	if err != nil {
    62  		log.Errorf("Unmarshal instance type details fail %s", err)
    63  		return nil, err
    64  	}
    65  	return instanceTypes, nil
    66  }
    67  
    68  func (self *SInstanceType) memoryMB() int {
    69  	return int(self.MemorySize * 1024)
    70  }
    71  
    72  func (self *SRegion) GetISkus() ([]cloudprovider.ICloudSku, error) {
    73  	skus, err := self.GetInstanceTypes()
    74  	if err != nil {
    75  		return nil, errors.Wrapf(err, "GetInstanceTypes")
    76  	}
    77  	ret := []cloudprovider.ICloudSku{}
    78  	for i := range skus {
    79  		ret = append(ret, &skus[i])
    80  	}
    81  	return ret, nil
    82  }
    83  
    84  func (self *SInstanceType) GetStatus() string {
    85  	return ""
    86  }
    87  
    88  func (self *SInstanceType) Delete() error {
    89  	return nil
    90  }
    91  
    92  func (self *SInstanceType) GetName() string {
    93  	return self.InstanceTypeId
    94  }
    95  
    96  func (self *SInstanceType) GetId() string {
    97  	return self.InstanceTypeId
    98  }
    99  
   100  func (self *SInstanceType) GetGlobalId() string {
   101  	return self.InstanceTypeId
   102  }
   103  
   104  func (self *SInstanceType) GetInstanceTypeFamily() string {
   105  	return self.InstanceTypeFamily
   106  }
   107  
   108  func (self *SInstanceType) GetInstanceTypeCategory() string {
   109  	return self.GetName()
   110  }
   111  
   112  func (self *SInstanceType) GetPrepaidStatus() string {
   113  	return api.SkuStatusSoldout
   114  }
   115  
   116  func (self *SInstanceType) GetPostpaidStatus() string {
   117  	return api.SkuStatusAvailable
   118  }
   119  
   120  func (self *SInstanceType) GetCpuArch() string {
   121  	return ""
   122  }
   123  
   124  func (self *SInstanceType) GetCpuCoreCount() int {
   125  	return int(self.CpuCoreCount)
   126  }
   127  
   128  func (self *SInstanceType) GetMemorySizeMB() int {
   129  	return int(self.MemorySize * 1024)
   130  }
   131  
   132  func (self *SInstanceType) GetOsName() string {
   133  	return "Any"
   134  }
   135  
   136  func (self *SInstanceType) GetSysDiskResizable() bool {
   137  	return true
   138  }
   139  
   140  func (self *SInstanceType) GetSysDiskType() string {
   141  	return ""
   142  }
   143  
   144  func (self *SInstanceType) GetSysDiskMinSizeGB() int {
   145  	return 0
   146  }
   147  
   148  func (self *SInstanceType) GetSysDiskMaxSizeGB() int {
   149  	return 0
   150  }
   151  
   152  func (self *SInstanceType) GetAttachedDiskType() string {
   153  	return "iscsi"
   154  }
   155  
   156  func (self *SInstanceType) GetAttachedDiskSizeGB() int {
   157  	return 0
   158  }
   159  
   160  func (self *SInstanceType) GetAttachedDiskCount() int {
   161  	return 0
   162  }
   163  
   164  func (self *SInstanceType) GetDataDiskTypes() string {
   165  	return ""
   166  }
   167  
   168  func (self *SInstanceType) GetDataDiskMaxCount() int {
   169  	return 6
   170  }
   171  
   172  func (self *SInstanceType) GetNicType() string {
   173  	return "vpc"
   174  }
   175  
   176  func (self *SInstanceType) GetNicMaxCount() int {
   177  	return 1
   178  }
   179  
   180  func (self *SInstanceType) GetGpuAttachable() bool {
   181  	return false
   182  }
   183  
   184  func (self *SInstanceType) GetGpuSpec() string {
   185  	return ""
   186  }
   187  
   188  func (self *SInstanceType) GetGpuCount() int {
   189  	return 0
   190  }
   191  
   192  func (self *SInstanceType) GetGpuMaxCount() int {
   193  	return 0
   194  }