baidu.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. "fmt"
  17. api "yunion.io/x/onecloud/pkg/apis/compute"
  18. "yunion.io/x/onecloud/pkg/compute/models"
  19. )
  20. type SBaiduHostDriver struct {
  21. SManagedVirtualizationHostDriver
  22. }
  23. func init() {
  24. driver := SBaiduHostDriver{}
  25. models.RegisterHostDriver(&driver)
  26. }
  27. func (self *SBaiduHostDriver) GetHostType() string {
  28. return api.HOST_TYPE_BAIDU
  29. }
  30. func (self *SBaiduHostDriver) GetHypervisor() string {
  31. return api.HYPERVISOR_BAIDU
  32. }
  33. func (self *SBaiduHostDriver) GetProvider() string {
  34. return api.CLOUD_PROVIDER_BAIDU
  35. }
  36. func (self *SBaiduHostDriver) ValidateDiskSize(storage *models.SStorage, sizeGb int) error {
  37. min, max := 20, 32765
  38. switch storage.StorageType {
  39. case api.STORAGE_BAIDU_HDD:
  40. min = 5
  41. case api.STORAGE_BAIDU_SSD:
  42. min = 50
  43. case api.STORAGE_BAIDU_PREMIUM_SSD:
  44. min = 5
  45. }
  46. if sizeGb < min || sizeGb > max {
  47. return fmt.Errorf("The %s disk size must be in the range of %d ~ %dGB", storage.StorageType, min, max)
  48. }
  49. return nil
  50. }