NetworkDeviceService.go 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. "fmt"
  20. "net/url"
  21. "strconv"
  22. )
  23. type AddNetworkDeviceParams struct {
  24. p map[string]interface{}
  25. }
  26. func (p *AddNetworkDeviceParams) toURLValues() url.Values {
  27. u := url.Values{}
  28. if p.p == nil {
  29. return u
  30. }
  31. if v, found := p.p["networkdeviceparameterlist"]; found {
  32. i := 0
  33. for k, vv := range v.(map[string]string) {
  34. u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].key", i), k)
  35. u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].value", i), vv)
  36. i++
  37. }
  38. }
  39. if v, found := p.p["networkdevicetype"]; found {
  40. u.Set("networkdevicetype", v.(string))
  41. }
  42. return u
  43. }
  44. func (p *AddNetworkDeviceParams) SetNetworkdeviceparameterlist(v map[string]string) {
  45. if p.p == nil {
  46. p.p = make(map[string]interface{})
  47. }
  48. p.p["networkdeviceparameterlist"] = v
  49. return
  50. }
  51. func (p *AddNetworkDeviceParams) SetNetworkdevicetype(v string) {
  52. if p.p == nil {
  53. p.p = make(map[string]interface{})
  54. }
  55. p.p["networkdevicetype"] = v
  56. return
  57. }
  58. // You should always use this function to get a new AddNetworkDeviceParams instance,
  59. // as then you are sure you have configured all required params
  60. func (s *NetworkDeviceService) NewAddNetworkDeviceParams() *AddNetworkDeviceParams {
  61. p := &AddNetworkDeviceParams{}
  62. p.p = make(map[string]interface{})
  63. return p
  64. }
  65. // Adds a network device of one of the following types: ExternalDhcp, ExternalFirewall, ExternalLoadBalancer, PxeServer
  66. func (s *NetworkDeviceService) AddNetworkDevice(p *AddNetworkDeviceParams) (*AddNetworkDeviceResponse, error) {
  67. resp, err := s.cs.newRequest("addNetworkDevice", p.toURLValues())
  68. if err != nil {
  69. return nil, err
  70. }
  71. var r AddNetworkDeviceResponse
  72. if err := json.Unmarshal(resp, &r); err != nil {
  73. return nil, err
  74. }
  75. return &r, nil
  76. }
  77. type AddNetworkDeviceResponse struct {
  78. Id string `json:"id,omitempty"`
  79. }
  80. type ListNetworkDeviceParams struct {
  81. p map[string]interface{}
  82. }
  83. func (p *ListNetworkDeviceParams) toURLValues() url.Values {
  84. u := url.Values{}
  85. if p.p == nil {
  86. return u
  87. }
  88. if v, found := p.p["keyword"]; found {
  89. u.Set("keyword", v.(string))
  90. }
  91. if v, found := p.p["networkdeviceparameterlist"]; found {
  92. i := 0
  93. for k, vv := range v.(map[string]string) {
  94. u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].key", i), k)
  95. u.Set(fmt.Sprintf("networkdeviceparameterlist[%d].value", i), vv)
  96. i++
  97. }
  98. }
  99. if v, found := p.p["networkdevicetype"]; found {
  100. u.Set("networkdevicetype", v.(string))
  101. }
  102. if v, found := p.p["page"]; found {
  103. vv := strconv.Itoa(v.(int))
  104. u.Set("page", vv)
  105. }
  106. if v, found := p.p["pagesize"]; found {
  107. vv := strconv.Itoa(v.(int))
  108. u.Set("pagesize", vv)
  109. }
  110. return u
  111. }
  112. func (p *ListNetworkDeviceParams) SetKeyword(v string) {
  113. if p.p == nil {
  114. p.p = make(map[string]interface{})
  115. }
  116. p.p["keyword"] = v
  117. return
  118. }
  119. func (p *ListNetworkDeviceParams) SetNetworkdeviceparameterlist(v map[string]string) {
  120. if p.p == nil {
  121. p.p = make(map[string]interface{})
  122. }
  123. p.p["networkdeviceparameterlist"] = v
  124. return
  125. }
  126. func (p *ListNetworkDeviceParams) SetNetworkdevicetype(v string) {
  127. if p.p == nil {
  128. p.p = make(map[string]interface{})
  129. }
  130. p.p["networkdevicetype"] = v
  131. return
  132. }
  133. func (p *ListNetworkDeviceParams) SetPage(v int) {
  134. if p.p == nil {
  135. p.p = make(map[string]interface{})
  136. }
  137. p.p["page"] = v
  138. return
  139. }
  140. func (p *ListNetworkDeviceParams) SetPagesize(v int) {
  141. if p.p == nil {
  142. p.p = make(map[string]interface{})
  143. }
  144. p.p["pagesize"] = v
  145. return
  146. }
  147. // You should always use this function to get a new ListNetworkDeviceParams instance,
  148. // as then you are sure you have configured all required params
  149. func (s *NetworkDeviceService) NewListNetworkDeviceParams() *ListNetworkDeviceParams {
  150. p := &ListNetworkDeviceParams{}
  151. p.p = make(map[string]interface{})
  152. return p
  153. }
  154. // List network devices
  155. func (s *NetworkDeviceService) ListNetworkDevice(p *ListNetworkDeviceParams) (*ListNetworkDeviceResponse, error) {
  156. resp, err := s.cs.newRequest("listNetworkDevice", p.toURLValues())
  157. if err != nil {
  158. return nil, err
  159. }
  160. var r ListNetworkDeviceResponse
  161. if err := json.Unmarshal(resp, &r); err != nil {
  162. return nil, err
  163. }
  164. return &r, nil
  165. }
  166. type ListNetworkDeviceResponse struct {
  167. Count int `json:"count"`
  168. NetworkDevice []*NetworkDevice `json:"networkdevice"`
  169. }
  170. type NetworkDevice struct {
  171. Id string `json:"id,omitempty"`
  172. }
  173. type DeleteNetworkDeviceParams struct {
  174. p map[string]interface{}
  175. }
  176. func (p *DeleteNetworkDeviceParams) toURLValues() url.Values {
  177. u := url.Values{}
  178. if p.p == nil {
  179. return u
  180. }
  181. if v, found := p.p["id"]; found {
  182. u.Set("id", v.(string))
  183. }
  184. return u
  185. }
  186. func (p *DeleteNetworkDeviceParams) SetId(v string) {
  187. if p.p == nil {
  188. p.p = make(map[string]interface{})
  189. }
  190. p.p["id"] = v
  191. return
  192. }
  193. // You should always use this function to get a new DeleteNetworkDeviceParams instance,
  194. // as then you are sure you have configured all required params
  195. func (s *NetworkDeviceService) NewDeleteNetworkDeviceParams(id string) *DeleteNetworkDeviceParams {
  196. p := &DeleteNetworkDeviceParams{}
  197. p.p = make(map[string]interface{})
  198. p.p["id"] = id
  199. return p
  200. }
  201. // Deletes network device.
  202. func (s *NetworkDeviceService) DeleteNetworkDevice(p *DeleteNetworkDeviceParams) (*DeleteNetworkDeviceResponse, error) {
  203. resp, err := s.cs.newRequest("deleteNetworkDevice", p.toURLValues())
  204. if err != nil {
  205. return nil, err
  206. }
  207. var r DeleteNetworkDeviceResponse
  208. if err := json.Unmarshal(resp, &r); err != nil {
  209. return nil, err
  210. }
  211. return &r, nil
  212. }
  213. type DeleteNetworkDeviceResponse struct {
  214. Displaytext string `json:"displaytext,omitempty"`
  215. Success string `json:"success,omitempty"`
  216. }