ctyun.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/rbacscope"
  19. "yunion.io/x/pkg/utils"
  20. api "yunion.io/x/onecloud/pkg/apis/compute"
  21. "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
  22. "yunion.io/x/onecloud/pkg/compute/models"
  23. "yunion.io/x/onecloud/pkg/mcclient"
  24. )
  25. type SCtyunGuestDriver struct {
  26. SManagedVirtualizedGuestDriver
  27. }
  28. func (self *SCtyunGuestDriver) GetHypervisor() string {
  29. return api.HYPERVISOR_CTYUN
  30. }
  31. func (self *SCtyunGuestDriver) GetProvider() string {
  32. return api.CLOUD_PROVIDER_CTYUN
  33. }
  34. func (self *SCtyunGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  35. return cloudprovider.SInstanceCapability{
  36. Hypervisor: self.GetHypervisor(),
  37. Provider: self.GetProvider(),
  38. DefaultAccount: cloudprovider.SDefaultAccount{
  39. Linux: cloudprovider.SOsDefaultAccount{
  40. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  41. Changeable: false,
  42. },
  43. Windows: cloudprovider.SOsDefaultAccount{
  44. DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
  45. Changeable: false,
  46. },
  47. },
  48. }
  49. }
  50. func (self *SCtyunGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
  51. keys := models.SComputeResourceKeys{}
  52. keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
  53. keys.CloudEnv = api.CLOUD_ENV_PUBLIC_CLOUD
  54. keys.Provider = api.CLOUD_PROVIDER_CTYUN
  55. keys.Brand = api.CLOUD_PROVIDER_CTYUN
  56. keys.Hypervisor = api.HYPERVISOR_CTYUN
  57. return keys
  58. }
  59. func (self *SCtyunGuestDriver) GetDefaultSysDiskBackend() string {
  60. return api.STORAGE_CTYUN_SAS
  61. }
  62. func (self *SCtyunGuestDriver) GetDeployStatus() ([]string, error) {
  63. return []string{api.VM_RUNNING}, nil
  64. }
  65. func (self *SCtyunGuestDriver) IsNeedRestartForResetLoginInfo() bool {
  66. return false
  67. }
  68. func (self *SCtyunGuestDriver) GetMinimalSysDiskSizeGb() int {
  69. return 10
  70. }
  71. func (self *SCtyunGuestDriver) GetGuestInitialStateAfterCreate() string {
  72. return api.VM_RUNNING
  73. }
  74. func (self *SCtyunGuestDriver) GetDetachDiskStatus() ([]string, error) {
  75. return []string{api.VM_READY, api.VM_RUNNING}, nil
  76. }
  77. func (self *SCtyunGuestDriver) GetAttachDiskStatus() ([]string, error) {
  78. return []string{api.VM_READY, api.VM_RUNNING}, nil
  79. }
  80. func (self *SCtyunGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
  81. return []string{api.VM_READY}, nil
  82. }
  83. func (self *SCtyunGuestDriver) GetRebuildRootStatus() ([]string, error) {
  84. return []string{api.VM_READY}, nil
  85. }
  86. func (self *SCtyunGuestDriver) GetGuestInitialStateAfterRebuild() string {
  87. return api.VM_READY
  88. }
  89. func (self *SCtyunGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
  90. if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY, api.VM_START_RESIZE_DISK, api.VM_RESIZE_DISK}) {
  91. return fmt.Errorf("Cannot resize disk when guest in status %s", guest.Status)
  92. }
  93. if !utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_CTYUN_SATA, api.STORAGE_CTYUN_SAS, api.STORAGE_CTYUN_SSD}) {
  94. return fmt.Errorf("Cannot resize disk with unsupported volumes type %s", storage.StorageType)
  95. }
  96. return nil
  97. }
  98. func init() {
  99. driver := SCtyunGuestDriver{}
  100. models.RegisterGuestDriver(&driver)
  101. }