baidu.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 SBaiduGuestDriver struct {
  27. SManagedVirtualizedGuestDriver
  28. }
  29. func init() {
  30. driver := SBaiduGuestDriver{}
  31. models.RegisterGuestDriver(&driver)
  32. }
  33. func (self *SBaiduGuestDriver) GetHypervisor() string {
  34. return api.HYPERVISOR_BAIDU
  35. }
  36. func (self *SBaiduGuestDriver) GetProvider() string {
  37. return api.CLOUD_PROVIDER_BAIDU
  38. }
  39. func (self *SBaiduGuestDriver) GetDefaultSysDiskBackend() string {
  40. return api.STORAGE_BAIDU_SSD
  41. }
  42. func (self *SBaiduGuestDriver) GetMinimalSysDiskSizeGb() int {
  43. return 20
  44. }
  45. func (self *SBaiduGuestDriver) ChooseHostStorage(host *models.SHost, guest *models.SGuest, diskConfig *api.DiskConfig, storageIds []string) (*models.SStorage, error) {
  46. return chooseHostStorage(self, host, diskConfig.Backend, storageIds), nil
  47. }
  48. func (self *SBaiduGuestDriver) GetStorageTypes() []string {
  49. return []string{
  50. api.STORAGE_BAIDU_SSD,
  51. api.STORAGE_BAIDU_PREMIUM_SSD,
  52. api.STORAGE_BAIDU_HDD,
  53. api.STORAGE_BAIDU_ENHANCED_SSD_PL1,
  54. api.STORAGE_BAIDU_ENHANCED_SSD_PL2,
  55. api.STORAGE_BAIDU_ENHANCED_SSD_PL3,
  56. }
  57. }
  58. func (self *SBaiduGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
  59. keys := models.SComputeResourceKeys{}
  60. keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
  61. keys.CloudEnv = api.CLOUD_ENV_PUBLIC_CLOUD
  62. keys.Provider = api.CLOUD_PROVIDER_BAIDU
  63. keys.Brand = api.CLOUD_PROVIDER_BAIDU
  64. keys.Hypervisor = api.HYPERVISOR_BAIDU
  65. return keys
  66. }
  67. func (self *SBaiduGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  68. return cloudprovider.SInstanceCapability{
  69. Hypervisor: self.GetHypervisor(),
  70. Provider: self.GetProvider(),
  71. DefaultAccount: cloudprovider.SDefaultAccount{
  72. Linux: cloudprovider.SOsDefaultAccount{
  73. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  74. Changeable: false,
  75. },
  76. Windows: cloudprovider.SOsDefaultAccount{
  77. DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
  78. Changeable: false,
  79. },
  80. },
  81. Storages: cloudprovider.Storage{
  82. DataDisk: []cloudprovider.StorageInfo{
  83. {StorageType: api.STORAGE_BAIDU_SSD, MaxSizeGb: 65536, MinSizeGb: 5, StepSizeGb: 1, Resizable: true},
  84. {StorageType: api.STORAGE_BAIDU_PREMIUM_SSD, MaxSizeGb: 65536, MinSizeGb: 20, StepSizeGb: 1, Resizable: true},
  85. {StorageType: api.STORAGE_BAIDU_HDD, MaxSizeGb: 65536, MinSizeGb: 5, StepSizeGb: 1, Resizable: true},
  86. {StorageType: api.STORAGE_BAIDU_ENHANCED_SSD_PL1, MaxSizeGb: 65536, MinSizeGb: 5, StepSizeGb: 1, Resizable: true},
  87. {StorageType: api.STORAGE_BAIDU_ENHANCED_SSD_PL2, MaxSizeGb: 65536, MinSizeGb: 461, StepSizeGb: 1, Resizable: true},
  88. {StorageType: api.STORAGE_BAIDU_ENHANCED_SSD_PL3, MaxSizeGb: 65536, MinSizeGb: 1261, StepSizeGb: 1, Resizable: true},
  89. },
  90. SysDisk: []cloudprovider.StorageInfo{
  91. {StorageType: api.STORAGE_BAIDU_SSD, MaxSizeGb: 20480, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
  92. {StorageType: api.STORAGE_BAIDU_PREMIUM_SSD, MaxSizeGb: 20480, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
  93. {StorageType: api.STORAGE_BAIDU_HDD, MaxSizeGb: 20480, MinSizeGb: 10, StepSizeGb: 1, Resizable: true},
  94. {StorageType: api.STORAGE_BAIDU_ENHANCED_SSD_PL1, MaxSizeGb: 20480, MinSizeGb: 20, StepSizeGb: 1, Resizable: true},
  95. {StorageType: api.STORAGE_BAIDU_ENHANCED_SSD_PL2, MaxSizeGb: 20480, MinSizeGb: 461, StepSizeGb: 1, Resizable: true},
  96. {StorageType: api.STORAGE_BAIDU_ENHANCED_SSD_PL3, MaxSizeGb: 20480, MinSizeGb: 1261, StepSizeGb: 1, Resizable: true},
  97. },
  98. },
  99. }
  100. }
  101. func (self *SBaiduGuestDriver) GetDetachDiskStatus() ([]string, error) {
  102. return []string{api.VM_READY, api.VM_RUNNING}, nil
  103. }
  104. func (self *SBaiduGuestDriver) GetAttachDiskStatus() ([]string, error) {
  105. return []string{api.VM_READY, api.VM_RUNNING}, nil
  106. }
  107. func (self *SBaiduGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
  108. return []string{api.VM_READY}, nil
  109. }
  110. func (self *SBaiduGuestDriver) GetDeployStatus() ([]string, error) {
  111. return []string{api.VM_READY, api.VM_RUNNING}, nil
  112. }
  113. func (self *SBaiduGuestDriver) GetGuestInitialStateAfterCreate() string {
  114. return api.VM_RUNNING
  115. }
  116. func (self *SBaiduGuestDriver) GetGuestInitialStateAfterRebuild() string {
  117. return api.VM_RUNNING
  118. }
  119. func (self *SBaiduGuestDriver) GetRebuildRootStatus() ([]string, error) {
  120. return []string{api.VM_READY, api.VM_RUNNING}, nil
  121. }
  122. func (self *SBaiduGuestDriver) AllowReconfigGuest() bool {
  123. return true
  124. }
  125. func (self *SBaiduGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
  126. return true
  127. }
  128. func (self *SBaiduGuestDriver) IsSupportPublicipToEip() bool {
  129. return false
  130. }
  131. func (self *SBaiduGuestDriver) IsSupportSetAutoRenew() bool {
  132. return false
  133. }
  134. func (self *SBaiduGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
  135. if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY, api.VM_START_RESIZE_DISK, api.VM_RESIZE_DISK}) {
  136. return fmt.Errorf("cannot resize disk when guest in status %s", guest.Status)
  137. }
  138. return nil
  139. }