RegionService.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 AddRegionParams struct {
  23. p map[string]interface{}
  24. }
  25. func (p *AddRegionParams) toURLValues() url.Values {
  26. u := url.Values{}
  27. if p.p == nil {
  28. return u
  29. }
  30. if v, found := p.p["endpoint"]; found {
  31. u.Set("endpoint", v.(string))
  32. }
  33. if v, found := p.p["id"]; found {
  34. vv := strconv.Itoa(v.(int))
  35. u.Set("id", vv)
  36. }
  37. if v, found := p.p["name"]; found {
  38. u.Set("name", v.(string))
  39. }
  40. return u
  41. }
  42. func (p *AddRegionParams) SetEndpoint(v string) {
  43. if p.p == nil {
  44. p.p = make(map[string]interface{})
  45. }
  46. p.p["endpoint"] = v
  47. return
  48. }
  49. func (p *AddRegionParams) SetId(v int) {
  50. if p.p == nil {
  51. p.p = make(map[string]interface{})
  52. }
  53. p.p["id"] = v
  54. return
  55. }
  56. func (p *AddRegionParams) SetName(v string) {
  57. if p.p == nil {
  58. p.p = make(map[string]interface{})
  59. }
  60. p.p["name"] = v
  61. return
  62. }
  63. // You should always use this function to get a new AddRegionParams instance,
  64. // as then you are sure you have configured all required params
  65. func (s *RegionService) NewAddRegionParams(endpoint string, id int, name string) *AddRegionParams {
  66. p := &AddRegionParams{}
  67. p.p = make(map[string]interface{})
  68. p.p["endpoint"] = endpoint
  69. p.p["id"] = id
  70. p.p["name"] = name
  71. return p
  72. }
  73. // Adds a Region
  74. func (s *RegionService) AddRegion(p *AddRegionParams) (*AddRegionResponse, error) {
  75. resp, err := s.cs.newRequest("addRegion", p.toURLValues())
  76. if err != nil {
  77. return nil, err
  78. }
  79. var r AddRegionResponse
  80. if err := json.Unmarshal(resp, &r); err != nil {
  81. return nil, err
  82. }
  83. return &r, nil
  84. }
  85. type AddRegionResponse struct {
  86. Endpoint string `json:"endpoint,omitempty"`
  87. Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"`
  88. Id int `json:"id,omitempty"`
  89. Name string `json:"name,omitempty"`
  90. Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"`
  91. }
  92. type UpdateRegionParams struct {
  93. p map[string]interface{}
  94. }
  95. func (p *UpdateRegionParams) toURLValues() url.Values {
  96. u := url.Values{}
  97. if p.p == nil {
  98. return u
  99. }
  100. if v, found := p.p["endpoint"]; found {
  101. u.Set("endpoint", v.(string))
  102. }
  103. if v, found := p.p["id"]; found {
  104. vv := strconv.Itoa(v.(int))
  105. u.Set("id", vv)
  106. }
  107. if v, found := p.p["name"]; found {
  108. u.Set("name", v.(string))
  109. }
  110. return u
  111. }
  112. func (p *UpdateRegionParams) SetEndpoint(v string) {
  113. if p.p == nil {
  114. p.p = make(map[string]interface{})
  115. }
  116. p.p["endpoint"] = v
  117. return
  118. }
  119. func (p *UpdateRegionParams) SetId(v int) {
  120. if p.p == nil {
  121. p.p = make(map[string]interface{})
  122. }
  123. p.p["id"] = v
  124. return
  125. }
  126. func (p *UpdateRegionParams) SetName(v string) {
  127. if p.p == nil {
  128. p.p = make(map[string]interface{})
  129. }
  130. p.p["name"] = v
  131. return
  132. }
  133. // You should always use this function to get a new UpdateRegionParams instance,
  134. // as then you are sure you have configured all required params
  135. func (s *RegionService) NewUpdateRegionParams(id int) *UpdateRegionParams {
  136. p := &UpdateRegionParams{}
  137. p.p = make(map[string]interface{})
  138. p.p["id"] = id
  139. return p
  140. }
  141. // Updates a region
  142. func (s *RegionService) UpdateRegion(p *UpdateRegionParams) (*UpdateRegionResponse, error) {
  143. resp, err := s.cs.newRequest("updateRegion", p.toURLValues())
  144. if err != nil {
  145. return nil, err
  146. }
  147. var r UpdateRegionResponse
  148. if err := json.Unmarshal(resp, &r); err != nil {
  149. return nil, err
  150. }
  151. return &r, nil
  152. }
  153. type UpdateRegionResponse struct {
  154. Endpoint string `json:"endpoint,omitempty"`
  155. Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"`
  156. Id int `json:"id,omitempty"`
  157. Name string `json:"name,omitempty"`
  158. Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"`
  159. }
  160. type RemoveRegionParams struct {
  161. p map[string]interface{}
  162. }
  163. func (p *RemoveRegionParams) toURLValues() url.Values {
  164. u := url.Values{}
  165. if p.p == nil {
  166. return u
  167. }
  168. if v, found := p.p["id"]; found {
  169. vv := strconv.Itoa(v.(int))
  170. u.Set("id", vv)
  171. }
  172. return u
  173. }
  174. func (p *RemoveRegionParams) SetId(v int) {
  175. if p.p == nil {
  176. p.p = make(map[string]interface{})
  177. }
  178. p.p["id"] = v
  179. return
  180. }
  181. // You should always use this function to get a new RemoveRegionParams instance,
  182. // as then you are sure you have configured all required params
  183. func (s *RegionService) NewRemoveRegionParams(id int) *RemoveRegionParams {
  184. p := &RemoveRegionParams{}
  185. p.p = make(map[string]interface{})
  186. p.p["id"] = id
  187. return p
  188. }
  189. // Removes specified region
  190. func (s *RegionService) RemoveRegion(p *RemoveRegionParams) (*RemoveRegionResponse, error) {
  191. resp, err := s.cs.newRequest("removeRegion", p.toURLValues())
  192. if err != nil {
  193. return nil, err
  194. }
  195. var r RemoveRegionResponse
  196. if err := json.Unmarshal(resp, &r); err != nil {
  197. return nil, err
  198. }
  199. return &r, nil
  200. }
  201. type RemoveRegionResponse struct {
  202. Displaytext string `json:"displaytext,omitempty"`
  203. Success string `json:"success,omitempty"`
  204. }
  205. type ListRegionsParams struct {
  206. p map[string]interface{}
  207. }
  208. func (p *ListRegionsParams) toURLValues() url.Values {
  209. u := url.Values{}
  210. if p.p == nil {
  211. return u
  212. }
  213. if v, found := p.p["id"]; found {
  214. vv := strconv.Itoa(v.(int))
  215. u.Set("id", vv)
  216. }
  217. if v, found := p.p["keyword"]; found {
  218. u.Set("keyword", v.(string))
  219. }
  220. if v, found := p.p["name"]; found {
  221. u.Set("name", v.(string))
  222. }
  223. if v, found := p.p["page"]; found {
  224. vv := strconv.Itoa(v.(int))
  225. u.Set("page", vv)
  226. }
  227. if v, found := p.p["pagesize"]; found {
  228. vv := strconv.Itoa(v.(int))
  229. u.Set("pagesize", vv)
  230. }
  231. return u
  232. }
  233. func (p *ListRegionsParams) SetId(v int) {
  234. if p.p == nil {
  235. p.p = make(map[string]interface{})
  236. }
  237. p.p["id"] = v
  238. return
  239. }
  240. func (p *ListRegionsParams) SetKeyword(v string) {
  241. if p.p == nil {
  242. p.p = make(map[string]interface{})
  243. }
  244. p.p["keyword"] = v
  245. return
  246. }
  247. func (p *ListRegionsParams) SetName(v string) {
  248. if p.p == nil {
  249. p.p = make(map[string]interface{})
  250. }
  251. p.p["name"] = v
  252. return
  253. }
  254. func (p *ListRegionsParams) SetPage(v int) {
  255. if p.p == nil {
  256. p.p = make(map[string]interface{})
  257. }
  258. p.p["page"] = v
  259. return
  260. }
  261. func (p *ListRegionsParams) SetPagesize(v int) {
  262. if p.p == nil {
  263. p.p = make(map[string]interface{})
  264. }
  265. p.p["pagesize"] = v
  266. return
  267. }
  268. // You should always use this function to get a new ListRegionsParams instance,
  269. // as then you are sure you have configured all required params
  270. func (s *RegionService) NewListRegionsParams() *ListRegionsParams {
  271. p := &ListRegionsParams{}
  272. p.p = make(map[string]interface{})
  273. return p
  274. }
  275. // Lists Regions
  276. func (s *RegionService) ListRegions(p *ListRegionsParams) (*ListRegionsResponse, error) {
  277. resp, err := s.cs.newRequest("listRegions", p.toURLValues())
  278. if err != nil {
  279. return nil, err
  280. }
  281. var r ListRegionsResponse
  282. if err := json.Unmarshal(resp, &r); err != nil {
  283. return nil, err
  284. }
  285. return &r, nil
  286. }
  287. type ListRegionsResponse struct {
  288. Count int `json:"count"`
  289. Regions []*Region `json:"region"`
  290. }
  291. type Region struct {
  292. Endpoint string `json:"endpoint,omitempty"`
  293. Gslbserviceenabled bool `json:"gslbserviceenabled,omitempty"`
  294. Id int `json:"id,omitempty"`
  295. Name string `json:"name,omitempty"`
  296. Portableipserviceenabled bool `json:"portableipserviceenabled,omitempty"`
  297. }