hcs.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 SHCSHostDriver struct {
  24. SManagedVirtualizationHostDriver
  25. }
  26. func init() {
  27. driver := SHCSHostDriver{}
  28. models.RegisterHostDriver(&driver)
  29. }
  30. func (self *SHCSHostDriver) GetHostType() string {
  31. return api.HOST_TYPE_HCS
  32. }
  33. func (self *SHCSHostDriver) GetHypervisor() string {
  34. return api.HYPERVISOR_HCS
  35. }
  36. func (self *SHCSHostDriver) GetProvider() string {
  37. return api.CLOUD_PROVIDER_HCS
  38. }
  39. // 系统盘必须至少40G
  40. func (self *SHCSHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
  41. if sizeGb < 1 || sizeGb > 65536 {
  42. return fmt.Errorf("The %s disk size must be in the range of 1G ~ 65536GB", storage.StorageType)
  43. }
  44. return nil
  45. }
  46. func (self *SHCSHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
  47. if len(guests) >= 1 {
  48. if disk.DiskType == api.DISK_TYPE_SYS {
  49. for _, g := range guests {
  50. if g.Status != api.VM_READY {
  51. return nil, httperrors.NewBadRequestError("Server %s must in status ready", g.GetName())
  52. }
  53. }
  54. } else {
  55. return nil, httperrors.NewBadRequestError("Disk must be detached")
  56. }
  57. }
  58. return input, nil
  59. }