incloudsphere.go 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. "context"
  17. "fmt"
  18. "yunion.io/x/cloudmux/pkg/cloudprovider"
  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/cloudcommon/db/taskman"
  24. "yunion.io/x/onecloud/pkg/compute/models"
  25. "yunion.io/x/onecloud/pkg/compute/options"
  26. "yunion.io/x/onecloud/pkg/httperrors"
  27. "yunion.io/x/onecloud/pkg/mcclient"
  28. )
  29. type SInCloudSphereGuestDriver struct {
  30. SManagedVirtualizedGuestDriver
  31. }
  32. func init() {
  33. driver := SInCloudSphereGuestDriver{}
  34. models.RegisterGuestDriver(&driver)
  35. }
  36. func (self *SInCloudSphereGuestDriver) DoScheduleSKUFilter() bool {
  37. return false
  38. }
  39. func (self *SInCloudSphereGuestDriver) GetHypervisor() string {
  40. return api.HYPERVISOR_INCLOUD_SPHERE
  41. }
  42. func (self *SInCloudSphereGuestDriver) GetProvider() string {
  43. return api.CLOUD_PROVIDER_INCLOUD_SPHERE
  44. }
  45. func (self *SInCloudSphereGuestDriver) GetMinimalSysDiskSizeGb() int {
  46. return options.Options.DefaultDiskSizeMB / 1024
  47. }
  48. func (self *SInCloudSphereGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  49. return cloudprovider.SInstanceCapability{
  50. Hypervisor: self.GetHypervisor(),
  51. Provider: self.GetProvider(),
  52. DefaultAccount: cloudprovider.SDefaultAccount{
  53. Linux: cloudprovider.SOsDefaultAccount{
  54. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  55. Changeable: true,
  56. },
  57. Windows: cloudprovider.SOsDefaultAccount{
  58. DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
  59. Changeable: false,
  60. },
  61. },
  62. }
  63. }
  64. func (self *SInCloudSphereGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
  65. keys := models.SComputeResourceKeys{}
  66. keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
  67. keys.CloudEnv = api.CLOUD_ENV_PRIVATE_CLOUD
  68. keys.Provider = api.CLOUD_PROVIDER_INCLOUD_SPHERE
  69. keys.Brand = api.CLOUD_PROVIDER_INCLOUD_SPHERE
  70. keys.Hypervisor = api.HYPERVISOR_INCLOUD_SPHERE
  71. return keys
  72. }
  73. func (self *SInCloudSphereGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
  74. if !utils.IsInStringArray(guest.Status, []string{api.VM_READY, api.VM_RUNNING}) {
  75. return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
  76. }
  77. return nil
  78. }
  79. func (self *SInCloudSphereGuestDriver) GetDefaultSysDiskBackend() string {
  80. return api.STORAGE_LOCAL
  81. }
  82. func (self *SInCloudSphereGuestDriver) IsNeedRestartForResetLoginInfo() bool {
  83. return false
  84. }
  85. func (self *SInCloudSphereGuestDriver) IsNeedInjectPasswordByCloudInit() bool {
  86. return true
  87. }
  88. func (self *SInCloudSphereGuestDriver) RequestSyncSecgroupsOnHost(ctx context.Context, guest *models.SGuest, host *models.SHost, task taskman.ITask) error {
  89. return nil // do nothing, not support securitygroup
  90. }
  91. func (self *SInCloudSphereGuestDriver) GetMaxSecurityGroupCount() int {
  92. //暂不支持绑定安全组
  93. return 0
  94. }
  95. func (self *SInCloudSphereGuestDriver) GetDetachDiskStatus() ([]string, error) {
  96. return []string{api.VM_READY}, nil
  97. }
  98. func (self *SInCloudSphereGuestDriver) GetAttachDiskStatus() ([]string, error) {
  99. return []string{api.VM_READY}, nil
  100. }
  101. func (self *SInCloudSphereGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
  102. return []string{api.VM_READY, api.VM_RUNNING}, nil
  103. }
  104. func (self *SInCloudSphereGuestDriver) GetRebuildRootStatus() ([]string, error) {
  105. return []string{}, cloudprovider.ErrNotSupported
  106. }
  107. func (self *SInCloudSphereGuestDriver) GetDeployStatus() ([]string, error) {
  108. return []string{api.VM_RUNNING}, nil
  109. }
  110. func (self *SInCloudSphereGuestDriver) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, input *api.ServerCreateInput) (*api.ServerCreateInput, error) {
  111. input, err := self.SManagedVirtualizedGuestDriver.ValidateCreateData(ctx, userCred, input)
  112. if err != nil {
  113. return nil, err
  114. }
  115. if len(input.Networks) > 2 {
  116. return nil, httperrors.NewInputParameterError("cannot support more than 1 nic")
  117. }
  118. if len(input.Eip) > 0 || input.EipBw > 0 {
  119. return nil, httperrors.NewUnsupportOperationError("%s not support create virtual machine with eip", self.GetHypervisor())
  120. }
  121. return input, nil
  122. }
  123. func (self *SInCloudSphereGuestDriver) ValidateCreateEip(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerCreateEipInput) error {
  124. return httperrors.NewInputParameterError("%s not support create eip", self.GetHypervisor())
  125. }
  126. func (self *SInCloudSphereGuestDriver) IsSupportEip() bool {
  127. return false
  128. }
  129. func (self *SInCloudSphereGuestDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
  130. return false, nil
  131. }
  132. func (self *SInCloudSphereGuestDriver) RequestRemoteUpdate(ctx context.Context, guest *models.SGuest, userCred mcclient.TokenCredential, replaceTags bool) error {
  133. return nil
  134. }