NiciraNVPService.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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 AddNiciraNvpDeviceParams struct {
  23. p map[string]interface{}
  24. }
  25. func (p *AddNiciraNvpDeviceParams) toURLValues() url.Values {
  26. u := url.Values{}
  27. if p.p == nil {
  28. return u
  29. }
  30. if v, found := p.p["hostname"]; found {
  31. u.Set("hostname", v.(string))
  32. }
  33. if v, found := p.p["l3gatewayserviceuuid"]; found {
  34. u.Set("l3gatewayserviceuuid", v.(string))
  35. }
  36. if v, found := p.p["password"]; found {
  37. u.Set("password", v.(string))
  38. }
  39. if v, found := p.p["physicalnetworkid"]; found {
  40. u.Set("physicalnetworkid", v.(string))
  41. }
  42. if v, found := p.p["transportzoneuuid"]; found {
  43. u.Set("transportzoneuuid", v.(string))
  44. }
  45. if v, found := p.p["username"]; found {
  46. u.Set("username", v.(string))
  47. }
  48. return u
  49. }
  50. func (p *AddNiciraNvpDeviceParams) SetHostname(v string) {
  51. if p.p == nil {
  52. p.p = make(map[string]interface{})
  53. }
  54. p.p["hostname"] = v
  55. return
  56. }
  57. func (p *AddNiciraNvpDeviceParams) SetL3gatewayserviceuuid(v string) {
  58. if p.p == nil {
  59. p.p = make(map[string]interface{})
  60. }
  61. p.p["l3gatewayserviceuuid"] = v
  62. return
  63. }
  64. func (p *AddNiciraNvpDeviceParams) SetPassword(v string) {
  65. if p.p == nil {
  66. p.p = make(map[string]interface{})
  67. }
  68. p.p["password"] = v
  69. return
  70. }
  71. func (p *AddNiciraNvpDeviceParams) SetPhysicalnetworkid(v string) {
  72. if p.p == nil {
  73. p.p = make(map[string]interface{})
  74. }
  75. p.p["physicalnetworkid"] = v
  76. return
  77. }
  78. func (p *AddNiciraNvpDeviceParams) SetTransportzoneuuid(v string) {
  79. if p.p == nil {
  80. p.p = make(map[string]interface{})
  81. }
  82. p.p["transportzoneuuid"] = v
  83. return
  84. }
  85. func (p *AddNiciraNvpDeviceParams) SetUsername(v string) {
  86. if p.p == nil {
  87. p.p = make(map[string]interface{})
  88. }
  89. p.p["username"] = v
  90. return
  91. }
  92. // You should always use this function to get a new AddNiciraNvpDeviceParams instance,
  93. // as then you are sure you have configured all required params
  94. func (s *NiciraNVPService) NewAddNiciraNvpDeviceParams(hostname string, password string, physicalnetworkid string, transportzoneuuid string, username string) *AddNiciraNvpDeviceParams {
  95. p := &AddNiciraNvpDeviceParams{}
  96. p.p = make(map[string]interface{})
  97. p.p["hostname"] = hostname
  98. p.p["password"] = password
  99. p.p["physicalnetworkid"] = physicalnetworkid
  100. p.p["transportzoneuuid"] = transportzoneuuid
  101. p.p["username"] = username
  102. return p
  103. }
  104. // Adds a Nicira NVP device
  105. func (s *NiciraNVPService) AddNiciraNvpDevice(p *AddNiciraNvpDeviceParams) (*AddNiciraNvpDeviceResponse, error) {
  106. resp, err := s.cs.newRequest("addNiciraNvpDevice", p.toURLValues())
  107. if err != nil {
  108. return nil, err
  109. }
  110. var r AddNiciraNvpDeviceResponse
  111. if err := json.Unmarshal(resp, &r); err != nil {
  112. return nil, err
  113. }
  114. // If we have a async client, we need to wait for the async result
  115. if s.cs.async {
  116. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  117. if err != nil {
  118. if err == AsyncTimeoutErr {
  119. return &r, err
  120. }
  121. return nil, err
  122. }
  123. b, err = getRawValue(b)
  124. if err != nil {
  125. return nil, err
  126. }
  127. if err := json.Unmarshal(b, &r); err != nil {
  128. return nil, err
  129. }
  130. }
  131. return &r, nil
  132. }
  133. type AddNiciraNvpDeviceResponse struct {
  134. JobID string `json:"jobid,omitempty"`
  135. Hostname string `json:"hostname,omitempty"`
  136. L3gatewayserviceuuid string `json:"l3gatewayserviceuuid,omitempty"`
  137. Niciradevicename string `json:"niciradevicename,omitempty"`
  138. Nvpdeviceid string `json:"nvpdeviceid,omitempty"`
  139. Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
  140. Provider string `json:"provider,omitempty"`
  141. Transportzoneuuid string `json:"transportzoneuuid,omitempty"`
  142. }
  143. type DeleteNiciraNvpDeviceParams struct {
  144. p map[string]interface{}
  145. }
  146. func (p *DeleteNiciraNvpDeviceParams) toURLValues() url.Values {
  147. u := url.Values{}
  148. if p.p == nil {
  149. return u
  150. }
  151. if v, found := p.p["nvpdeviceid"]; found {
  152. u.Set("nvpdeviceid", v.(string))
  153. }
  154. return u
  155. }
  156. func (p *DeleteNiciraNvpDeviceParams) SetNvpdeviceid(v string) {
  157. if p.p == nil {
  158. p.p = make(map[string]interface{})
  159. }
  160. p.p["nvpdeviceid"] = v
  161. return
  162. }
  163. // You should always use this function to get a new DeleteNiciraNvpDeviceParams instance,
  164. // as then you are sure you have configured all required params
  165. func (s *NiciraNVPService) NewDeleteNiciraNvpDeviceParams(nvpdeviceid string) *DeleteNiciraNvpDeviceParams {
  166. p := &DeleteNiciraNvpDeviceParams{}
  167. p.p = make(map[string]interface{})
  168. p.p["nvpdeviceid"] = nvpdeviceid
  169. return p
  170. }
  171. // delete a nicira nvp device
  172. func (s *NiciraNVPService) DeleteNiciraNvpDevice(p *DeleteNiciraNvpDeviceParams) (*DeleteNiciraNvpDeviceResponse, error) {
  173. resp, err := s.cs.newRequest("deleteNiciraNvpDevice", p.toURLValues())
  174. if err != nil {
  175. return nil, err
  176. }
  177. var r DeleteNiciraNvpDeviceResponse
  178. if err := json.Unmarshal(resp, &r); err != nil {
  179. return nil, err
  180. }
  181. // If we have a async client, we need to wait for the async result
  182. if s.cs.async {
  183. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  184. if err != nil {
  185. if err == AsyncTimeoutErr {
  186. return &r, err
  187. }
  188. return nil, err
  189. }
  190. if err := json.Unmarshal(b, &r); err != nil {
  191. return nil, err
  192. }
  193. }
  194. return &r, nil
  195. }
  196. type DeleteNiciraNvpDeviceResponse struct {
  197. JobID string `json:"jobid,omitempty"`
  198. Displaytext string `json:"displaytext,omitempty"`
  199. Success bool `json:"success,omitempty"`
  200. }
  201. type ListNiciraNvpDevicesParams struct {
  202. p map[string]interface{}
  203. }
  204. func (p *ListNiciraNvpDevicesParams) toURLValues() url.Values {
  205. u := url.Values{}
  206. if p.p == nil {
  207. return u
  208. }
  209. if v, found := p.p["keyword"]; found {
  210. u.Set("keyword", v.(string))
  211. }
  212. if v, found := p.p["nvpdeviceid"]; found {
  213. u.Set("nvpdeviceid", v.(string))
  214. }
  215. if v, found := p.p["page"]; found {
  216. vv := strconv.Itoa(v.(int))
  217. u.Set("page", vv)
  218. }
  219. if v, found := p.p["pagesize"]; found {
  220. vv := strconv.Itoa(v.(int))
  221. u.Set("pagesize", vv)
  222. }
  223. if v, found := p.p["physicalnetworkid"]; found {
  224. u.Set("physicalnetworkid", v.(string))
  225. }
  226. return u
  227. }
  228. func (p *ListNiciraNvpDevicesParams) SetKeyword(v string) {
  229. if p.p == nil {
  230. p.p = make(map[string]interface{})
  231. }
  232. p.p["keyword"] = v
  233. return
  234. }
  235. func (p *ListNiciraNvpDevicesParams) SetNvpdeviceid(v string) {
  236. if p.p == nil {
  237. p.p = make(map[string]interface{})
  238. }
  239. p.p["nvpdeviceid"] = v
  240. return
  241. }
  242. func (p *ListNiciraNvpDevicesParams) SetPage(v int) {
  243. if p.p == nil {
  244. p.p = make(map[string]interface{})
  245. }
  246. p.p["page"] = v
  247. return
  248. }
  249. func (p *ListNiciraNvpDevicesParams) SetPagesize(v int) {
  250. if p.p == nil {
  251. p.p = make(map[string]interface{})
  252. }
  253. p.p["pagesize"] = v
  254. return
  255. }
  256. func (p *ListNiciraNvpDevicesParams) SetPhysicalnetworkid(v string) {
  257. if p.p == nil {
  258. p.p = make(map[string]interface{})
  259. }
  260. p.p["physicalnetworkid"] = v
  261. return
  262. }
  263. // You should always use this function to get a new ListNiciraNvpDevicesParams instance,
  264. // as then you are sure you have configured all required params
  265. func (s *NiciraNVPService) NewListNiciraNvpDevicesParams() *ListNiciraNvpDevicesParams {
  266. p := &ListNiciraNvpDevicesParams{}
  267. p.p = make(map[string]interface{})
  268. return p
  269. }
  270. // Lists Nicira NVP devices
  271. func (s *NiciraNVPService) ListNiciraNvpDevices(p *ListNiciraNvpDevicesParams) (*ListNiciraNvpDevicesResponse, error) {
  272. resp, err := s.cs.newRequest("listNiciraNvpDevices", p.toURLValues())
  273. if err != nil {
  274. return nil, err
  275. }
  276. var r ListNiciraNvpDevicesResponse
  277. if err := json.Unmarshal(resp, &r); err != nil {
  278. return nil, err
  279. }
  280. return &r, nil
  281. }
  282. type ListNiciraNvpDevicesResponse struct {
  283. Count int `json:"count"`
  284. NiciraNvpDevices []*NiciraNvpDevice `json:"niciranvpdevice"`
  285. }
  286. type NiciraNvpDevice struct {
  287. Hostname string `json:"hostname,omitempty"`
  288. L3gatewayserviceuuid string `json:"l3gatewayserviceuuid,omitempty"`
  289. Niciradevicename string `json:"niciradevicename,omitempty"`
  290. Nvpdeviceid string `json:"nvpdeviceid,omitempty"`
  291. Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
  292. Provider string `json:"provider,omitempty"`
  293. Transportzoneuuid string `json:"transportzoneuuid,omitempty"`
  294. }