StoragePoolService.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 ListStorageProvidersParams struct {
  23. p map[string]interface{}
  24. }
  25. func (p *ListStorageProvidersParams) toURLValues() url.Values {
  26. u := url.Values{}
  27. if p.p == nil {
  28. return u
  29. }
  30. if v, found := p.p["keyword"]; found {
  31. u.Set("keyword", v.(string))
  32. }
  33. if v, found := p.p["page"]; found {
  34. vv := strconv.Itoa(v.(int))
  35. u.Set("page", vv)
  36. }
  37. if v, found := p.p["pagesize"]; found {
  38. vv := strconv.Itoa(v.(int))
  39. u.Set("pagesize", vv)
  40. }
  41. if v, found := p.p["type"]; found {
  42. u.Set("type", v.(string))
  43. }
  44. return u
  45. }
  46. func (p *ListStorageProvidersParams) SetKeyword(v string) {
  47. if p.p == nil {
  48. p.p = make(map[string]interface{})
  49. }
  50. p.p["keyword"] = v
  51. return
  52. }
  53. func (p *ListStorageProvidersParams) SetPage(v int) {
  54. if p.p == nil {
  55. p.p = make(map[string]interface{})
  56. }
  57. p.p["page"] = v
  58. return
  59. }
  60. func (p *ListStorageProvidersParams) SetPagesize(v int) {
  61. if p.p == nil {
  62. p.p = make(map[string]interface{})
  63. }
  64. p.p["pagesize"] = v
  65. return
  66. }
  67. func (p *ListStorageProvidersParams) SetType(v string) {
  68. if p.p == nil {
  69. p.p = make(map[string]interface{})
  70. }
  71. p.p["storagePoolType"] = v
  72. return
  73. }
  74. // You should always use this function to get a new ListStorageProvidersParams instance,
  75. // as then you are sure you have configured all required params
  76. func (s *StoragePoolService) NewListStorageProvidersParams(storagePoolType string) *ListStorageProvidersParams {
  77. p := &ListStorageProvidersParams{}
  78. p.p = make(map[string]interface{})
  79. p.p["storagePoolType"] = storagePoolType
  80. return p
  81. }
  82. // Lists storage providers.
  83. func (s *StoragePoolService) ListStorageProviders(p *ListStorageProvidersParams) (*ListStorageProvidersResponse, error) {
  84. resp, err := s.cs.newRequest("listStorageProviders", p.toURLValues())
  85. if err != nil {
  86. return nil, err
  87. }
  88. var r ListStorageProvidersResponse
  89. if err := json.Unmarshal(resp, &r); err != nil {
  90. return nil, err
  91. }
  92. return &r, nil
  93. }
  94. type ListStorageProvidersResponse struct {
  95. Count int `json:"count"`
  96. StorageProviders []*StorageProvider `json:"storageprovider"`
  97. }
  98. type StorageProvider struct {
  99. Name string `json:"name,omitempty"`
  100. Type string `json:"type,omitempty"`
  101. }
  102. type EnableStorageMaintenanceParams struct {
  103. p map[string]interface{}
  104. }
  105. func (p *EnableStorageMaintenanceParams) toURLValues() url.Values {
  106. u := url.Values{}
  107. if p.p == nil {
  108. return u
  109. }
  110. if v, found := p.p["id"]; found {
  111. u.Set("id", v.(string))
  112. }
  113. return u
  114. }
  115. func (p *EnableStorageMaintenanceParams) SetId(v string) {
  116. if p.p == nil {
  117. p.p = make(map[string]interface{})
  118. }
  119. p.p["id"] = v
  120. return
  121. }
  122. // You should always use this function to get a new EnableStorageMaintenanceParams instance,
  123. // as then you are sure you have configured all required params
  124. func (s *StoragePoolService) NewEnableStorageMaintenanceParams(id string) *EnableStorageMaintenanceParams {
  125. p := &EnableStorageMaintenanceParams{}
  126. p.p = make(map[string]interface{})
  127. p.p["id"] = id
  128. return p
  129. }
  130. // Puts storage pool into maintenance state
  131. func (s *StoragePoolService) EnableStorageMaintenance(p *EnableStorageMaintenanceParams) (*EnableStorageMaintenanceResponse, error) {
  132. resp, err := s.cs.newRequest("enableStorageMaintenance", p.toURLValues())
  133. if err != nil {
  134. return nil, err
  135. }
  136. var r EnableStorageMaintenanceResponse
  137. if err := json.Unmarshal(resp, &r); err != nil {
  138. return nil, err
  139. }
  140. // If we have a async client, we need to wait for the async result
  141. if s.cs.async {
  142. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  143. if err != nil {
  144. if err == AsyncTimeoutErr {
  145. return &r, err
  146. }
  147. return nil, err
  148. }
  149. b, err = getRawValue(b)
  150. if err != nil {
  151. return nil, err
  152. }
  153. if err := json.Unmarshal(b, &r); err != nil {
  154. return nil, err
  155. }
  156. }
  157. return &r, nil
  158. }
  159. type EnableStorageMaintenanceResponse struct {
  160. JobID string `json:"jobid,omitempty"`
  161. Capacityiops int64 `json:"capacityiops,omitempty"`
  162. Clusterid string `json:"clusterid,omitempty"`
  163. Clustername string `json:"clustername,omitempty"`
  164. Created string `json:"created,omitempty"`
  165. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  166. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  167. Disksizeused int64 `json:"disksizeused,omitempty"`
  168. Hypervisor string `json:"hypervisor,omitempty"`
  169. Id string `json:"id,omitempty"`
  170. Ipaddress string `json:"ipaddress,omitempty"`
  171. Name string `json:"name,omitempty"`
  172. Overprovisionfactor string `json:"overprovisionfactor,omitempty"`
  173. Path string `json:"path,omitempty"`
  174. Podid string `json:"podid,omitempty"`
  175. Podname string `json:"podname,omitempty"`
  176. Scope string `json:"scope,omitempty"`
  177. State string `json:"state,omitempty"`
  178. Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"`
  179. Suitableformigration bool `json:"suitableformigration,omitempty"`
  180. Tags string `json:"tags,omitempty"`
  181. Type string `json:"type,omitempty"`
  182. Zoneid string `json:"zoneid,omitempty"`
  183. Zonename string `json:"zonename,omitempty"`
  184. }
  185. type CancelStorageMaintenanceParams struct {
  186. p map[string]interface{}
  187. }
  188. func (p *CancelStorageMaintenanceParams) toURLValues() url.Values {
  189. u := url.Values{}
  190. if p.p == nil {
  191. return u
  192. }
  193. if v, found := p.p["id"]; found {
  194. u.Set("id", v.(string))
  195. }
  196. return u
  197. }
  198. func (p *CancelStorageMaintenanceParams) SetId(v string) {
  199. if p.p == nil {
  200. p.p = make(map[string]interface{})
  201. }
  202. p.p["id"] = v
  203. return
  204. }
  205. // You should always use this function to get a new CancelStorageMaintenanceParams instance,
  206. // as then you are sure you have configured all required params
  207. func (s *StoragePoolService) NewCancelStorageMaintenanceParams(id string) *CancelStorageMaintenanceParams {
  208. p := &CancelStorageMaintenanceParams{}
  209. p.p = make(map[string]interface{})
  210. p.p["id"] = id
  211. return p
  212. }
  213. // Cancels maintenance for primary storage
  214. func (s *StoragePoolService) CancelStorageMaintenance(p *CancelStorageMaintenanceParams) (*CancelStorageMaintenanceResponse, error) {
  215. resp, err := s.cs.newRequest("cancelStorageMaintenance", p.toURLValues())
  216. if err != nil {
  217. return nil, err
  218. }
  219. var r CancelStorageMaintenanceResponse
  220. if err := json.Unmarshal(resp, &r); err != nil {
  221. return nil, err
  222. }
  223. // If we have a async client, we need to wait for the async result
  224. if s.cs.async {
  225. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  226. if err != nil {
  227. if err == AsyncTimeoutErr {
  228. return &r, err
  229. }
  230. return nil, err
  231. }
  232. b, err = getRawValue(b)
  233. if err != nil {
  234. return nil, err
  235. }
  236. if err := json.Unmarshal(b, &r); err != nil {
  237. return nil, err
  238. }
  239. }
  240. return &r, nil
  241. }
  242. type CancelStorageMaintenanceResponse struct {
  243. JobID string `json:"jobid,omitempty"`
  244. Capacityiops int64 `json:"capacityiops,omitempty"`
  245. Clusterid string `json:"clusterid,omitempty"`
  246. Clustername string `json:"clustername,omitempty"`
  247. Created string `json:"created,omitempty"`
  248. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  249. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  250. Disksizeused int64 `json:"disksizeused,omitempty"`
  251. Hypervisor string `json:"hypervisor,omitempty"`
  252. Id string `json:"id,omitempty"`
  253. Ipaddress string `json:"ipaddress,omitempty"`
  254. Name string `json:"name,omitempty"`
  255. Overprovisionfactor string `json:"overprovisionfactor,omitempty"`
  256. Path string `json:"path,omitempty"`
  257. Podid string `json:"podid,omitempty"`
  258. Podname string `json:"podname,omitempty"`
  259. Scope string `json:"scope,omitempty"`
  260. State string `json:"state,omitempty"`
  261. Storagecapabilities map[string]string `json:"storagecapabilities,omitempty"`
  262. Suitableformigration bool `json:"suitableformigration,omitempty"`
  263. Tags string `json:"tags,omitempty"`
  264. Type string `json:"type,omitempty"`
  265. Zoneid string `json:"zoneid,omitempty"`
  266. Zonename string `json:"zonename,omitempty"`
  267. }