aws.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/compute/models"
  21. "yunion.io/x/onecloud/pkg/httperrors"
  22. "yunion.io/x/onecloud/pkg/mcclient"
  23. )
  24. type SAwsHostDriver struct {
  25. SManagedVirtualizationHostDriver
  26. }
  27. func init() {
  28. driver := SAwsHostDriver{}
  29. models.RegisterHostDriver(&driver)
  30. }
  31. func (self *SAwsHostDriver) GetHostType() string {
  32. return api.HOST_TYPE_AWS
  33. }
  34. func (self *SAwsHostDriver) GetHypervisor() string {
  35. return api.HYPERVISOR_AWS
  36. }
  37. func (self *SAwsHostDriver) GetProvider() string {
  38. return api.CLOUD_PROVIDER_AWS
  39. }
  40. func (self *SAwsHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
  41. if storage.StorageType == api.STORAGE_GP2_SSD || storage.StorageType == api.STORAGE_GP3_SSD {
  42. if sizeGb < 1 || sizeGb > 16384 {
  43. return fmt.Errorf("The %s disk size must be in the range of 1G ~ 16384GB", storage.StorageType)
  44. }
  45. } else if storage.StorageType == api.STORAGE_IO1_SSD || storage.StorageType == api.STORAGE_IO2_SSD {
  46. if sizeGb < 4 || sizeGb > 16384 {
  47. return fmt.Errorf("The %s disk size must be in the range of 4G ~ 16384GB", storage.StorageType)
  48. }
  49. } else if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_ST1_HDD, api.STORAGE_SC1_HDD}) {
  50. if sizeGb < 500 || sizeGb > 16384 {
  51. return fmt.Errorf("The %s disk size must be in the range of 500G ~ 16384GB", storage.StorageType)
  52. }
  53. } else if storage.StorageType == api.STORAGE_STANDARD_HDD {
  54. if sizeGb < 1 || sizeGb > 1024 {
  55. return fmt.Errorf("The %s disk size must be in the range of 1G ~ 1024GB", storage.StorageType)
  56. }
  57. } else {
  58. return fmt.Errorf("Not support create %s disk", storage.StorageType)
  59. }
  60. return nil
  61. }
  62. func (self *SAwsHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
  63. return nil, httperrors.NewBadRequestError("Aws not support reset disk, you can create new disk with snapshot")
  64. }