AddressService.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  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 AssociateIpAddressParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *AssociateIpAddressParams) 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["fordisplay"]; found {
  39. vv := strconv.FormatBool(v.(bool))
  40. u.Set("fordisplay", vv)
  41. }
  42. if v, found := p.p["isportable"]; found {
  43. vv := strconv.FormatBool(v.(bool))
  44. u.Set("isportable", vv)
  45. }
  46. if v, found := p.p["networkid"]; found {
  47. u.Set("networkid", v.(string))
  48. }
  49. if v, found := p.p["projectid"]; found {
  50. u.Set("projectid", v.(string))
  51. }
  52. if v, found := p.p["regionid"]; found {
  53. vv := strconv.Itoa(v.(int))
  54. u.Set("regionid", vv)
  55. }
  56. if v, found := p.p["vpcid"]; found {
  57. u.Set("vpcid", v.(string))
  58. }
  59. if v, found := p.p["zoneid"]; found {
  60. u.Set("zoneid", v.(string))
  61. }
  62. return u
  63. }
  64. func (p *AssociateIpAddressParams) SetAccount(v string) {
  65. if p.p == nil {
  66. p.p = make(map[string]interface{})
  67. }
  68. p.p["account"] = v
  69. return
  70. }
  71. func (p *AssociateIpAddressParams) SetDomainid(v string) {
  72. if p.p == nil {
  73. p.p = make(map[string]interface{})
  74. }
  75. p.p["domainid"] = v
  76. return
  77. }
  78. func (p *AssociateIpAddressParams) SetFordisplay(v bool) {
  79. if p.p == nil {
  80. p.p = make(map[string]interface{})
  81. }
  82. p.p["fordisplay"] = v
  83. return
  84. }
  85. func (p *AssociateIpAddressParams) SetIsportable(v bool) {
  86. if p.p == nil {
  87. p.p = make(map[string]interface{})
  88. }
  89. p.p["isportable"] = v
  90. return
  91. }
  92. func (p *AssociateIpAddressParams) SetNetworkid(v string) {
  93. if p.p == nil {
  94. p.p = make(map[string]interface{})
  95. }
  96. p.p["networkid"] = v
  97. return
  98. }
  99. func (p *AssociateIpAddressParams) SetProjectid(v string) {
  100. if p.p == nil {
  101. p.p = make(map[string]interface{})
  102. }
  103. p.p["projectid"] = v
  104. return
  105. }
  106. func (p *AssociateIpAddressParams) SetRegionid(v int) {
  107. if p.p == nil {
  108. p.p = make(map[string]interface{})
  109. }
  110. p.p["regionid"] = v
  111. return
  112. }
  113. func (p *AssociateIpAddressParams) SetVpcid(v string) {
  114. if p.p == nil {
  115. p.p = make(map[string]interface{})
  116. }
  117. p.p["vpcid"] = v
  118. return
  119. }
  120. func (p *AssociateIpAddressParams) SetZoneid(v string) {
  121. if p.p == nil {
  122. p.p = make(map[string]interface{})
  123. }
  124. p.p["zoneid"] = v
  125. return
  126. }
  127. // You should always use this function to get a new AssociateIpAddressParams instance,
  128. // as then you are sure you have configured all required params
  129. func (s *AddressService) NewAssociateIpAddressParams() *AssociateIpAddressParams {
  130. p := &AssociateIpAddressParams{}
  131. p.p = make(map[string]interface{})
  132. return p
  133. }
  134. // Acquires and associates a public IP to an account.
  135. func (s *AddressService) AssociateIpAddress(p *AssociateIpAddressParams) (*AssociateIpAddressResponse, error) {
  136. resp, err := s.cs.newRequest("associateIpAddress", p.toURLValues())
  137. if err != nil {
  138. return nil, err
  139. }
  140. var r AssociateIpAddressResponse
  141. if err := json.Unmarshal(resp, &r); err != nil {
  142. return nil, err
  143. }
  144. // If we have a async client, we need to wait for the async result
  145. if s.cs.async {
  146. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  147. if err != nil {
  148. if err == AsyncTimeoutErr {
  149. return &r, err
  150. }
  151. return nil, err
  152. }
  153. b, err = getRawValue(b)
  154. if err != nil {
  155. return nil, err
  156. }
  157. if err := json.Unmarshal(b, &r); err != nil {
  158. return nil, err
  159. }
  160. }
  161. return &r, nil
  162. }
  163. type AssociateIpAddressResponse struct {
  164. JobID string `json:"jobid,omitempty"`
  165. Account string `json:"account,omitempty"`
  166. Allocated string `json:"allocated,omitempty"`
  167. Associatednetworkid string `json:"associatednetworkid,omitempty"`
  168. Associatednetworkname string `json:"associatednetworkname,omitempty"`
  169. Domain string `json:"domain,omitempty"`
  170. Domainid string `json:"domainid,omitempty"`
  171. Fordisplay bool `json:"fordisplay,omitempty"`
  172. Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
  173. Id string `json:"id,omitempty"`
  174. Ipaddress string `json:"ipaddress,omitempty"`
  175. Isportable bool `json:"isportable,omitempty"`
  176. Issourcenat bool `json:"issourcenat,omitempty"`
  177. Isstaticnat bool `json:"isstaticnat,omitempty"`
  178. Issystem bool `json:"issystem,omitempty"`
  179. Networkid string `json:"networkid,omitempty"`
  180. Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
  181. Project string `json:"project,omitempty"`
  182. Projectid string `json:"projectid,omitempty"`
  183. Purpose string `json:"purpose,omitempty"`
  184. State string `json:"state,omitempty"`
  185. Tags []struct {
  186. Account string `json:"account,omitempty"`
  187. Customer string `json:"customer,omitempty"`
  188. Domain string `json:"domain,omitempty"`
  189. Domainid string `json:"domainid,omitempty"`
  190. Key string `json:"key,omitempty"`
  191. Project string `json:"project,omitempty"`
  192. Projectid string `json:"projectid,omitempty"`
  193. Resourceid string `json:"resourceid,omitempty"`
  194. Resourcetype string `json:"resourcetype,omitempty"`
  195. Value string `json:"value,omitempty"`
  196. } `json:"tags,omitempty"`
  197. Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
  198. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  199. Virtualmachinename string `json:"virtualmachinename,omitempty"`
  200. Vlanid string `json:"vlanid,omitempty"`
  201. Vlanname string `json:"vlanname,omitempty"`
  202. Vmipaddress string `json:"vmipaddress,omitempty"`
  203. Vpcid string `json:"vpcid,omitempty"`
  204. Zoneid string `json:"zoneid,omitempty"`
  205. Zonename string `json:"zonename,omitempty"`
  206. }
  207. type DisassociateIpAddressParams struct {
  208. p map[string]interface{}
  209. }
  210. func (p *DisassociateIpAddressParams) toURLValues() url.Values {
  211. u := url.Values{}
  212. if p.p == nil {
  213. return u
  214. }
  215. if v, found := p.p["id"]; found {
  216. u.Set("id", v.(string))
  217. }
  218. return u
  219. }
  220. func (p *DisassociateIpAddressParams) SetId(v string) {
  221. if p.p == nil {
  222. p.p = make(map[string]interface{})
  223. }
  224. p.p["id"] = v
  225. return
  226. }
  227. // You should always use this function to get a new DisassociateIpAddressParams instance,
  228. // as then you are sure you have configured all required params
  229. func (s *AddressService) NewDisassociateIpAddressParams(id string) *DisassociateIpAddressParams {
  230. p := &DisassociateIpAddressParams{}
  231. p.p = make(map[string]interface{})
  232. p.p["id"] = id
  233. return p
  234. }
  235. // Disassociates an IP address from the account.
  236. func (s *AddressService) DisassociateIpAddress(p *DisassociateIpAddressParams) (*DisassociateIpAddressResponse, error) {
  237. resp, err := s.cs.newRequest("disassociateIpAddress", p.toURLValues())
  238. if err != nil {
  239. return nil, err
  240. }
  241. var r DisassociateIpAddressResponse
  242. if err := json.Unmarshal(resp, &r); err != nil {
  243. return nil, err
  244. }
  245. // If we have a async client, we need to wait for the async result
  246. if s.cs.async {
  247. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  248. if err != nil {
  249. if err == AsyncTimeoutErr {
  250. return &r, err
  251. }
  252. return nil, err
  253. }
  254. if err := json.Unmarshal(b, &r); err != nil {
  255. return nil, err
  256. }
  257. }
  258. return &r, nil
  259. }
  260. type DisassociateIpAddressResponse struct {
  261. JobID string `json:"jobid,omitempty"`
  262. Displaytext string `json:"displaytext,omitempty"`
  263. Success bool `json:"success,omitempty"`
  264. }
  265. type ListPublicIpAddressesParams struct {
  266. p map[string]interface{}
  267. }
  268. func (p *ListPublicIpAddressesParams) toURLValues() url.Values {
  269. u := url.Values{}
  270. if p.p == nil {
  271. return u
  272. }
  273. if v, found := p.p["account"]; found {
  274. u.Set("account", v.(string))
  275. }
  276. if v, found := p.p["allocatedonly"]; found {
  277. vv := strconv.FormatBool(v.(bool))
  278. u.Set("allocatedonly", vv)
  279. }
  280. if v, found := p.p["associatednetworkid"]; found {
  281. u.Set("associatednetworkid", v.(string))
  282. }
  283. if v, found := p.p["domainid"]; found {
  284. u.Set("domainid", v.(string))
  285. }
  286. if v, found := p.p["fordisplay"]; found {
  287. vv := strconv.FormatBool(v.(bool))
  288. u.Set("fordisplay", vv)
  289. }
  290. if v, found := p.p["forloadbalancing"]; found {
  291. vv := strconv.FormatBool(v.(bool))
  292. u.Set("forloadbalancing", vv)
  293. }
  294. if v, found := p.p["forvirtualnetwork"]; found {
  295. vv := strconv.FormatBool(v.(bool))
  296. u.Set("forvirtualnetwork", vv)
  297. }
  298. if v, found := p.p["id"]; found {
  299. u.Set("id", v.(string))
  300. }
  301. if v, found := p.p["ipaddress"]; found {
  302. u.Set("ipaddress", v.(string))
  303. }
  304. if v, found := p.p["isrecursive"]; found {
  305. vv := strconv.FormatBool(v.(bool))
  306. u.Set("isrecursive", vv)
  307. }
  308. if v, found := p.p["issourcenat"]; found {
  309. vv := strconv.FormatBool(v.(bool))
  310. u.Set("issourcenat", vv)
  311. }
  312. if v, found := p.p["isstaticnat"]; found {
  313. vv := strconv.FormatBool(v.(bool))
  314. u.Set("isstaticnat", vv)
  315. }
  316. if v, found := p.p["keyword"]; found {
  317. u.Set("keyword", v.(string))
  318. }
  319. if v, found := p.p["listall"]; found {
  320. vv := strconv.FormatBool(v.(bool))
  321. u.Set("listall", vv)
  322. }
  323. if v, found := p.p["page"]; found {
  324. vv := strconv.Itoa(v.(int))
  325. u.Set("page", vv)
  326. }
  327. if v, found := p.p["pagesize"]; found {
  328. vv := strconv.Itoa(v.(int))
  329. u.Set("pagesize", vv)
  330. }
  331. if v, found := p.p["physicalnetworkid"]; found {
  332. u.Set("physicalnetworkid", v.(string))
  333. }
  334. if v, found := p.p["projectid"]; found {
  335. u.Set("projectid", v.(string))
  336. }
  337. if v, found := p.p["state"]; found {
  338. u.Set("state", v.(string))
  339. }
  340. if v, found := p.p["tags"]; found {
  341. i := 0
  342. for k, vv := range v.(map[string]string) {
  343. u.Set(fmt.Sprintf("tags[%d].key", i), k)
  344. u.Set(fmt.Sprintf("tags[%d].value", i), vv)
  345. i++
  346. }
  347. }
  348. if v, found := p.p["vlanid"]; found {
  349. u.Set("vlanid", v.(string))
  350. }
  351. if v, found := p.p["vpcid"]; found {
  352. u.Set("vpcid", v.(string))
  353. }
  354. if v, found := p.p["zoneid"]; found {
  355. u.Set("zoneid", v.(string))
  356. }
  357. return u
  358. }
  359. func (p *ListPublicIpAddressesParams) SetAccount(v string) {
  360. if p.p == nil {
  361. p.p = make(map[string]interface{})
  362. }
  363. p.p["account"] = v
  364. return
  365. }
  366. func (p *ListPublicIpAddressesParams) SetAllocatedonly(v bool) {
  367. if p.p == nil {
  368. p.p = make(map[string]interface{})
  369. }
  370. p.p["allocatedonly"] = v
  371. return
  372. }
  373. func (p *ListPublicIpAddressesParams) SetAssociatednetworkid(v string) {
  374. if p.p == nil {
  375. p.p = make(map[string]interface{})
  376. }
  377. p.p["associatednetworkid"] = v
  378. return
  379. }
  380. func (p *ListPublicIpAddressesParams) SetDomainid(v string) {
  381. if p.p == nil {
  382. p.p = make(map[string]interface{})
  383. }
  384. p.p["domainid"] = v
  385. return
  386. }
  387. func (p *ListPublicIpAddressesParams) SetFordisplay(v bool) {
  388. if p.p == nil {
  389. p.p = make(map[string]interface{})
  390. }
  391. p.p["fordisplay"] = v
  392. return
  393. }
  394. func (p *ListPublicIpAddressesParams) SetForloadbalancing(v bool) {
  395. if p.p == nil {
  396. p.p = make(map[string]interface{})
  397. }
  398. p.p["forloadbalancing"] = v
  399. return
  400. }
  401. func (p *ListPublicIpAddressesParams) SetForvirtualnetwork(v bool) {
  402. if p.p == nil {
  403. p.p = make(map[string]interface{})
  404. }
  405. p.p["forvirtualnetwork"] = v
  406. return
  407. }
  408. func (p *ListPublicIpAddressesParams) SetId(v string) {
  409. if p.p == nil {
  410. p.p = make(map[string]interface{})
  411. }
  412. p.p["id"] = v
  413. return
  414. }
  415. func (p *ListPublicIpAddressesParams) SetIpaddress(v string) {
  416. if p.p == nil {
  417. p.p = make(map[string]interface{})
  418. }
  419. p.p["ipaddress"] = v
  420. return
  421. }
  422. func (p *ListPublicIpAddressesParams) SetIsrecursive(v bool) {
  423. if p.p == nil {
  424. p.p = make(map[string]interface{})
  425. }
  426. p.p["isrecursive"] = v
  427. return
  428. }
  429. func (p *ListPublicIpAddressesParams) SetIssourcenat(v bool) {
  430. if p.p == nil {
  431. p.p = make(map[string]interface{})
  432. }
  433. p.p["issourcenat"] = v
  434. return
  435. }
  436. func (p *ListPublicIpAddressesParams) SetIsstaticnat(v bool) {
  437. if p.p == nil {
  438. p.p = make(map[string]interface{})
  439. }
  440. p.p["isstaticnat"] = v
  441. return
  442. }
  443. func (p *ListPublicIpAddressesParams) SetKeyword(v string) {
  444. if p.p == nil {
  445. p.p = make(map[string]interface{})
  446. }
  447. p.p["keyword"] = v
  448. return
  449. }
  450. func (p *ListPublicIpAddressesParams) SetListall(v bool) {
  451. if p.p == nil {
  452. p.p = make(map[string]interface{})
  453. }
  454. p.p["listall"] = v
  455. return
  456. }
  457. func (p *ListPublicIpAddressesParams) SetPage(v int) {
  458. if p.p == nil {
  459. p.p = make(map[string]interface{})
  460. }
  461. p.p["page"] = v
  462. return
  463. }
  464. func (p *ListPublicIpAddressesParams) SetPagesize(v int) {
  465. if p.p == nil {
  466. p.p = make(map[string]interface{})
  467. }
  468. p.p["pagesize"] = v
  469. return
  470. }
  471. func (p *ListPublicIpAddressesParams) SetPhysicalnetworkid(v string) {
  472. if p.p == nil {
  473. p.p = make(map[string]interface{})
  474. }
  475. p.p["physicalnetworkid"] = v
  476. return
  477. }
  478. func (p *ListPublicIpAddressesParams) SetProjectid(v string) {
  479. if p.p == nil {
  480. p.p = make(map[string]interface{})
  481. }
  482. p.p["projectid"] = v
  483. return
  484. }
  485. func (p *ListPublicIpAddressesParams) SetState(v string) {
  486. if p.p == nil {
  487. p.p = make(map[string]interface{})
  488. }
  489. p.p["state"] = v
  490. return
  491. }
  492. func (p *ListPublicIpAddressesParams) SetTags(v map[string]string) {
  493. if p.p == nil {
  494. p.p = make(map[string]interface{})
  495. }
  496. p.p["tags"] = v
  497. return
  498. }
  499. func (p *ListPublicIpAddressesParams) SetVlanid(v string) {
  500. if p.p == nil {
  501. p.p = make(map[string]interface{})
  502. }
  503. p.p["vlanid"] = v
  504. return
  505. }
  506. func (p *ListPublicIpAddressesParams) SetVpcid(v string) {
  507. if p.p == nil {
  508. p.p = make(map[string]interface{})
  509. }
  510. p.p["vpcid"] = v
  511. return
  512. }
  513. func (p *ListPublicIpAddressesParams) SetZoneid(v string) {
  514. if p.p == nil {
  515. p.p = make(map[string]interface{})
  516. }
  517. p.p["zoneid"] = v
  518. return
  519. }
  520. // You should always use this function to get a new ListPublicIpAddressesParams instance,
  521. // as then you are sure you have configured all required params
  522. func (s *AddressService) NewListPublicIpAddressesParams() *ListPublicIpAddressesParams {
  523. p := &ListPublicIpAddressesParams{}
  524. p.p = make(map[string]interface{})
  525. return p
  526. }
  527. // This is a courtesy helper function, which in some cases may not work as expected!
  528. func (s *AddressService) GetPublicIpAddressByID(id string, opts ...OptionFunc) (*PublicIpAddress, int, error) {
  529. p := &ListPublicIpAddressesParams{}
  530. p.p = make(map[string]interface{})
  531. p.p["id"] = id
  532. for _, fn := range opts {
  533. if err := fn(s.cs, p); err != nil {
  534. return nil, -1, err
  535. }
  536. }
  537. l, err := s.ListPublicIpAddresses(p)
  538. if err != nil {
  539. if strings.Contains(err.Error(), fmt.Sprintf(
  540. "Invalid parameter id value=%s due to incorrect long value format, "+
  541. "or entity does not exist", id)) {
  542. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  543. }
  544. return nil, -1, err
  545. }
  546. if l.Count == 0 {
  547. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  548. }
  549. if l.Count == 1 {
  550. return l.PublicIpAddresses[0], l.Count, nil
  551. }
  552. return nil, l.Count, fmt.Errorf("There is more then one result for PublicIpAddress UUID: %s!", id)
  553. }
  554. // Lists all public ip addresses
  555. func (s *AddressService) ListPublicIpAddresses(p *ListPublicIpAddressesParams) (*ListPublicIpAddressesResponse, error) {
  556. resp, err := s.cs.newRequest("listPublicIpAddresses", p.toURLValues())
  557. if err != nil {
  558. return nil, err
  559. }
  560. var r ListPublicIpAddressesResponse
  561. if err := json.Unmarshal(resp, &r); err != nil {
  562. return nil, err
  563. }
  564. return &r, nil
  565. }
  566. type ListPublicIpAddressesResponse struct {
  567. Count int `json:"count"`
  568. PublicIpAddresses []*PublicIpAddress `json:"publicipaddress"`
  569. }
  570. type PublicIpAddress struct {
  571. Account string `json:"account,omitempty"`
  572. Allocated string `json:"allocated,omitempty"`
  573. Associatednetworkid string `json:"associatednetworkid,omitempty"`
  574. Associatednetworkname string `json:"associatednetworkname,omitempty"`
  575. Domain string `json:"domain,omitempty"`
  576. Domainid string `json:"domainid,omitempty"`
  577. Fordisplay bool `json:"fordisplay,omitempty"`
  578. Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
  579. Id string `json:"id,omitempty"`
  580. Ipaddress string `json:"ipaddress,omitempty"`
  581. Isportable bool `json:"isportable,omitempty"`
  582. Issourcenat bool `json:"issourcenat,omitempty"`
  583. Isstaticnat bool `json:"isstaticnat,omitempty"`
  584. Issystem bool `json:"issystem,omitempty"`
  585. Networkid string `json:"networkid,omitempty"`
  586. Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
  587. Project string `json:"project,omitempty"`
  588. Projectid string `json:"projectid,omitempty"`
  589. Purpose string `json:"purpose,omitempty"`
  590. State string `json:"state,omitempty"`
  591. Tags []struct {
  592. Account string `json:"account,omitempty"`
  593. Customer string `json:"customer,omitempty"`
  594. Domain string `json:"domain,omitempty"`
  595. Domainid string `json:"domainid,omitempty"`
  596. Key string `json:"key,omitempty"`
  597. Project string `json:"project,omitempty"`
  598. Projectid string `json:"projectid,omitempty"`
  599. Resourceid string `json:"resourceid,omitempty"`
  600. Resourcetype string `json:"resourcetype,omitempty"`
  601. Value string `json:"value,omitempty"`
  602. } `json:"tags,omitempty"`
  603. Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
  604. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  605. Virtualmachinename string `json:"virtualmachinename,omitempty"`
  606. Vlanid string `json:"vlanid,omitempty"`
  607. Vlanname string `json:"vlanname,omitempty"`
  608. Vmipaddress string `json:"vmipaddress,omitempty"`
  609. Vpcid string `json:"vpcid,omitempty"`
  610. Zoneid string `json:"zoneid,omitempty"`
  611. Zonename string `json:"zonename,omitempty"`
  612. }
  613. type UpdateIpAddressParams struct {
  614. p map[string]interface{}
  615. }
  616. func (p *UpdateIpAddressParams) toURLValues() url.Values {
  617. u := url.Values{}
  618. if p.p == nil {
  619. return u
  620. }
  621. if v, found := p.p["customid"]; found {
  622. u.Set("customid", v.(string))
  623. }
  624. if v, found := p.p["fordisplay"]; found {
  625. vv := strconv.FormatBool(v.(bool))
  626. u.Set("fordisplay", vv)
  627. }
  628. if v, found := p.p["id"]; found {
  629. u.Set("id", v.(string))
  630. }
  631. return u
  632. }
  633. func (p *UpdateIpAddressParams) SetCustomid(v string) {
  634. if p.p == nil {
  635. p.p = make(map[string]interface{})
  636. }
  637. p.p["customid"] = v
  638. return
  639. }
  640. func (p *UpdateIpAddressParams) SetFordisplay(v bool) {
  641. if p.p == nil {
  642. p.p = make(map[string]interface{})
  643. }
  644. p.p["fordisplay"] = v
  645. return
  646. }
  647. func (p *UpdateIpAddressParams) SetId(v string) {
  648. if p.p == nil {
  649. p.p = make(map[string]interface{})
  650. }
  651. p.p["id"] = v
  652. return
  653. }
  654. // You should always use this function to get a new UpdateIpAddressParams instance,
  655. // as then you are sure you have configured all required params
  656. func (s *AddressService) NewUpdateIpAddressParams(id string) *UpdateIpAddressParams {
  657. p := &UpdateIpAddressParams{}
  658. p.p = make(map[string]interface{})
  659. p.p["id"] = id
  660. return p
  661. }
  662. // Updates an IP address
  663. func (s *AddressService) UpdateIpAddress(p *UpdateIpAddressParams) (*UpdateIpAddressResponse, error) {
  664. resp, err := s.cs.newRequest("updateIpAddress", p.toURLValues())
  665. if err != nil {
  666. return nil, err
  667. }
  668. var r UpdateIpAddressResponse
  669. if err := json.Unmarshal(resp, &r); err != nil {
  670. return nil, err
  671. }
  672. // If we have a async client, we need to wait for the async result
  673. if s.cs.async {
  674. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  675. if err != nil {
  676. if err == AsyncTimeoutErr {
  677. return &r, err
  678. }
  679. return nil, err
  680. }
  681. b, err = getRawValue(b)
  682. if err != nil {
  683. return nil, err
  684. }
  685. if err := json.Unmarshal(b, &r); err != nil {
  686. return nil, err
  687. }
  688. }
  689. return &r, nil
  690. }
  691. type UpdateIpAddressResponse struct {
  692. JobID string `json:"jobid,omitempty"`
  693. Account string `json:"account,omitempty"`
  694. Allocated string `json:"allocated,omitempty"`
  695. Associatednetworkid string `json:"associatednetworkid,omitempty"`
  696. Associatednetworkname string `json:"associatednetworkname,omitempty"`
  697. Domain string `json:"domain,omitempty"`
  698. Domainid string `json:"domainid,omitempty"`
  699. Fordisplay bool `json:"fordisplay,omitempty"`
  700. Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
  701. Id string `json:"id,omitempty"`
  702. Ipaddress string `json:"ipaddress,omitempty"`
  703. Isportable bool `json:"isportable,omitempty"`
  704. Issourcenat bool `json:"issourcenat,omitempty"`
  705. Isstaticnat bool `json:"isstaticnat,omitempty"`
  706. Issystem bool `json:"issystem,omitempty"`
  707. Networkid string `json:"networkid,omitempty"`
  708. Physicalnetworkid string `json:"physicalnetworkid,omitempty"`
  709. Project string `json:"project,omitempty"`
  710. Projectid string `json:"projectid,omitempty"`
  711. Purpose string `json:"purpose,omitempty"`
  712. State string `json:"state,omitempty"`
  713. Tags []struct {
  714. Account string `json:"account,omitempty"`
  715. Customer string `json:"customer,omitempty"`
  716. Domain string `json:"domain,omitempty"`
  717. Domainid string `json:"domainid,omitempty"`
  718. Key string `json:"key,omitempty"`
  719. Project string `json:"project,omitempty"`
  720. Projectid string `json:"projectid,omitempty"`
  721. Resourceid string `json:"resourceid,omitempty"`
  722. Resourcetype string `json:"resourcetype,omitempty"`
  723. Value string `json:"value,omitempty"`
  724. } `json:"tags,omitempty"`
  725. Virtualmachinedisplayname string `json:"virtualmachinedisplayname,omitempty"`
  726. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  727. Virtualmachinename string `json:"virtualmachinename,omitempty"`
  728. Vlanid string `json:"vlanid,omitempty"`
  729. Vlanname string `json:"vlanname,omitempty"`
  730. Vmipaddress string `json:"vmipaddress,omitempty"`
  731. Vpcid string `json:"vpcid,omitempty"`
  732. Zoneid string `json:"zoneid,omitempty"`
  733. Zonename string `json:"zonename,omitempty"`
  734. }