subscription.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 azure
  15. import (
  16. api "yunion.io/x/cloudmux/pkg/apis/compute"
  17. )
  18. type SSubscription struct {
  19. SubscriptionId string
  20. State string
  21. DisplayName string
  22. Id string
  23. SubscriptionPolicies struct {
  24. LocationPlacementId string
  25. QuotaId string
  26. SpendingLimit string
  27. }
  28. }
  29. func (self *SSubscription) GetHealthStatus() string {
  30. if self.State == "Enabled" {
  31. return api.CLOUD_PROVIDER_HEALTH_NORMAL
  32. }
  33. return api.CLOUD_PROVIDER_HEALTH_SUSPENDED
  34. }
  35. func (self *SAzureClient) ListSubscriptions() ([]SSubscription, error) {
  36. resp, err := self.list_v2("subscriptions", "2014-02-26", nil)
  37. if err != nil {
  38. return nil, err
  39. }
  40. result := []SSubscription{}
  41. err = resp.Unmarshal(&result, "value")
  42. if err != nil {
  43. return nil, err
  44. }
  45. return result, nil
  46. }