huawei.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 guestdrivers
  15. import (
  16. "fmt"
  17. "yunion.io/x/cloudmux/pkg/cloudprovider"
  18. "yunion.io/x/pkg/util/billing"
  19. "yunion.io/x/pkg/util/rbacscope"
  20. "yunion.io/x/pkg/utils"
  21. api "yunion.io/x/onecloud/pkg/apis/compute"
  22. "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
  23. "yunion.io/x/onecloud/pkg/compute/models"
  24. "yunion.io/x/onecloud/pkg/mcclient"
  25. )
  26. type SHuaweiGuestDriver struct {
  27. SManagedVirtualizedGuestDriver
  28. }
  29. func init() {
  30. driver := SHuaweiGuestDriver{}
  31. models.RegisterGuestDriver(&driver)
  32. }
  33. func (self *SHuaweiGuestDriver) GetHypervisor() string {
  34. return api.HYPERVISOR_HUAWEI
  35. }
  36. func (self *SHuaweiGuestDriver) GetProvider() string {
  37. return api.CLOUD_PROVIDER_HUAWEI
  38. }
  39. func (self *SHuaweiGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
  40. keys := models.SComputeResourceKeys{}
  41. keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
  42. keys.CloudEnv = api.CLOUD_ENV_PUBLIC_CLOUD
  43. keys.Provider = api.CLOUD_PROVIDER_HUAWEI
  44. keys.Brand = api.CLOUD_PROVIDER_HUAWEI
  45. keys.Hypervisor = api.HYPERVISOR_HUAWEI
  46. return keys
  47. }
  48. func (self *SHuaweiGuestDriver) GetDefaultSysDiskBackend() string {
  49. return api.STORAGE_HUAWEI_SAS
  50. }
  51. func (self *SHuaweiGuestDriver) GetMinimalSysDiskSizeGb() int {
  52. return 40
  53. }
  54. func (self *SHuaweiGuestDriver) GetStorageTypes() []string {
  55. return []string{
  56. api.STORAGE_HUAWEI_SATA,
  57. api.STORAGE_HUAWEI_SAS,
  58. api.STORAGE_HUAWEI_SSD,
  59. api.STORAGE_HUAWEI_GPSSD,
  60. api.STORAGE_HUAWEI_ESSD,
  61. }
  62. }
  63. func (self *SHuaweiGuestDriver) ChooseHostStorage(host *models.SHost, guest *models.SGuest, diskConfig *api.DiskConfig, storageIds []string) (*models.SStorage, error) {
  64. return chooseHostStorage(self, host, diskConfig.Backend, storageIds), nil
  65. }
  66. func (self *SHuaweiGuestDriver) GetDetachDiskStatus() ([]string, error) {
  67. return []string{api.VM_READY, api.VM_RUNNING}, nil
  68. }
  69. func (self *SHuaweiGuestDriver) GetAttachDiskStatus() ([]string, error) {
  70. return []string{api.VM_READY, api.VM_RUNNING}, nil
  71. }
  72. func (self *SHuaweiGuestDriver) GetRebuildRootStatus() ([]string, error) {
  73. return []string{api.VM_READY, api.VM_RUNNING}, nil
  74. }
  75. func (self *SHuaweiGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
  76. return []string{api.VM_READY}, nil
  77. }
  78. func (self *SHuaweiGuestDriver) GetDeployStatus() ([]string, error) {
  79. return []string{api.VM_READY, api.VM_RUNNING}, nil
  80. }
  81. func (self *SHuaweiGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
  82. if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY, api.VM_START_RESIZE_DISK, api.VM_RESIZE_DISK}) {
  83. return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
  84. }
  85. if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_HUAWEI_SATA, api.STORAGE_HUAWEI_SAS, api.STORAGE_HUAWEI_SSD}) {
  86. return fmt.Errorf("Cannot resize disk with unsupported volumes type %s", storage.StorageType)
  87. }
  88. return nil
  89. }
  90. func (self *SHuaweiGuestDriver) GetGuestInitialStateAfterCreate() string {
  91. return api.VM_RUNNING
  92. }
  93. func (self *SHuaweiGuestDriver) GetGuestInitialStateAfterRebuild() string {
  94. return api.VM_RUNNING
  95. }
  96. func (self *SHuaweiGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  97. return cloudprovider.SInstanceCapability{
  98. Hypervisor: self.GetHypervisor(),
  99. Provider: self.GetProvider(),
  100. DefaultAccount: cloudprovider.SDefaultAccount{
  101. Linux: cloudprovider.SOsDefaultAccount{
  102. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  103. },
  104. Windows: cloudprovider.SOsDefaultAccount{
  105. DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
  106. },
  107. },
  108. Storages: cloudprovider.Storage{
  109. DataDisk: []cloudprovider.StorageInfo{
  110. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SSD, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
  111. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SATA, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
  112. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SAS, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
  113. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_GPSSD, MaxSizeGb: 32768, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
  114. },
  115. SysDisk: []cloudprovider.StorageInfo{
  116. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SSD, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
  117. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SATA, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
  118. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_SAS, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
  119. cloudprovider.StorageInfo{StorageType: api.STORAGE_HUAWEI_GPSSD, MaxSizeGb: 1024, MinSizeGb: 40, StepSizeGb: 1, Resizable: false},
  120. },
  121. },
  122. }
  123. }
  124. func (self *SHuaweiGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
  125. months := bc.GetMonths()
  126. if (months >= 1 && months <= 9) || (months == 12) || (months == 24) || (months == 36) {
  127. return true
  128. }
  129. return false
  130. }
  131. func (self *SHuaweiGuestDriver) IsNeedInjectPasswordByCloudInit() bool {
  132. return true
  133. }
  134. func (self *SHuaweiGuestDriver) IsSupportSetAutoRenew() bool {
  135. return false
  136. }