volcengine.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 SVolcengineHostDriver struct {
  26. SManagedVirtualizationHostDriver
  27. }
  28. func init() {
  29. driver := SVolcengineHostDriver{}
  30. models.RegisterHostDriver(&driver)
  31. }
  32. func (self *SVolcengineHostDriver) GetHostType() string {
  33. return api.HOST_TYPE_VOLCENGINE
  34. }
  35. func (self *SVolcengineHostDriver) GetHypervisor() string {
  36. return api.HYPERVISOR_VOLCENGINE
  37. }
  38. func (self *SVolcengineHostDriver) GetProvider() string {
  39. return api.CLOUD_PROVIDER_VOLCENGINE
  40. }
  41. func (self *SVolcengineHostDriver) 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_VOLC_CLOUD_PL0:
  48. min, max = 10, 32768
  49. case api.STORAGE_VOLC_CLOUD_FLEXPL:
  50. min, max = 10, 32768
  51. default:
  52. return fmt.Errorf("Not support create or resize %s disk", storage.StorageType)
  53. }
  54. if sizeGb < min || sizeGb > max {
  55. return fmt.Errorf("The %s disk size must be in the range of %d ~ %dGB", storage.StorageType, min, max)
  56. }
  57. return nil
  58. }
  59. func (self *SVolcengineHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
  60. for _, guest := range guests {
  61. if !utils.IsInStringArray(guest.Status, []string{api.VM_RUNNING, api.VM_READY}) {
  62. return nil, httperrors.NewBadGatewayError("Volcengine reset disk required guest status is running or ready")
  63. }
  64. }
  65. return input, nil
  66. }
  67. func (self *SVolcengineHostDriver) RequestDeleteSnapshotWithStorage(ctx context.Context, host *models.SHost, snapshot *models.SSnapshot, task taskman.ITask) error {
  68. return httperrors.NewNotImplementedError("not implement")
  69. }
  70. func (driver *SVolcengineHostDriver) GetStoragecacheQuota(host *models.SHost) int {
  71. return -1
  72. }