jdcloud.go 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/util/billing"
  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 SJDcloudGuestDriver struct {
  25. SManagedVirtualizedGuestDriver
  26. }
  27. func init() {
  28. driver := SJDcloudGuestDriver{}
  29. models.RegisterGuestDriver(&driver)
  30. }
  31. func (self *SJDcloudGuestDriver) GetHypervisor() string {
  32. return api.HYPERVISOR_JDCLOUD
  33. }
  34. func (self *SJDcloudGuestDriver) GetProvider() string {
  35. return api.CLOUD_PROVIDER_JDCLOUD
  36. }
  37. func (self *SJDcloudGuestDriver) GetComputeQuotaKeys(scope rbacscope.TRbacScope, ownerId mcclient.IIdentityProvider, brand string) models.SComputeResourceKeys {
  38. keys := models.SComputeResourceKeys{}
  39. keys.SBaseProjectQuotaKeys = quotas.OwnerIdProjectQuotaKeys(scope, ownerId)
  40. keys.CloudEnv = api.CLOUD_ENV_PUBLIC_CLOUD
  41. keys.Provider = api.CLOUD_PROVIDER_JDCLOUD
  42. keys.Brand = api.CLOUD_PROVIDER_JDCLOUD
  43. keys.Hypervisor = api.HYPERVISOR_JDCLOUD
  44. return keys
  45. }
  46. func (self *SJDcloudGuestDriver) GetDefaultSysDiskBackend() string {
  47. return api.STORAGE_JDCLOUD_GP1
  48. }
  49. // 系统盘:
  50. // local:不能指定大小,默认为40GB
  51. // cloud:取值范围: [40,500]GB,并且不能小于镜像的最小系统盘大小,如果没有指定,默认以镜像中的系统盘大小为准
  52. func (self *SJDcloudGuestDriver) GetMinimalSysDiskSizeGb() int {
  53. return 40
  54. }
  55. // 云硬盘大小,单位为 GiB;ssd.io1 类型取值范围[20,16000]GB,步长为10G;
  56. // ssd.gp1 类型取值范围[20,16000]GB,步长为10G;
  57. // hdd.std1 类型取值范围[20,16000]GB,步长为10G
  58. func (self *SJDcloudGuestDriver) GetInstanceCapability() cloudprovider.SInstanceCapability {
  59. return cloudprovider.SInstanceCapability{
  60. Hypervisor: self.GetHypervisor(),
  61. Provider: self.GetProvider(),
  62. DefaultAccount: cloudprovider.SDefaultAccount{
  63. Linux: cloudprovider.SOsDefaultAccount{
  64. DefaultAccount: api.VM_DEFAULT_LINUX_LOGIN_USER,
  65. },
  66. Windows: cloudprovider.SOsDefaultAccount{
  67. DefaultAccount: api.VM_JDCLOUD_DEFAULT_WINDOWS_LOGIN_USER,
  68. },
  69. },
  70. Storages: cloudprovider.Storage{
  71. DataDisk: []cloudprovider.StorageInfo{
  72. cloudprovider.StorageInfo{StorageType: api.STORAGE_JDCLOUD_STD, MaxSizeGb: 16000, MinSizeGb: 20, StepSizeGb: 10, Resizable: true},
  73. cloudprovider.StorageInfo{StorageType: api.STORAGE_JDCLOUD_GP1, MaxSizeGb: 16000, MinSizeGb: 20, StepSizeGb: 10, Resizable: true},
  74. cloudprovider.StorageInfo{StorageType: api.STORAGE_JDCLOUD_IO1, MaxSizeGb: 16000, MinSizeGb: 20, StepSizeGb: 10, Resizable: true},
  75. },
  76. SysDisk: []cloudprovider.StorageInfo{
  77. cloudprovider.StorageInfo{StorageType: api.STORAGE_JDCLOUD_STD, MaxSizeGb: 500, MinSizeGb: 40, StepSizeGb: 10, Resizable: false},
  78. cloudprovider.StorageInfo{StorageType: api.STORAGE_JDCLOUD_GP1, MaxSizeGb: 500, MinSizeGb: 40, StepSizeGb: 10, Resizable: false},
  79. cloudprovider.StorageInfo{StorageType: api.STORAGE_JDCLOUD_IO1, MaxSizeGb: 500, MinSizeGb: 40, StepSizeGb: 10, Resizable: false},
  80. },
  81. },
  82. }
  83. }
  84. func (self *SJDcloudGuestDriver) IsSupportedBillingCycle(bc billing.SBillingCycle) bool {
  85. months := bc.GetMonths()
  86. if (months >= 1 && months <= 9) || (months == 12) || (months == 24) || (months == 36) {
  87. return true
  88. }
  89. return false
  90. }