reservation.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "time"
  16. type SReservationOrder struct {
  17. Id string
  18. Name string
  19. Type string
  20. Properties struct {
  21. OriginalQuantity int
  22. RequestDateTime time.Time
  23. BillingPlan string
  24. Reservations []struct {
  25. Id string
  26. }
  27. Term string
  28. DisplayName string
  29. CreatedDateTime time.Time
  30. BenefitStartTime time.Time
  31. ProvisioningState string
  32. BillingProfileId string
  33. BillingAccountId string
  34. ExpiryDate time.Time
  35. ExpiryDateTime time.Time
  36. }
  37. }
  38. func (client *SAzureClient) ListReservationOrders() ([]SReservationOrder, error) {
  39. result := []SReservationOrder{}
  40. resp, err := client.list_v2("/providers/Microsoft.Capacity/reservationOrders", "2022-11-01", nil)
  41. if err != nil {
  42. return nil, err
  43. }
  44. err = resp.Unmarshal(&result, "value")
  45. if err != nil {
  46. return nil, err
  47. }
  48. return result, nil
  49. }
  50. type SReservation struct {
  51. Id string
  52. Name string
  53. Type string
  54. Location string
  55. Etag int
  56. Sku struct {
  57. Name string
  58. }
  59. Properties struct {
  60. ReservedResourceType string
  61. UserFriendlyRenewState string
  62. SkuDescription string
  63. Renew bool
  64. Archived bool
  65. Quantity int
  66. AppliedScopeType string
  67. DisplayName string
  68. ProvisioningState string
  69. Term string
  70. DisplayProvisioningState string
  71. UserFriendlyAppliedScopeType string
  72. ExpiryDateTime time.Time
  73. PurchaseDateTime time.Time
  74. BenefitStartTime time.Time
  75. LastUpdatedDateTime time.Time
  76. ExpiryDate string
  77. PurchaseDate string
  78. EffectiveDateTime time.Time
  79. InstanceFlexibility string
  80. Utilization struct {
  81. Trend string
  82. Aggregates []struct {
  83. Grain float64
  84. GrainUnit string
  85. Value float64
  86. ValueUnit string
  87. }
  88. }
  89. BillingPlan string
  90. BillingScopeId string
  91. }
  92. }
  93. func (client *SAzureClient) ListReservations() ([]SReservation, error) {
  94. result := []SReservation{}
  95. resp, err := client.list_v2("/providers/Microsoft.Capacity/reservations", "2022-11-01", nil)
  96. if err != nil {
  97. return nil, err
  98. }
  99. err = resp.Unmarshal(&result, "value")
  100. if err != nil {
  101. return nil, err
  102. }
  103. return result, nil
  104. }