nutanix.go 5.8 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. "context"
  17. "fmt"
  18. "time"
  19. "yunion.io/x/cloudmux/pkg/cloudprovider"
  20. "yunion.io/x/pkg/util/billing"
  21. "yunion.io/x/pkg/util/rbacscope"
  22. "yunion.io/x/pkg/utils"
  23. api "yunion.io/x/onecloud/pkg/apis/compute"
  24. "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
  25. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  26. "yunion.io/x/onecloud/pkg/compute/models"
  27. "yunion.io/x/onecloud/pkg/compute/options"
  28. "yunion.io/x/onecloud/pkg/httperrors"
  29. "yunion.io/x/onecloud/pkg/mcclient"
  30. )
  31. type SNutanixGuestDriver struct {
  32. SManagedVirtualizedGuestDriver
  33. }
  34. func init() {
  35. driver := SNutanixGuestDriver{}
  36. models.RegisterGuestDriver(&driver)
  37. }
  38. func (self *SNutanixGuestDriver) DoScheduleCPUFilter() bool { return true }
  39. func (self *SNutanixGuestDriver) DoScheduleMemoryFilter() bool { return true }
  40. func (self *SNutanixGuestDriver) DoScheduleSKUFilter() bool { return false }
  41. func (self *SNutanixGuestDriver) DoScheduleStorageFilter() bool { return true }
  42. func (self *SNutanixGuestDriver) GetHypervisor() string {
  43. return api.HYPERVISOR_NUTANIX
  44. }
  45. func (self *SNutanixGuestDriver) GetProvider() string {
  46. return api.CLOUD_PROVIDER_NUTANIX
  47. }
  48. func (self *SNutanixGuestDriver) 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 *SNutanixGuestDriver) 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_NUTANIX
  69. keys.Brand = api.CLOUD_PROVIDER_NUTANIX
  70. keys.Hypervisor = api.HYPERVISOR_NUTANIX
  71. return keys
  72. }
  73. func (self *SNutanixGuestDriver) GetDefaultSysDiskBackend() string {
  74. return ""
  75. }
  76. func (self *SNutanixGuestDriver) GetUserDataType() string {
  77. return cloudprovider.CLOUD_SHELL
  78. }
  79. func (self *SNutanixGuestDriver) IsNeedInjectPasswordByCloudInit() bool {
  80. return true
  81. }
  82. func (self *SNutanixGuestDriver) ChooseHostStorage(host *models.SHost, guest *models.SGuest, diskConfig *api.DiskConfig, storageIds []string) (*models.SStorage, error) {
  83. return chooseHostStorage(self, host, diskConfig.Backend, storageIds), nil
  84. }
  85. func (self *SNutanixGuestDriver) GetMinimalSysDiskSizeGb() int {
  86. return options.Options.DefaultDiskSizeMB / 1024
  87. }
  88. func (self *SNutanixGuestDriver) 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 *SNutanixGuestDriver) GetMaxSecurityGroupCount() int {
  92. //暂不支持绑定安全组
  93. return 0
  94. }
  95. func (self *SNutanixGuestDriver) DoGuestCreateDisksTask(ctx context.Context, guest *models.SGuest, task taskman.ITask) error {
  96. subtask, err := taskman.TaskManager.NewTask(ctx, "NutanixGuestCreateDiskTask", guest, task.GetUserCred(), task.GetParams(), task.GetTaskId(), "", nil)
  97. if err != nil {
  98. return err
  99. }
  100. subtask.ScheduleRun(nil)
  101. return nil
  102. }
  103. func (self *SNutanixGuestDriver) GetDetachDiskStatus() ([]string, error) {
  104. return []string{api.VM_READY}, nil
  105. }
  106. func (self *SNutanixGuestDriver) GetAttachDiskStatus() ([]string, error) {
  107. return []string{api.VM_READY}, nil
  108. }
  109. func (self *SNutanixGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
  110. return []string{api.VM_READY}, nil
  111. }
  112. func (self *SNutanixGuestDriver) CanKeepDetachDisk() bool {
  113. return false
  114. }
  115. func (self *SNutanixGuestDriver) GetRebuildRootStatus() ([]string, error) {
  116. return []string{}, cloudprovider.ErrNotSupported
  117. }
  118. func (self *SNutanixGuestDriver) GetDeployStatus() ([]string, error) {
  119. return []string{api.VM_READY}, nil
  120. }
  121. func (self *SNutanixGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
  122. if !utils.IsInStringArray(guest.Status, []string{api.VM_READY}) {
  123. return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
  124. }
  125. if disk.DiskSize/1024%1 > 0 {
  126. return fmt.Errorf("Resize disk size must be an integer multiple of 1G")
  127. }
  128. return nil
  129. }
  130. func (self *SNutanixGuestDriver) ValidateCreateEip(ctx context.Context, userCred mcclient.TokenCredential, input api.ServerCreateEipInput) error {
  131. return httperrors.NewInputParameterError("%s not support create eip", self.GetHypervisor())
  132. }
  133. func (self *SNutanixGuestDriver) AllowReconfigGuest() bool {
  134. return true
  135. }
  136. func (self *SNutanixGuestDriver) RequestRenewInstance(ctx context.Context, guest *models.SGuest, bc billing.SBillingCycle) (time.Time, error) {
  137. return time.Time{}, nil
  138. }
  139. func (self *SNutanixGuestDriver) IsSupportEip() bool {
  140. return false
  141. }
  142. func (self *SNutanixGuestDriver) IsSupportCdrom(guest *models.SGuest) (bool, error) {
  143. return false, nil
  144. }
  145. func (self *SNutanixGuestDriver) RequestRemoteUpdate(ctx context.Context, guest *models.SGuest, userCred mcclient.TokenCredential, replaceTags bool) error {
  146. return nil
  147. }