ctyun.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 SCtyunHostDriver struct {
  24. SManagedVirtualizationHostDriver
  25. }
  26. func init() {
  27. driver := SCtyunHostDriver{}
  28. models.RegisterHostDriver(&driver)
  29. }
  30. func (self *SCtyunHostDriver) GetHostType() string {
  31. return api.HOST_TYPE_CTYUN
  32. }
  33. func (self *SCtyunHostDriver) GetHypervisor() string {
  34. return api.HYPERVISOR_CTYUN
  35. }
  36. func (self *SCtyunHostDriver) GetProvider() string {
  37. return api.CLOUD_PROVIDER_CTYUN
  38. }
  39. // 系统盘必须至少40G
  40. func (self *SCtyunHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
  41. switch storage.StorageType {
  42. case api.STORAGE_CTYUN_SSD, api.STORAGE_CTYUN_SATA, api.STORAGE_CTYUN_SAS:
  43. if sizeGb < 10 || sizeGb > 32768 {
  44. return fmt.Errorf("The %s disk size must be in the range of 10G ~ 32768GB", storage.StorageType)
  45. }
  46. default:
  47. return fmt.Errorf("Not support create %s disk", storage.StorageType)
  48. }
  49. return nil
  50. }
  51. func (self *SCtyunHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
  52. if len(guests) >= 1 {
  53. return nil, httperrors.NewBadRequestError("Disk must be dettached")
  54. }
  55. return input, nil
  56. }