quota.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 hcso
  15. import (
  16. "yunion.io/x/pkg/errors"
  17. "yunion.io/x/cloudmux/pkg/cloudprovider"
  18. )
  19. type SQuota struct {
  20. Min int
  21. Quota int
  22. Type string
  23. Used int
  24. }
  25. func (q *SQuota) GetGlobalId() string {
  26. return q.Type
  27. }
  28. func (q *SQuota) GetQuotaType() string {
  29. return q.Type
  30. }
  31. func (q *SQuota) GetName() string {
  32. return q.Type
  33. }
  34. func (q *SQuota) GetDesc() string {
  35. return ""
  36. }
  37. func (q *SQuota) GetMaxQuotaCount() int {
  38. return q.Quota
  39. }
  40. func (q *SQuota) GetCurrentQuotaUsedCount() int {
  41. return q.Used
  42. }
  43. func (self *SRegion) GetQuotas() ([]SQuota, error) {
  44. quotas := []SQuota{}
  45. params := map[string]string{}
  46. result, err := self.ecsClient.Quotas.Get("", params)
  47. if err != nil {
  48. return nil, errors.Wrap(err, "Quotas.List")
  49. }
  50. err = result.Unmarshal(&quotas, "resources")
  51. if err != nil {
  52. return nil, errors.Wrap(err, "result.Unmarshal")
  53. }
  54. return quotas, nil
  55. }
  56. func (region *SRegion) GetICloudQuotas() ([]cloudprovider.ICloudQuota, error) {
  57. quotas, err := region.GetQuotas()
  58. if err != nil {
  59. return nil, errors.Wrap(err, "GetQuotas")
  60. }
  61. ret := []cloudprovider.ICloudQuota{}
  62. for i := range quotas {
  63. ret = append(ret, &quotas[i])
  64. }
  65. return ret, nil
  66. }