yunion.io/x/cloudmux@v0.3.10-0-alpha.1/pkg/multicloud/hcso/modelarts_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 hcso
    16  
    17  import (
    18  	"strconv"
    19  	"time"
    20  
    21  	"yunion.io/x/pkg/errors"
    22  
    23  	"yunion.io/x/cloudmux/pkg/apis/compute"
    24  	"yunion.io/x/cloudmux/pkg/cloudprovider"
    25  	"yunion.io/x/cloudmux/pkg/multicloud"
    26  	"yunion.io/x/cloudmux/pkg/multicloud/huawei"
    27  )
    28  
    29  type SModelartsPoolSku struct {
    30  	multicloud.SResourceBase
    31  	huawei.HuaweiTags
    32  	region *SRegion
    33  
    34  	Kind   string                          `json:"kind"`
    35  	Spec   SModelartsResourceflavorsSpec   `json:"spec"`
    36  	Status SModelartsResourceflavorsStatus `json:"status"`
    37  }
    38  
    39  type SModelartsResourceflavorsSpec struct {
    40  	BillingCode  string                           `json:"billingCode"`
    41  	BillingModes []int                            `json:"billingMods"`
    42  	Cpu          int                              `json:"cpu"`
    43  	CpuArch      string                           `json:"cpuArch"`
    44  	Gpu          SModelartsResourceflavorsGpuSpec `json:"gpu"`
    45  	Npu          SModelartsResourceflavorsGpuSpec `json:"npu"`
    46  	Memory       string                           `json:"memory"`
    47  	Type         string                           `json:"type"`
    48  }
    49  
    50  type SModelartsResourceflavorsGpuSpec struct {
    51  	Size int    `json:"size"`
    52  	Type string `json:"type"`
    53  }
    54  
    55  type SModelartsResourceflavorsStatus struct {
    56  	Phase map[string]interface{} `json:"phase"`
    57  }
    58  
    59  func (self *SRegion) GetIModelartsPoolSku() ([]cloudprovider.ICloudModelartsPoolSku, error) {
    60  	params := make(map[string]interface{})
    61  	resourceflavors := make([]SModelartsPoolSku, 0)
    62  	obj, err := self.client.modelartsResourceflavors(params)
    63  	if err != nil {
    64  		return nil, errors.Wrap(err, "region.modelartsResourceflavors")
    65  	}
    66  	obj.Unmarshal(&resourceflavors, "items")
    67  	res := make([]cloudprovider.ICloudModelartsPoolSku, len(resourceflavors))
    68  	for i := 0; i < len(resourceflavors); i++ {
    69  		res[i] = &resourceflavors[i]
    70  	}
    71  	return res, nil
    72  }
    73  
    74  func (self *SModelartsPoolSku) GetCreatedAt() time.Time {
    75  	createdAt, _ := time.Parse("2006-01-02T15:04:05CST", time.Now().Format("2006-01-02T15:04:05CST"))
    76  	return createdAt
    77  }
    78  
    79  func (self *SModelartsPoolSku) GetGlobalId() string {
    80  	return self.Spec.BillingCode
    81  }
    82  
    83  func (self *SModelartsPoolSku) GetId() string {
    84  	return self.Spec.BillingCode
    85  }
    86  
    87  func (self *SModelartsPoolSku) GetName() string {
    88  	return self.Spec.BillingCode
    89  }
    90  
    91  func (self *SModelartsPoolSku) GetCpuArch() string {
    92  	return self.Spec.CpuArch
    93  }
    94  
    95  func (self *SModelartsPoolSku) GetCpuCoreCount() int {
    96  	return self.Spec.Cpu
    97  }
    98  
    99  func (self *SModelartsPoolSku) GetMemorySizeMB() int {
   100  	size, _ := strconv.Atoi(self.Spec.Memory[:len(self.Spec.Memory)-2])
   101  	return size * 1024
   102  }
   103  
   104  func (self *SModelartsPoolSku) GetStatus() string {
   105  	for _, v := range self.Status.Phase {
   106  		if v == "normal" {
   107  			return compute.MODELARTS_POOL_SKU_AVAILABLE
   108  		}
   109  	}
   110  	return compute.MODELARTS_POOL_SKU_SOLDOUT
   111  }
   112  
   113  func (self *SModelartsPoolSku) GetGpuSize() int {
   114  	return self.Spec.Gpu.Size
   115  }
   116  
   117  func (self *SModelartsPoolSku) GetGpuType() string {
   118  	return self.Spec.Gpu.Type
   119  }
   120  
   121  func (self *SModelartsPoolSku) GetNpuSize() int {
   122  	return self.Spec.Npu.Size
   123  }
   124  
   125  func (self *SModelartsPoolSku) GetNpuType() string {
   126  	return self.Spec.Npu.Type
   127  }
   128  
   129  func (self *SModelartsPoolSku) GetPoolType() string {
   130  	return self.Spec.Type
   131  }