bingocloud.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. "yunion.io/x/cloudmux/pkg/cloudprovider"
  18. "yunion.io/x/log"
  19. "yunion.io/x/pkg/util/billing"
  20. "yunion.io/x/pkg/util/rbacscope"
  21. "yunion.io/x/sqlchemy"
  22. api "yunion.io/x/onecloud/pkg/apis/compute"
  23. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  24. "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
  25. "yunion.io/x/onecloud/pkg/compute/models"
  26. "yunion.io/x/onecloud/pkg/compute/options"
  27. "yunion.io/x/onecloud/pkg/mcclient"
  28. )
  29. type SBingoCloudGuestDriver struct {
  30. SManagedVirtualizedGuestDriver
  31. }
  32. func init() {
  33. driver := SBingoCloudGuestDriver{}
  34. models.RegisterGuestDriver(&driver)
  35. }
  36. func (self *SBingoCloudGuestDriver) DoScheduleCPUFilter() bool { return false }
  37. func (self *SBingoCloudGuestDriver) DoScheduleMemoryFilter() bool { return false }
  38. func (self *SBingoCloudGuestDriver) DoScheduleSKUFilter() bool { return false }
  39. func (self *SBingoCloudGuestDriver) DoScheduleStorageFilter() bool { return false }
  40. func (self *SBingoCloudGuestDriver) GetHypervisor() string {
  41. return api.HYPERVISOR_BINGO_CLOUD
  42. }
  43. func (self *SBingoCloudGuestDriver) GetProvider() string {
  44. return api.CLOUD_PROVIDER_BINGO_CLOUD
  45. }
  46. func (self *SBingoCloudGuestDriver) GetMinimalSysDiskSizeGb() int {
  47. return options.Options.DefaultDiskSizeMB / 1024
  48. }
  49. func (self *SBingoCloudGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  50. return cloudprovider.SInstanceCapability{
  51. Hypervisor: self.GetHypervisor(),
  52. Provider: self.GetProvider(),
  53. DefaultAccount: cloudprovider.SDefaultAccount{
  54. Linux: cloudprovider.SOsDefaultAccount{
  55. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  56. Changeable: true,
  57. },
  58. Windows: cloudprovider.SOsDefaultAccount{
  59. DefaultAccount: api.VM_DEFAULT_WINDOWS_LOGIN_USER,
  60. Changeable: false,
  61. },
  62. },
  63. }
  64. }
  65. func (self *SBingoCloudGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
  66. keys := models.SComputeResourceKeys{}
  67. keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
  68. keys.CloudEnv = api.CLOUD_ENV_PRIVATE_CLOUD
  69. keys.Provider = api.CLOUD_PROVIDER_BINGO_CLOUD
  70. keys.Brand = api.CLOUD_PROVIDER_BINGO_CLOUD
  71. keys.Hypervisor = api.HYPERVISOR_BINGO_CLOUD
  72. return keys
  73. }
  74. func (self *SBingoCloudGuestDriver) GetDeployStatus() ([]string, error) {
  75. return []string{api.VM_READY, api.VM_RUNNING}, nil
  76. }
  77. func (self *SBingoCloudGuestDriver) GetDefaultSysDiskBackend() string {
  78. return ""
  79. }
  80. func (self *SBingoCloudGuestDriver) GetGuestInitialStateAfterCreate() string {
  81. return api.VM_RUNNING
  82. }
  83. func (self *SBingoCloudGuestDriver) GetGuestInitialStateAfterRebuild() string {
  84. return api.VM_READY
  85. }
  86. func (self *SBingoCloudGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
  87. return false
  88. }
  89. func (self *SBingoCloudGuestDriver) RemoteDeployGuestSyncHost(ctx context.Context, userCred mcclient.TokenCredential, guest *models.SGuest, host *models.SHost, iVM cloudprovider.ICloudVM) (cloudprovider.ICloudHost, error) {
  90. if hostId := iVM.GetIHostId(); len(hostId) > 0 {
  91. nh, err := db.FetchByExternalIdAndManagerId(models.HostManager, hostId, func(q *sqlchemy.SQuery) *sqlchemy.SQuery {
  92. return q.Equals("manager_id", host.ManagerId)
  93. })
  94. if err != nil {
  95. log.Warningf("failed to found new hostId(%s) for ivm %s(%s) error: %v", hostId, guest.Name, guest.Id, err)
  96. } else if nh.GetId() != guest.HostId {
  97. guest.OnScheduleToHost(ctx, userCred, nh.GetId())
  98. host = nh.(*models.SHost)
  99. }
  100. }
  101. return host.GetIHost(ctx)
  102. }