jdcloud.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 hostdrivers
  15. import (
  16. "context"
  17. "fmt"
  18. api "yunion.io/x/onecloud/pkg/apis/compute"
  19. "yunion.io/x/onecloud/pkg/compute/models"
  20. "yunion.io/x/onecloud/pkg/httperrors"
  21. "yunion.io/x/onecloud/pkg/mcclient"
  22. )
  23. type SJDcloudHostDriver struct {
  24. SManagedVirtualizationHostDriver
  25. }
  26. func init() {
  27. driver := SJDcloudHostDriver{}
  28. models.RegisterHostDriver(&driver)
  29. }
  30. func (self *SJDcloudHostDriver) GetHostType() string {
  31. return api.HOST_TYPE_JDCLOUD
  32. }
  33. func (self *SJDcloudHostDriver) GetHypervisor() string {
  34. return api.HYPERVISOR_JDCLOUD
  35. }
  36. func (self *SJDcloudHostDriver) GetProvider() string {
  37. return api.CLOUD_PROVIDER_JDCLOUD
  38. }
  39. // ValidateResetDisk 仅可用状态的云硬盘支持恢复
  40. // 卸载硬盘需要停止云主机
  41. func (self *SJDcloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
  42. return nil, httperrors.NewNotSupportedError("not supported resize disk")
  43. }
  44. // ValidateDiskSize
  45. // 云硬盘大小,单位为 GiB;ssd.io1 类型取值范围[20,16000]GB,步长为10G;
  46. // ssd.gp1 类型取值范围[20,16000]GB,步长为10G;
  47. // hdd.std1 类型取值范围[20,16000]GB,步长为10G
  48. //
  49. // 系统盘:
  50. // local:不能指定大小,默认为40GB
  51. // cloud:取值范围: [40,500]GB,并且不能小于镜像的最小系统盘大小,如果没有指定,默认以镜像中的系统盘大小为准
  52. func (self *SJDcloudHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
  53. switch storage.StorageType {
  54. case api.STORAGE_JDCLOUD_GP1, api.STORAGE_JDCLOUD_IO1, api.STORAGE_JDCLOUD_STD:
  55. if sizeGb < 20 || sizeGb > 16000 {
  56. return fmt.Errorf("The %s disk size must be in the range of 20G ~ 16000GB", storage.StorageType)
  57. }
  58. default:
  59. return fmt.Errorf("Not support create %s disk", storage.StorageType)
  60. }
  61. return nil
  62. }