sku.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. package cloudpods
  15. import (
  16. "yunion.io/x/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/cloudmux/pkg/multicloud"
  18. api "yunion.io/x/onecloud/pkg/apis/compute"
  19. modules "yunion.io/x/onecloud/pkg/mcclient/modules/compute"
  20. )
  21. type SServerSku struct {
  22. multicloud.SResourceBase
  23. CloudpodsTags
  24. region *SRegion
  25. api.ServerSkuDetails
  26. }
  27. func (self *SServerSku) GetName() string {
  28. return self.Name
  29. }
  30. func (self *SServerSku) GetId() string {
  31. return self.Id
  32. }
  33. func (self *SServerSku) GetGlobalId() string {
  34. return self.Id
  35. }
  36. func (self *SServerSku) GetStatus() string {
  37. return self.Status
  38. }
  39. func (self *SServerSku) GetInstanceTypeFamily() string {
  40. return self.InstanceTypeFamily
  41. }
  42. func (self *SServerSku) GetInstanceTypeCategory() string {
  43. return self.InstanceTypeCategory
  44. }
  45. func (self *SServerSku) GetPrepaidStatus() string {
  46. return self.PrepaidStatus
  47. }
  48. func (self *SServerSku) GetPostpaidStatus() string {
  49. return self.PostpaidStatus
  50. }
  51. func (self *SServerSku) GetCpuArch() string {
  52. return "x86"
  53. }
  54. func (self *SServerSku) GetCpuCoreCount() int {
  55. return self.CpuCoreCount
  56. }
  57. func (self *SServerSku) GetMemorySizeMB() int {
  58. return self.MemorySizeMB
  59. }
  60. func (self *SServerSku) GetOsName() string {
  61. return self.OsName
  62. }
  63. func (self *SServerSku) GetSysDiskResizable() bool {
  64. return self.SysDiskResizable != nil && *self.SysDiskResizable
  65. }
  66. func (self *SServerSku) GetSysDiskType() string {
  67. return self.SysDiskType
  68. }
  69. func (self *SServerSku) GetSysDiskMinSizeGB() int {
  70. return self.SysDiskMinSizeGB
  71. }
  72. func (self *SServerSku) GetSysDiskMaxSizeGB() int {
  73. return self.SysDiskMaxSizeGB
  74. }
  75. func (self *SServerSku) GetAttachedDiskType() string {
  76. return self.AttachedDiskType
  77. }
  78. func (self *SServerSku) GetAttachedDiskSizeGB() int {
  79. return self.AttachedDiskSizeGB
  80. }
  81. func (self *SServerSku) GetAttachedDiskCount() int {
  82. return self.AttachedDiskCount
  83. }
  84. func (self *SServerSku) GetDataDiskTypes() string {
  85. return self.DataDiskTypes
  86. }
  87. func (self *SServerSku) GetDataDiskMaxCount() int {
  88. return self.DataDiskMaxCount
  89. }
  90. func (self *SServerSku) GetNicType() string {
  91. return self.NicType
  92. }
  93. func (self *SServerSku) GetNicMaxCount() int {
  94. return self.NicMaxCount
  95. }
  96. func (self *SServerSku) GetGpuAttachable() bool {
  97. return self.GpuAttachable != nil && *self.GpuAttachable
  98. }
  99. func (self *SServerSku) GetGpuSpec() string {
  100. return self.GpuSpec
  101. }
  102. func (self *SServerSku) GetGpuCount() string {
  103. return self.GpuCount
  104. }
  105. func (self *SServerSku) GetGpuMaxCount() int {
  106. return self.GpuMaxCount
  107. }
  108. func (self *SServerSku) Delete() error {
  109. return self.region.cli.delete(&modules.ServerSkus, self.Id)
  110. }
  111. func (self *SRegion) GetISkus() ([]cloudprovider.ICloudSku, error) {
  112. skus, err := self.GetServerSkus()
  113. if err != nil {
  114. return nil, err
  115. }
  116. ret := []cloudprovider.ICloudSku{}
  117. for i := range skus {
  118. skus[i].region = self
  119. ret = append(ret, &skus[i])
  120. }
  121. return ret, nil
  122. }
  123. func (self *SRegion) GetServerSkus() ([]SServerSku, error) {
  124. skus := []SServerSku{}
  125. return skus, self.list(&modules.ServerSkus, nil, &skus)
  126. }