SystemCapacityService.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. //
  2. // Copyright 2016, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package cloudstack
  17. import (
  18. "encoding/json"
  19. "net/url"
  20. "strconv"
  21. )
  22. type ListCapacityParams struct {
  23. p map[string]interface{}
  24. }
  25. func (p *ListCapacityParams) toURLValues() url.Values {
  26. u := url.Values{}
  27. if p.p == nil {
  28. return u
  29. }
  30. if v, found := p.p["clusterid"]; found {
  31. u.Set("clusterid", v.(string))
  32. }
  33. if v, found := p.p["fetchlatest"]; found {
  34. vv := strconv.FormatBool(v.(bool))
  35. u.Set("fetchlatest", vv)
  36. }
  37. if v, found := p.p["keyword"]; found {
  38. u.Set("keyword", v.(string))
  39. }
  40. if v, found := p.p["page"]; found {
  41. vv := strconv.Itoa(v.(int))
  42. u.Set("page", vv)
  43. }
  44. if v, found := p.p["pagesize"]; found {
  45. vv := strconv.Itoa(v.(int))
  46. u.Set("pagesize", vv)
  47. }
  48. if v, found := p.p["podid"]; found {
  49. u.Set("podid", v.(string))
  50. }
  51. if v, found := p.p["sortby"]; found {
  52. u.Set("sortby", v.(string))
  53. }
  54. if v, found := p.p["type"]; found {
  55. vv := strconv.Itoa(v.(int))
  56. u.Set("type", vv)
  57. }
  58. if v, found := p.p["zoneid"]; found {
  59. u.Set("zoneid", v.(string))
  60. }
  61. return u
  62. }
  63. func (p *ListCapacityParams) SetClusterid(v string) {
  64. if p.p == nil {
  65. p.p = make(map[string]interface{})
  66. }
  67. p.p["clusterid"] = v
  68. return
  69. }
  70. func (p *ListCapacityParams) SetFetchlatest(v bool) {
  71. if p.p == nil {
  72. p.p = make(map[string]interface{})
  73. }
  74. p.p["fetchlatest"] = v
  75. return
  76. }
  77. func (p *ListCapacityParams) SetKeyword(v string) {
  78. if p.p == nil {
  79. p.p = make(map[string]interface{})
  80. }
  81. p.p["keyword"] = v
  82. return
  83. }
  84. func (p *ListCapacityParams) SetPage(v int) {
  85. if p.p == nil {
  86. p.p = make(map[string]interface{})
  87. }
  88. p.p["page"] = v
  89. return
  90. }
  91. func (p *ListCapacityParams) SetPagesize(v int) {
  92. if p.p == nil {
  93. p.p = make(map[string]interface{})
  94. }
  95. p.p["pagesize"] = v
  96. return
  97. }
  98. func (p *ListCapacityParams) SetPodid(v string) {
  99. if p.p == nil {
  100. p.p = make(map[string]interface{})
  101. }
  102. p.p["podid"] = v
  103. return
  104. }
  105. func (p *ListCapacityParams) SetSortby(v string) {
  106. if p.p == nil {
  107. p.p = make(map[string]interface{})
  108. }
  109. p.p["sortby"] = v
  110. return
  111. }
  112. func (p *ListCapacityParams) SetType(v int) {
  113. if p.p == nil {
  114. p.p = make(map[string]interface{})
  115. }
  116. p.p["systemCapacityType"] = v
  117. return
  118. }
  119. func (p *ListCapacityParams) SetZoneid(v string) {
  120. if p.p == nil {
  121. p.p = make(map[string]interface{})
  122. }
  123. p.p["zoneid"] = v
  124. return
  125. }
  126. // You should always use this function to get a new ListCapacityParams instance,
  127. // as then you are sure you have configured all required params
  128. func (s *SystemCapacityService) NewListCapacityParams() *ListCapacityParams {
  129. p := &ListCapacityParams{}
  130. p.p = make(map[string]interface{})
  131. return p
  132. }
  133. // Lists all the system wide capacities.
  134. func (s *SystemCapacityService) ListCapacity(p *ListCapacityParams) (*ListCapacityResponse, error) {
  135. resp, err := s.cs.newRequest("listCapacity", p.toURLValues())
  136. if err != nil {
  137. return nil, err
  138. }
  139. var r ListCapacityResponse
  140. if err := json.Unmarshal(resp, &r); err != nil {
  141. return nil, err
  142. }
  143. return &r, nil
  144. }
  145. type ListCapacityResponse struct {
  146. Count int `json:"count"`
  147. Capacity []*Capacity `json:"capacity"`
  148. }
  149. type Capacity struct {
  150. Capacitytotal int64 `json:"capacitytotal,omitempty"`
  151. Capacityused int64 `json:"capacityused,omitempty"`
  152. Clusterid string `json:"clusterid,omitempty"`
  153. Clustername string `json:"clustername,omitempty"`
  154. Percentused string `json:"percentused,omitempty"`
  155. Podid string `json:"podid,omitempty"`
  156. Podname string `json:"podname,omitempty"`
  157. Type int `json:"type,omitempty"`
  158. Zoneid string `json:"zoneid,omitempty"`
  159. Zonename string `json:"zonename,omitempty"`
  160. }