VLANService.go 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  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. "strings"
  23. )
  24. type CreateVlanIpRangeParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *CreateVlanIpRangeParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["account"]; found {
  33. u.Set("account", v.(string))
  34. }
  35. if v, found := p.p["domainid"]; found {
  36. u.Set("domainid", v.(string))
  37. }
  38. if v, found := p.p["endip"]; found {
  39. u.Set("endip", v.(string))
  40. }
  41. if v, found := p.p["endipv6"]; found {
  42. u.Set("endipv6", v.(string))
  43. }
  44. if v, found := p.p["forvirtualnetwork"]; found {
  45. vv := strconv.FormatBool(v.(bool))
  46. u.Set("forvirtualnetwork", vv)
  47. }
  48. if v, found := p.p["gateway"]; found {
  49. u.Set("gateway", v.(string))
  50. }
  51. if v, found := p.p["ip6cidr"]; found {
  52. u.Set("ip6cidr", v.(string))
  53. }
  54. if v, found := p.p["ip6gateway"]; found {
  55. u.Set("ip6gateway", v.(string))
  56. }
  57. if v, found := p.p["netmask"]; found {
  58. u.Set("netmask", v.(string))
  59. }
  60. if v, found := p.p["networkid"]; found {
  61. u.Set("networkid", v.(string))
  62. }
  63. if v, found := p.p["physicalnetworkid"]; found {
  64. u.Set("physicalnetworkid", v.(string))
  65. }
  66. if v, found := p.p["podid"]; found {
  67. u.Set("podid", v.(string))
  68. }
  69. if v, found := p.p["projectid"]; found {
  70. u.Set("projectid", v.(string))
  71. }
  72. if v, found := p.p["startip"]; found {
  73. u.Set("startip", v.(string))
  74. }
  75. if v, found := p.p["startipv6"]; found {
  76. u.Set("startipv6", v.(string))
  77. }
  78. if v, found := p.p["vlan"]; found {
  79. u.Set("vlan", v.(string))
  80. }
  81. if v, found := p.p["zoneid"]; found {
  82. u.Set("zoneid", v.(string))
  83. }
  84. return u
  85. }
  86. func (p *CreateVlanIpRangeParams) SetAccount(v string) {
  87. if p.p == nil {
  88. p.p = make(map[string]interface{})
  89. }
  90. p.p["account"] = v
  91. return
  92. }
  93. func (p *CreateVlanIpRangeParams) SetDomainid(v string) {
  94. if p.p == nil {
  95. p.p = make(map[string]interface{})
  96. }
  97. p.p["domainid"] = v
  98. return
  99. }
  100. func (p *CreateVlanIpRangeParams) SetEndip(v string) {
  101. if p.p == nil {
  102. p.p = make(map[string]interface{})
  103. }
  104. p.p["endip"] = v
  105. return
  106. }
  107. func (p *CreateVlanIpRangeParams) SetEndipv6(v string) {
  108. if p.p == nil {
  109. p.p = make(map[string]interface{})
  110. }
  111. p.p["endipv6"] = v
  112. return
  113. }
  114. func (p *CreateVlanIpRangeParams) SetForvirtualnetwork(v bool) {
  115. if p.p == nil {
  116. p.p = make(map[string]interface{})
  117. }
  118. p.p["forvirtualnetwork"] = v
  119. return
  120. }
  121. func (p *CreateVlanIpRangeParams) SetGateway(v string) {
  122. if p.p == nil {
  123. p.p = make(map[string]interface{})
  124. }
  125. p.p["gateway"] = v
  126. return
  127. }
  128. func (p *CreateVlanIpRangeParams) SetIp6cidr(v string) {
  129. if p.p == nil {
  130. p.p = make(map[string]interface{})
  131. }
  132. p.p["ip6cidr"] = v
  133. return
  134. }
  135. func (p *CreateVlanIpRangeParams) SetIp6gateway(v string) {
  136. if p.p == nil {
  137. p.p = make(map[string]interface{})
  138. }
  139. p.p["ip6gateway"] = v
  140. return
  141. }
  142. func (p *CreateVlanIpRangeParams) SetNetmask(v string) {
  143. if p.p == nil {
  144. p.p = make(map[string]interface{})
  145. }
  146. p.p["netmask"] = v
  147. return
  148. }
  149. func (p *CreateVlanIpRangeParams) SetNetworkid(v string) {
  150. if p.p == nil {
  151. p.p = make(map[string]interface{})
  152. }
  153. p.p["networkid"] = v
  154. return
  155. }
  156. func (p *CreateVlanIpRangeParams) SetPhysicalnetworkid(v string) {
  157. if p.p == nil {
  158. p.p = make(map[string]interface{})
  159. }
  160. p.p["physicalnetworkid"] = v
  161. return
  162. }
  163. func (p *CreateVlanIpRangeParams) SetPodid(v string) {
  164. if p.p == nil {
  165. p.p = make(map[string]interface{})
  166. }
  167. p.p["podid"] = v
  168. return
  169. }
  170. func (p *CreateVlanIpRangeParams) SetProjectid(v string) {
  171. if p.p == nil {
  172. p.p = make(map[string]interface{})
  173. }
  174. p.p["projectid"] = v
  175. return
  176. }
  177. func (p *CreateVlanIpRangeParams) SetStartip(v string) {
  178. if p.p == nil {
  179. p.p = make(map[string]interface{})
  180. }
  181. p.p["startip"] = v
  182. return
  183. }
  184. func (p *CreateVlanIpRangeParams) SetStartipv6(v string) {
  185. if p.p == nil {
  186. p.p = make(map[string]interface{})
  187. }
  188. p.p["startipv6"] = v
  189. return
  190. }
  191. func (p *CreateVlanIpRangeParams) SetVlan(v string) {
  192. if p.p == nil {
  193. p.p = make(map[string]interface{})
  194. }
  195. p.p["vlan"] = v
  196. return
  197. }
  198. func (p *CreateVlanIpRangeParams) SetZoneid(v string) {
  199. if p.p == nil {
  200. p.p = make(map[string]interface{})
  201. }
  202. p.p["zoneid"] = v
  203. return
  204. }
  205. // You should always use this function to get a new CreateVlanIpRangeParams instance,
  206. // as then you are sure you have configured all required params
  207. func (s *VLANService) NewCreateVlanIpRangeParams() *CreateVlanIpRangeParams {
  208. p := &CreateVlanIpRangeParams{}
  209. p.p = make(map[string]interface{})
  210. return p
  211. }
  212. // Creates a VLAN IP range.
  213. func (s *VLANService) CreateVlanIpRange(p *CreateVlanIpRangeParams) (*CreateVlanIpRangeResponse, error) {
  214. resp, err := s.cs.newRequest("createVlanIpRange", p.toURLValues())
  215. if err != nil {
  216. return nil, err
  217. }
  218. var r CreateVlanIpRangeResponse
  219. if err := json.Unmarshal(resp, &r); err != nil {
  220. return nil, err
  221. }
  222. return &r, nil
  223. }
  224. type CreateVlanIpRangeResponse struct {
  225. Account string `json:"account,omitempty"`
  226. Description string `json:"description,omitempty"`
  227. Domain string `json:"domain,omitempty"`
  228. Domainid string `json:"domainid,omitempty"`
  229. Endip string `json:"endip,omitempty"`
  230. Endipv6 string `json:"endipv6,omitempty"`
  231. Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
  232. Gateway string `json:"gateway,omitempty"`
  233. Id string `json:"id,omitempty"`
  234. Ip6cidr string `json:"ip6cidr,omitempty"`
  235. Ip6gateway string `json:"ip6gateway,omitempty"`
  236. Netmask string `json:"netmask,omitempty"`
  237. Networkid string `json:"networkid,omitempty"`
  238. Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
  239. Podid string `json:"podid,omitempty"`
  240. Podname string `json:"podname,omitempty"`
  241. Project string `json:"project,omitempty"`
  242. Projectid string `json:"projectid,omitempty"`
  243. Startip string `json:"startip,omitempty"`
  244. Startipv6 string `json:"startipv6,omitempty"`
  245. Vlan string `json:"vlan,omitempty"`
  246. Zoneid string `json:"zoneid,omitempty"`
  247. }
  248. type DeleteVlanIpRangeParams struct {
  249. p map[string]interface{}
  250. }
  251. func (p *DeleteVlanIpRangeParams) toURLValues() url.Values {
  252. u := url.Values{}
  253. if p.p == nil {
  254. return u
  255. }
  256. if v, found := p.p["id"]; found {
  257. u.Set("id", v.(string))
  258. }
  259. return u
  260. }
  261. func (p *DeleteVlanIpRangeParams) SetId(v string) {
  262. if p.p == nil {
  263. p.p = make(map[string]interface{})
  264. }
  265. p.p["id"] = v
  266. return
  267. }
  268. // You should always use this function to get a new DeleteVlanIpRangeParams instance,
  269. // as then you are sure you have configured all required params
  270. func (s *VLANService) NewDeleteVlanIpRangeParams(id string) *DeleteVlanIpRangeParams {
  271. p := &DeleteVlanIpRangeParams{}
  272. p.p = make(map[string]interface{})
  273. p.p["id"] = id
  274. return p
  275. }
  276. // Creates a VLAN IP range.
  277. func (s *VLANService) DeleteVlanIpRange(p *DeleteVlanIpRangeParams) (*DeleteVlanIpRangeResponse, error) {
  278. resp, err := s.cs.newRequest("deleteVlanIpRange", p.toURLValues())
  279. if err != nil {
  280. return nil, err
  281. }
  282. var r DeleteVlanIpRangeResponse
  283. if err := json.Unmarshal(resp, &r); err != nil {
  284. return nil, err
  285. }
  286. return &r, nil
  287. }
  288. type DeleteVlanIpRangeResponse struct {
  289. Displaytext string `json:"displaytext,omitempty"`
  290. Success string `json:"success,omitempty"`
  291. }
  292. type ListVlanIpRangesParams struct {
  293. p map[string]interface{}
  294. }
  295. func (p *ListVlanIpRangesParams) toURLValues() url.Values {
  296. u := url.Values{}
  297. if p.p == nil {
  298. return u
  299. }
  300. if v, found := p.p["account"]; found {
  301. u.Set("account", v.(string))
  302. }
  303. if v, found := p.p["domainid"]; found {
  304. u.Set("domainid", v.(string))
  305. }
  306. if v, found := p.p["forvirtualnetwork"]; found {
  307. vv := strconv.FormatBool(v.(bool))
  308. u.Set("forvirtualnetwork", vv)
  309. }
  310. if v, found := p.p["id"]; found {
  311. u.Set("id", v.(string))
  312. }
  313. if v, found := p.p["keyword"]; found {
  314. u.Set("keyword", v.(string))
  315. }
  316. if v, found := p.p["networkid"]; found {
  317. u.Set("networkid", v.(string))
  318. }
  319. if v, found := p.p["page"]; found {
  320. vv := strconv.Itoa(v.(int))
  321. u.Set("page", vv)
  322. }
  323. if v, found := p.p["pagesize"]; found {
  324. vv := strconv.Itoa(v.(int))
  325. u.Set("pagesize", vv)
  326. }
  327. if v, found := p.p["physicalnetworkid"]; found {
  328. u.Set("physicalnetworkid", v.(string))
  329. }
  330. if v, found := p.p["podid"]; found {
  331. u.Set("podid", v.(string))
  332. }
  333. if v, found := p.p["projectid"]; found {
  334. u.Set("projectid", v.(string))
  335. }
  336. if v, found := p.p["vlan"]; found {
  337. u.Set("vlan", v.(string))
  338. }
  339. if v, found := p.p["zoneid"]; found {
  340. u.Set("zoneid", v.(string))
  341. }
  342. return u
  343. }
  344. func (p *ListVlanIpRangesParams) SetAccount(v string) {
  345. if p.p == nil {
  346. p.p = make(map[string]interface{})
  347. }
  348. p.p["account"] = v
  349. return
  350. }
  351. func (p *ListVlanIpRangesParams) SetDomainid(v string) {
  352. if p.p == nil {
  353. p.p = make(map[string]interface{})
  354. }
  355. p.p["domainid"] = v
  356. return
  357. }
  358. func (p *ListVlanIpRangesParams) SetForvirtualnetwork(v bool) {
  359. if p.p == nil {
  360. p.p = make(map[string]interface{})
  361. }
  362. p.p["forvirtualnetwork"] = v
  363. return
  364. }
  365. func (p *ListVlanIpRangesParams) SetId(v string) {
  366. if p.p == nil {
  367. p.p = make(map[string]interface{})
  368. }
  369. p.p["id"] = v
  370. return
  371. }
  372. func (p *ListVlanIpRangesParams) SetKeyword(v string) {
  373. if p.p == nil {
  374. p.p = make(map[string]interface{})
  375. }
  376. p.p["keyword"] = v
  377. return
  378. }
  379. func (p *ListVlanIpRangesParams) SetNetworkid(v string) {
  380. if p.p == nil {
  381. p.p = make(map[string]interface{})
  382. }
  383. p.p["networkid"] = v
  384. return
  385. }
  386. func (p *ListVlanIpRangesParams) SetPage(v int) {
  387. if p.p == nil {
  388. p.p = make(map[string]interface{})
  389. }
  390. p.p["page"] = v
  391. return
  392. }
  393. func (p *ListVlanIpRangesParams) SetPagesize(v int) {
  394. if p.p == nil {
  395. p.p = make(map[string]interface{})
  396. }
  397. p.p["pagesize"] = v
  398. return
  399. }
  400. func (p *ListVlanIpRangesParams) SetPhysicalnetworkid(v string) {
  401. if p.p == nil {
  402. p.p = make(map[string]interface{})
  403. }
  404. p.p["physicalnetworkid"] = v
  405. return
  406. }
  407. func (p *ListVlanIpRangesParams) SetPodid(v string) {
  408. if p.p == nil {
  409. p.p = make(map[string]interface{})
  410. }
  411. p.p["podid"] = v
  412. return
  413. }
  414. func (p *ListVlanIpRangesParams) SetProjectid(v string) {
  415. if p.p == nil {
  416. p.p = make(map[string]interface{})
  417. }
  418. p.p["projectid"] = v
  419. return
  420. }
  421. func (p *ListVlanIpRangesParams) SetVlan(v string) {
  422. if p.p == nil {
  423. p.p = make(map[string]interface{})
  424. }
  425. p.p["vlan"] = v
  426. return
  427. }
  428. func (p *ListVlanIpRangesParams) SetZoneid(v string) {
  429. if p.p == nil {
  430. p.p = make(map[string]interface{})
  431. }
  432. p.p["zoneid"] = v
  433. return
  434. }
  435. // You should always use this function to get a new ListVlanIpRangesParams instance,
  436. // as then you are sure you have configured all required params
  437. func (s *VLANService) NewListVlanIpRangesParams() *ListVlanIpRangesParams {
  438. p := &ListVlanIpRangesParams{}
  439. p.p = make(map[string]interface{})
  440. return p
  441. }
  442. // This is a courtesy helper function, which in some cases may not work as expected!
  443. func (s *VLANService) GetVlanIpRangeByID(id string, opts ...OptionFunc) (*VlanIpRange, int, error) {
  444. p := &ListVlanIpRangesParams{}
  445. p.p = make(map[string]interface{})
  446. p.p["id"] = id
  447. for _, fn := range opts {
  448. if err := fn(s.cs, p); err != nil {
  449. return nil, -1, err
  450. }
  451. }
  452. l, err := s.ListVlanIpRanges(p)
  453. if err != nil {
  454. if strings.Contains(err.Error(), fmt.Sprintf(
  455. "Invalid parameter id value=%s due to incorrect long value format, "+
  456. "or entity does not exist", id)) {
  457. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  458. }
  459. return nil, -1, err
  460. }
  461. if l.Count == 0 {
  462. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  463. }
  464. if l.Count == 1 {
  465. return l.VlanIpRanges[0], l.Count, nil
  466. }
  467. return nil, l.Count, fmt.Errorf("There is more then one result for VlanIpRange UUID: %s!", id)
  468. }
  469. // Lists all VLAN IP ranges.
  470. func (s *VLANService) ListVlanIpRanges(p *ListVlanIpRangesParams) (*ListVlanIpRangesResponse, error) {
  471. resp, err := s.cs.newRequest("listVlanIpRanges", p.toURLValues())
  472. if err != nil {
  473. return nil, err
  474. }
  475. var r ListVlanIpRangesResponse
  476. if err := json.Unmarshal(resp, &r); err != nil {
  477. return nil, err
  478. }
  479. return &r, nil
  480. }
  481. type ListVlanIpRangesResponse struct {
  482. Count int `json:"count"`
  483. VlanIpRanges []*VlanIpRange `json:"vlaniprange"`
  484. }
  485. type VlanIpRange struct {
  486. Account string `json:"account,omitempty"`
  487. Description string `json:"description,omitempty"`
  488. Domain string `json:"domain,omitempty"`
  489. Domainid string `json:"domainid,omitempty"`
  490. Endip string `json:"endip,omitempty"`
  491. Endipv6 string `json:"endipv6,omitempty"`
  492. Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
  493. Gateway string `json:"gateway,omitempty"`
  494. Id string `json:"id,omitempty"`
  495. Ip6cidr string `json:"ip6cidr,omitempty"`
  496. Ip6gateway string `json:"ip6gateway,omitempty"`
  497. Netmask string `json:"netmask,omitempty"`
  498. Networkid string `json:"networkid,omitempty"`
  499. Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
  500. Podid string `json:"podid,omitempty"`
  501. Podname string `json:"podname,omitempty"`
  502. Project string `json:"project,omitempty"`
  503. Projectid string `json:"projectid,omitempty"`
  504. Startip string `json:"startip,omitempty"`
  505. Startipv6 string `json:"startipv6,omitempty"`
  506. Vlan string `json:"vlan,omitempty"`
  507. Zoneid string `json:"zoneid,omitempty"`
  508. }
  509. type DedicateGuestVlanRangeParams struct {
  510. p map[string]interface{}
  511. }
  512. func (p *DedicateGuestVlanRangeParams) toURLValues() url.Values {
  513. u := url.Values{}
  514. if p.p == nil {
  515. return u
  516. }
  517. if v, found := p.p["account"]; found {
  518. u.Set("account", v.(string))
  519. }
  520. if v, found := p.p["domainid"]; found {
  521. u.Set("domainid", v.(string))
  522. }
  523. if v, found := p.p["physicalnetworkid"]; found {
  524. u.Set("physicalnetworkid", v.(string))
  525. }
  526. if v, found := p.p["projectid"]; found {
  527. u.Set("projectid", v.(string))
  528. }
  529. if v, found := p.p["vlanrange"]; found {
  530. u.Set("vlanrange", v.(string))
  531. }
  532. return u
  533. }
  534. func (p *DedicateGuestVlanRangeParams) SetAccount(v string) {
  535. if p.p == nil {
  536. p.p = make(map[string]interface{})
  537. }
  538. p.p["account"] = v
  539. return
  540. }
  541. func (p *DedicateGuestVlanRangeParams) SetDomainid(v string) {
  542. if p.p == nil {
  543. p.p = make(map[string]interface{})
  544. }
  545. p.p["domainid"] = v
  546. return
  547. }
  548. func (p *DedicateGuestVlanRangeParams) SetPhysicalnetworkid(v string) {
  549. if p.p == nil {
  550. p.p = make(map[string]interface{})
  551. }
  552. p.p["physicalnetworkid"] = v
  553. return
  554. }
  555. func (p *DedicateGuestVlanRangeParams) SetProjectid(v string) {
  556. if p.p == nil {
  557. p.p = make(map[string]interface{})
  558. }
  559. p.p["projectid"] = v
  560. return
  561. }
  562. func (p *DedicateGuestVlanRangeParams) SetVlanrange(v string) {
  563. if p.p == nil {
  564. p.p = make(map[string]interface{})
  565. }
  566. p.p["vlanrange"] = v
  567. return
  568. }
  569. // You should always use this function to get a new DedicateGuestVlanRangeParams instance,
  570. // as then you are sure you have configured all required params
  571. func (s *VLANService) NewDedicateGuestVlanRangeParams(account string, domainid string, physicalnetworkid string, vlanrange string) *DedicateGuestVlanRangeParams {
  572. p := &DedicateGuestVlanRangeParams{}
  573. p.p = make(map[string]interface{})
  574. p.p["account"] = account
  575. p.p["domainid"] = domainid
  576. p.p["physicalnetworkid"] = physicalnetworkid
  577. p.p["vlanrange"] = vlanrange
  578. return p
  579. }
  580. // Dedicates a guest vlan range to an account
  581. func (s *VLANService) DedicateGuestVlanRange(p *DedicateGuestVlanRangeParams) (*DedicateGuestVlanRangeResponse, error) {
  582. resp, err := s.cs.newRequest("dedicateGuestVlanRange", p.toURLValues())
  583. if err != nil {
  584. return nil, err
  585. }
  586. var r DedicateGuestVlanRangeResponse
  587. if err := json.Unmarshal(resp, &r); err != nil {
  588. return nil, err
  589. }
  590. return &r, nil
  591. }
  592. type DedicateGuestVlanRangeResponse struct {
  593. Account string `json:"account,omitempty"`
  594. Domain string `json:"domain,omitempty"`
  595. Domainid string `json:"domainid,omitempty"`
  596. Guestvlanrange string `json:"guestvlanrange,omitempty"`
  597. Id string `json:"id,omitempty"`
  598. Physicalnetworkid int64 `json:"physicalnetworkid,omitempty"`
  599. Project string `json:"project,omitempty"`
  600. Projectid string `json:"projectid,omitempty"`
  601. Zoneid int64 `json:"zoneid,omitempty"`
  602. }
  603. type ReleaseDedicatedGuestVlanRangeParams struct {
  604. p map[string]interface{}
  605. }
  606. func (p *ReleaseDedicatedGuestVlanRangeParams) toURLValues() url.Values {
  607. u := url.Values{}
  608. if p.p == nil {
  609. return u
  610. }
  611. if v, found := p.p["id"]; found {
  612. u.Set("id", v.(string))
  613. }
  614. return u
  615. }
  616. func (p *ReleaseDedicatedGuestVlanRangeParams) SetId(v string) {
  617. if p.p == nil {
  618. p.p = make(map[string]interface{})
  619. }
  620. p.p["id"] = v
  621. return
  622. }
  623. // You should always use this function to get a new ReleaseDedicatedGuestVlanRangeParams instance,
  624. // as then you are sure you have configured all required params
  625. func (s *VLANService) NewReleaseDedicatedGuestVlanRangeParams(id string) *ReleaseDedicatedGuestVlanRangeParams {
  626. p := &ReleaseDedicatedGuestVlanRangeParams{}
  627. p.p = make(map[string]interface{})
  628. p.p["id"] = id
  629. return p
  630. }
  631. // Releases a dedicated guest vlan range to the system
  632. func (s *VLANService) ReleaseDedicatedGuestVlanRange(p *ReleaseDedicatedGuestVlanRangeParams) (*ReleaseDedicatedGuestVlanRangeResponse, error) {
  633. resp, err := s.cs.newRequest("releaseDedicatedGuestVlanRange", p.toURLValues())
  634. if err != nil {
  635. return nil, err
  636. }
  637. var r ReleaseDedicatedGuestVlanRangeResponse
  638. if err := json.Unmarshal(resp, &r); err != nil {
  639. return nil, err
  640. }
  641. // If we have a async client, we need to wait for the async result
  642. if s.cs.async {
  643. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  644. if err != nil {
  645. if err == AsyncTimeoutErr {
  646. return &r, err
  647. }
  648. return nil, err
  649. }
  650. if err := json.Unmarshal(b, &r); err != nil {
  651. return nil, err
  652. }
  653. }
  654. return &r, nil
  655. }
  656. type ReleaseDedicatedGuestVlanRangeResponse struct {
  657. JobID string `json:"jobid,omitempty"`
  658. Displaytext string `json:"displaytext,omitempty"`
  659. Success bool `json:"success,omitempty"`
  660. }
  661. type ListDedicatedGuestVlanRangesParams struct {
  662. p map[string]interface{}
  663. }
  664. func (p *ListDedicatedGuestVlanRangesParams) toURLValues() url.Values {
  665. u := url.Values{}
  666. if p.p == nil {
  667. return u
  668. }
  669. if v, found := p.p["account"]; found {
  670. u.Set("account", v.(string))
  671. }
  672. if v, found := p.p["domainid"]; found {
  673. u.Set("domainid", v.(string))
  674. }
  675. if v, found := p.p["guestvlanrange"]; found {
  676. u.Set("guestvlanrange", v.(string))
  677. }
  678. if v, found := p.p["id"]; found {
  679. u.Set("id", v.(string))
  680. }
  681. if v, found := p.p["keyword"]; found {
  682. u.Set("keyword", v.(string))
  683. }
  684. if v, found := p.p["page"]; found {
  685. vv := strconv.Itoa(v.(int))
  686. u.Set("page", vv)
  687. }
  688. if v, found := p.p["pagesize"]; found {
  689. vv := strconv.Itoa(v.(int))
  690. u.Set("pagesize", vv)
  691. }
  692. if v, found := p.p["physicalnetworkid"]; found {
  693. u.Set("physicalnetworkid", v.(string))
  694. }
  695. if v, found := p.p["projectid"]; found {
  696. u.Set("projectid", v.(string))
  697. }
  698. if v, found := p.p["zoneid"]; found {
  699. u.Set("zoneid", v.(string))
  700. }
  701. return u
  702. }
  703. func (p *ListDedicatedGuestVlanRangesParams) SetAccount(v string) {
  704. if p.p == nil {
  705. p.p = make(map[string]interface{})
  706. }
  707. p.p["account"] = v
  708. return
  709. }
  710. func (p *ListDedicatedGuestVlanRangesParams) SetDomainid(v string) {
  711. if p.p == nil {
  712. p.p = make(map[string]interface{})
  713. }
  714. p.p["domainid"] = v
  715. return
  716. }
  717. func (p *ListDedicatedGuestVlanRangesParams) SetGuestvlanrange(v string) {
  718. if p.p == nil {
  719. p.p = make(map[string]interface{})
  720. }
  721. p.p["guestvlanrange"] = v
  722. return
  723. }
  724. func (p *ListDedicatedGuestVlanRangesParams) SetId(v string) {
  725. if p.p == nil {
  726. p.p = make(map[string]interface{})
  727. }
  728. p.p["id"] = v
  729. return
  730. }
  731. func (p *ListDedicatedGuestVlanRangesParams) SetKeyword(v string) {
  732. if p.p == nil {
  733. p.p = make(map[string]interface{})
  734. }
  735. p.p["keyword"] = v
  736. return
  737. }
  738. func (p *ListDedicatedGuestVlanRangesParams) SetPage(v int) {
  739. if p.p == nil {
  740. p.p = make(map[string]interface{})
  741. }
  742. p.p["page"] = v
  743. return
  744. }
  745. func (p *ListDedicatedGuestVlanRangesParams) SetPagesize(v int) {
  746. if p.p == nil {
  747. p.p = make(map[string]interface{})
  748. }
  749. p.p["pagesize"] = v
  750. return
  751. }
  752. func (p *ListDedicatedGuestVlanRangesParams) SetPhysicalnetworkid(v string) {
  753. if p.p == nil {
  754. p.p = make(map[string]interface{})
  755. }
  756. p.p["physicalnetworkid"] = v
  757. return
  758. }
  759. func (p *ListDedicatedGuestVlanRangesParams) SetProjectid(v string) {
  760. if p.p == nil {
  761. p.p = make(map[string]interface{})
  762. }
  763. p.p["projectid"] = v
  764. return
  765. }
  766. func (p *ListDedicatedGuestVlanRangesParams) SetZoneid(v string) {
  767. if p.p == nil {
  768. p.p = make(map[string]interface{})
  769. }
  770. p.p["zoneid"] = v
  771. return
  772. }
  773. // You should always use this function to get a new ListDedicatedGuestVlanRangesParams instance,
  774. // as then you are sure you have configured all required params
  775. func (s *VLANService) NewListDedicatedGuestVlanRangesParams() *ListDedicatedGuestVlanRangesParams {
  776. p := &ListDedicatedGuestVlanRangesParams{}
  777. p.p = make(map[string]interface{})
  778. return p
  779. }
  780. // This is a courtesy helper function, which in some cases may not work as expected!
  781. func (s *VLANService) GetDedicatedGuestVlanRangeByID(id string, opts ...OptionFunc) (*DedicatedGuestVlanRange, int, error) {
  782. p := &ListDedicatedGuestVlanRangesParams{}
  783. p.p = make(map[string]interface{})
  784. p.p["id"] = id
  785. for _, fn := range opts {
  786. if err := fn(s.cs, p); err != nil {
  787. return nil, -1, err
  788. }
  789. }
  790. l, err := s.ListDedicatedGuestVlanRanges(p)
  791. if err != nil {
  792. if strings.Contains(err.Error(), fmt.Sprintf(
  793. "Invalid parameter id value=%s due to incorrect long value format, "+
  794. "or entity does not exist", id)) {
  795. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  796. }
  797. return nil, -1, err
  798. }
  799. if l.Count == 0 {
  800. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  801. }
  802. if l.Count == 1 {
  803. return l.DedicatedGuestVlanRanges[0], l.Count, nil
  804. }
  805. return nil, l.Count, fmt.Errorf("There is more then one result for DedicatedGuestVlanRange UUID: %s!", id)
  806. }
  807. // Lists dedicated guest vlan ranges
  808. func (s *VLANService) ListDedicatedGuestVlanRanges(p *ListDedicatedGuestVlanRangesParams) (*ListDedicatedGuestVlanRangesResponse, error) {
  809. resp, err := s.cs.newRequest("listDedicatedGuestVlanRanges", p.toURLValues())
  810. if err != nil {
  811. return nil, err
  812. }
  813. var r ListDedicatedGuestVlanRangesResponse
  814. if err := json.Unmarshal(resp, &r); err != nil {
  815. return nil, err
  816. }
  817. return &r, nil
  818. }
  819. type ListDedicatedGuestVlanRangesResponse struct {
  820. Count int `json:"count"`
  821. DedicatedGuestVlanRanges []*DedicatedGuestVlanRange `json:"dedicatedguestvlanrange"`
  822. }
  823. type DedicatedGuestVlanRange struct {
  824. Account string `json:"account,omitempty"`
  825. Domain string `json:"domain,omitempty"`
  826. Domainid string `json:"domainid,omitempty"`
  827. Guestvlanrange string `json:"guestvlanrange,omitempty"`
  828. Id string `json:"id,omitempty"`
  829. Physicalnetworkid int64 `json:"physicalnetworkid,omitempty"`
  830. Project string `json:"project,omitempty"`
  831. Projectid string `json:"projectid,omitempty"`
  832. Zoneid int64 `json:"zoneid,omitempty"`
  833. }