ecloud.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. "yunion.io/x/cloudmux/pkg/cloudprovider"
  17. "yunion.io/x/pkg/errors"
  18. "yunion.io/x/pkg/util/rbacscope"
  19. api "yunion.io/x/onecloud/pkg/apis/compute"
  20. "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
  21. "yunion.io/x/onecloud/pkg/compute/models"
  22. "yunion.io/x/onecloud/pkg/mcclient"
  23. )
  24. type SEcloudGuestDriver struct {
  25. SManagedVirtualizedGuestDriver
  26. }
  27. func (self *SEcloudGuestDriver) GetHypervisor() string {
  28. return api.HYPERVISOR_ECLOUD
  29. }
  30. func (self *SEcloudGuestDriver) GetProvider() string {
  31. return api.CLOUD_PROVIDER_ECLOUD
  32. }
  33. func (self *SEcloudGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  34. return cloudprovider.SInstanceCapability{
  35. Hypervisor: self.GetHypervisor(),
  36. Provider: self.GetProvider(),
  37. DefaultAccount: cloudprovider.SDefaultAccount{
  38. Linux: cloudprovider.SOsDefaultAccount{
  39. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  40. Changeable: false,
  41. },
  42. Windows: cloudprovider.SOsDefaultAccount{
  43. DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
  44. Changeable: false,
  45. },
  46. },
  47. }
  48. }
  49. func (self *SEcloudGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
  50. keys := models.SComputeResourceKeys{}
  51. keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
  52. keys.CloudEnv = api.CLOUD_ENV_PUBLIC_CLOUD
  53. keys.Provider = api.CLOUD_PROVIDER_ECLOUD
  54. keys.Brand = api.CLOUD_PROVIDER_ECLOUD
  55. keys.Hypervisor = api.HYPERVISOR_ECLOUD
  56. return keys
  57. }
  58. func (self *SEcloudGuestDriver) GetDefaultSysDiskBackend() string {
  59. return api.STORAGE_ECLOUD_SYSTEM
  60. }
  61. func (self *SEcloudGuestDriver) GetDeployStatus() ([]string, error) {
  62. return []string{api.VM_READY, api.VM_RUNNING}, nil
  63. }
  64. func (self *SEcloudGuestDriver) GetMinimalSysDiskSizeGb() int {
  65. return 10
  66. }
  67. func (self *SEcloudGuestDriver) GetGuestInitialStateAfterCreate() string {
  68. return api.VM_RUNNING
  69. }
  70. func (self *SEcloudGuestDriver) GetDetachDiskStatus() ([]string, error) {
  71. return []string{api.VM_READY, api.VM_RUNNING}, nil
  72. }
  73. func (self *SEcloudGuestDriver) GetAttachDiskStatus() ([]string, error) {
  74. return []string{api.VM_READY, api.VM_RUNNING}, nil
  75. }
  76. func (self *SEcloudGuestDriver) GetChangeInstanceTypeStatus() ([]string, error) {
  77. return []string{api.VM_READY}, nil
  78. }
  79. func (self *SEcloudGuestDriver) GetRebuildRootStatus() ([]string, error) {
  80. return []string{api.VM_READY, api.VM_RUNNING}, nil
  81. }
  82. func (self *SEcloudGuestDriver) GetGuestInitialStateAfterRebuild() string {
  83. return api.VM_RUNNING
  84. }
  85. func (self *SEcloudGuestDriver) ValidateResizeDisk(guest *models.SGuest, disk *models.SDisk, storage *models.SStorage) error {
  86. return errors.ErrNotImplemented
  87. }
  88. func init() {
  89. driver := SEcloudGuestDriver{}
  90. models.RegisterGuestDriver(&driver)
  91. }