qcloud.go 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. "yunion.io/x/pkg/utils"
  19. api "yunion.io/x/onecloud/pkg/apis/compute"
  20. "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
  21. "yunion.io/x/onecloud/pkg/compute/models"
  22. "yunion.io/x/onecloud/pkg/httperrors"
  23. "yunion.io/x/onecloud/pkg/mcclient"
  24. )
  25. type SQcloudHostDriver struct {
  26. SManagedVirtualizationHostDriver
  27. }
  28. func init() {
  29. driver := SQcloudHostDriver{}
  30. models.RegisterHostDriver(&driver)
  31. }
  32. func (self *SQcloudHostDriver) GetHostType() string {
  33. return api.HOST_TYPE_QCLOUD
  34. }
  35. func (self *SQcloudHostDriver) GetHypervisor() string {
  36. return api.HYPERVISOR_QCLOUD
  37. }
  38. func (self *SQcloudHostDriver) GetProvider() string {
  39. return api.CLOUD_PROVIDER_QCLOUD
  40. }
  41. func (self *SQcloudHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
  42. if sizeGb%10 != 0 {
  43. return fmt.Errorf("The disk size must be a multiple of 10Gb")
  44. }
  45. min, max := 0, 0
  46. switch storage.StorageType {
  47. case api.STORAGE_CLOUD_BASIC:
  48. min, max = 10, 16000
  49. case api.STORAGE_CLOUD_PREMIUM:
  50. min, max = 50, 16000
  51. case api.STORAGE_CLOUD_SSD:
  52. min, max = 100, 16000
  53. case api.STORAGE_CLOUD_HSSD, api.STORAGE_CLOUD_BSSD, api.STORAGE_CLOUD_TSSD:
  54. min, max = 20, 320000
  55. default:
  56. return fmt.Errorf("Not support create or resize %s disk", storage.StorageType)
  57. }
  58. if sizeGb < min || sizeGb > max {
  59. return fmt.Errorf("The %s disk size must be in the range of %d ~ %dGB", storage.StorageType, min, max)
  60. }
  61. return nil
  62. }
  63. func (self *SQcloudHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
  64. for _, guest := range guests {
  65. if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) {
  66. return nil, httperrors.NewBadGatewayError("Qcloud reset disk required guest status is running or ready")
  67. }
  68. }
  69. return input, nil
  70. }
  71. func (self *SQcloudHostDriver) RequestDeleteSnapshotWithStorage(ctx context.Context, host *models.SHost, snapshot *models.SSnapshot, task taskman.ITask) error {
  72. return httperrors.NewNotImplementedError("not implement")
  73. }
  74. func (driver *SQcloudHostDriver) GetStoragecacheQuota(host *models.SHost) int {
  75. return 500
  76. }