volcengine.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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 SVolcengineGuestDriver struct {
  27. SManagedVirtualizedGuestDriver
  28. }
  29. func init() {
  30. driver := SVolcengineGuestDriver{}
  31. models.RegisterGuestDriver(&driver)
  32. }
  33. func (self *SVolcengineGuestDriver) GetHypervisor() string {
  34. return api.HYPERVISOR_VOLCENGINE
  35. }
  36. func (self *SVolcengineGuestDriver) GetProvider() string {
  37. return api.CLOUD_PROVIDER_VOLCENGINE
  38. }
  39. func (self *SVolcengineGuestDriver) 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_VOLCENGINE
  44. keys.Brand = api.CLOUD_PROVIDER_VOLCENGINE
  45. keys.Hypervisor = api.HYPERVISOR_VOLCENGINE
  46. return keys
  47. }
  48. func (self *SVolcengineGuestDriver) GetDefaultSysDiskBackend() string {
  49. return ""
  50. }
  51. func (self *SVolcengineGuestDriver) GetMinimalSysDiskSizeGb() int {
  52. return 40
  53. }
  54. func (self *SVolcengineGuestDriver) GetStorageTypes() []string {
  55. return []string{}
  56. }
  57. func (self *SVolcengineGuestDriver) ChooseHostStorage(host *models.SHost, guest *models.SGuest, diskConfig *api.DiskConfig, storageIds []string) (*models.SStorage, error) {
  58. return chooseHostStorage(self, host, diskConfig.Backend, storageIds), nil
  59. }
  60. func (self *SVolcengineGuestDriver) GetDetachDiskStatus() ([]string, error) {
  61. return []string{api.VM_READY, api.VM_RUNNING}, nil
  62. }
  63. func (self *SVolcengineGuestDriver) GetAttachDiskStatus() ([]string, error) {
  64. return []string{api.VM_READY, api.VM_RUNNING}, nil
  65. }
  66. func (self *SVolcengineGuestDriver) GetRebuildRootStatus() ([]string, error) {
  67. return []string{api.VM_READY, api.VM_RUNNING}, nil
  68. }
  69. func (self *SVolcengineGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
  70. return []string{api.VM_READY}, nil
  71. }
  72. func (self *SVolcengineGuestDriver) GetDeployStatus() ([]string, error) {
  73. return []string{api.VM_READY, api.VM_RUNNING}, nil
  74. }
  75. func (self *SVolcengineGuestDriver) GetGuestInitialStateAfterCreate() string {
  76. return api.VM_RUNNING
  77. }
  78. func (self *SVolcengineGuestDriver) GetGuestInitialStateAfterRebuild() string {
  79. return api.VM_RUNNING
  80. }
  81. func (self *SVolcengineGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  82. return cloudprovider.SInstanceCapability{
  83. Hypervisor: self.GetHypervisor(),
  84. Provider: self.GetProvider(),
  85. DefaultAccount: cloudprovider.SDefaultAccount{
  86. Linux: cloudprovider.SOsDefaultAccount{
  87. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  88. Changeable: false,
  89. },
  90. Windows: cloudprovider.SOsDefaultAccount{
  91. DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
  92. Changeable: false,
  93. },
  94. },
  95. Storages: cloudprovider.Storage{
  96. DataDisk: []cloudprovider.StorageInfo{
  97. {StorageType: api.STORAGE_VOLC_CLOUD_PTSSD, MaxSizeGb: 8192, MinSizeGb: 20, StepSizeGb: 1, Resizable: true},
  98. {StorageType: api.STORAGE_VOLC_CLOUD_PL0, MaxSizeGb: 32768, MinSizeGb: 20, StepSizeGb: 1, Resizable: true},
  99. {StorageType: api.STORAGE_VOLC_CLOUD_FLEXPL, MaxSizeGb: 32768, MinSizeGb: 20, StepSizeGb: 1, Resizable: true},
  100. },
  101. SysDisk: []cloudprovider.StorageInfo{
  102. {StorageType: api.STORAGE_VOLC_CLOUD_PTSSD, MaxSizeGb: 500, MinSizeGb: 40, StepSizeGb: 1, Resizable: true},
  103. {StorageType: api.STORAGE_VOLC_CLOUD_PL0, MaxSizeGb: 2048, MinSizeGb: 40, StepSizeGb: 1, Resizable: true},
  104. {StorageType: api.STORAGE_VOLC_CLOUD_FLEXPL, MaxSizeGb: 2048, MinSizeGb: 40, StepSizeGb: 1, Resizable: true},
  105. },
  106. },
  107. }
  108. }
  109. func (self *SVolcengineGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
  110. months := bc.GetMonths()
  111. if (months >= 1 && months <= 9) || (months == 12) || (months == 24) || (months == 36) {
  112. return true
  113. }
  114. return false
  115. }
  116. func (self *SVolcengineGuestDriver) IsNeedInjectPasswordByCloudInit() bool {
  117. return true
  118. }
  119. func (self *SVolcengineGuestDriver) IsSupportSetAutoRenew() bool {
  120. return false
  121. }
  122. func (self *SVolcengineGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
  123. if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY, api.VM_START_RESIZE_DISK, api.VM_RESIZE_DISK}) {
  124. return fmt.Errorf("cannot resize disk when guest in status %s", guest.Status)
  125. }
  126. return nil
  127. }