ksyun.go 5.9 KB

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