azure.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/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 SAzureHostDriver struct {
  26. SManagedVirtualizationHostDriver
  27. }
  28. func init() {
  29. driver := SAzureHostDriver{}
  30. models.RegisterHostDriver(&driver)
  31. }
  32. func (self *SAzureHostDriver) GetHostType() string {
  33. return api.HOST_TYPE_AZURE
  34. }
  35. func (self *SAzureHostDriver) GetHypervisor() string {
  36. return api.HYPERVISOR_AZURE
  37. }
  38. func (self *SAzureHostDriver) GetProvider() string {
  39. return api.CLOUD_PROVIDER_AZURE
  40. }
  41. func (self *SAzureHostDriver) ValidateUpdateDisk(ctx context.Context, userCred mcclient.TokenCredential, input *api.DiskUpdateInput) (*api.DiskUpdateInput, error) {
  42. if len(input.Name) > 0 {
  43. return input, httperrors.NewInputParameterError("cannot support change azure disk name")
  44. }
  45. return input, nil
  46. }
  47. func (self *SAzureHostDriver) ValidateResetDisk(ctx context.Context, userCred mcclient.TokenCredential, disk *models.SDisk, snapshot *models.SSnapshot, guests []models.SGuest, input *api.DiskResetInput) (*api.DiskResetInput, error) {
  48. return nil, httperrors.NewBadRequestError("Azure not support reset disk, you can create new disk with snapshot")
  49. }
  50. func (self *SAzureHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
  51. if utils.IsInStringArray(storage.StorageType, []string{api.STORAGE_STANDARD_LRS, api.STORAGE_STANDARDSSD_LRS, api.STORAGE_PREMIUM_LRS}) {
  52. if sizeGb < 1 || sizeGb > 4095 {
  53. return fmt.Errorf("The %s disk size must be in the range of 1G ~ 4095GB", storage.StorageType)
  54. }
  55. } else {
  56. return fmt.Errorf("Not support create %s disk", storage.StorageType)
  57. }
  58. return nil
  59. }
  60. func (self *SAzureHostDriver) RequestDeleteSnapshotWithStorage(ctx context.Context, host *models.SHost, snapshot *models.SSnapshot, task taskman.ITask) error {
  61. return httperrors.NewNotImplementedError("not implement")
  62. }