RouterService.go 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458
  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 StartRouterParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *StartRouterParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["id"]; found {
  33. u.Set("id", v.(string))
  34. }
  35. return u
  36. }
  37. func (p *StartRouterParams) SetId(v string) {
  38. if p.p == nil {
  39. p.p = make(map[string]interface{})
  40. }
  41. p.p["id"] = v
  42. return
  43. }
  44. // You should always use this function to get a new StartRouterParams instance,
  45. // as then you are sure you have configured all required params
  46. func (s *RouterService) NewStartRouterParams(id string) *StartRouterParams {
  47. p := &StartRouterParams{}
  48. p.p = make(map[string]interface{})
  49. p.p["id"] = id
  50. return p
  51. }
  52. // Starts a router.
  53. func (s *RouterService) StartRouter(p *StartRouterParams) (*StartRouterResponse, error) {
  54. resp, err := s.cs.newRequest("startRouter", p.toURLValues())
  55. if err != nil {
  56. return nil, err
  57. }
  58. var r StartRouterResponse
  59. if err := json.Unmarshal(resp, &r); err != nil {
  60. return nil, err
  61. }
  62. // If we have a async client, we need to wait for the async result
  63. if s.cs.async {
  64. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  65. if err != nil {
  66. if err == AsyncTimeoutErr {
  67. return &r, err
  68. }
  69. return nil, err
  70. }
  71. b, err = getRawValue(b)
  72. if err != nil {
  73. return nil, err
  74. }
  75. if err := json.Unmarshal(b, &r); err != nil {
  76. return nil, err
  77. }
  78. }
  79. return &r, nil
  80. }
  81. type StartRouterResponse struct {
  82. JobID string `json:"jobid,omitempty"`
  83. Account string `json:"account,omitempty"`
  84. Created string `json:"created,omitempty"`
  85. Dns1 string `json:"dns1,omitempty"`
  86. Dns2 string `json:"dns2,omitempty"`
  87. Domain string `json:"domain,omitempty"`
  88. Domainid string `json:"domainid,omitempty"`
  89. Gateway string `json:"gateway,omitempty"`
  90. Guestipaddress string `json:"guestipaddress,omitempty"`
  91. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  92. Guestnetmask string `json:"guestnetmask,omitempty"`
  93. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  94. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  95. Hostid string `json:"hostid,omitempty"`
  96. Hostname string `json:"hostname,omitempty"`
  97. Hypervisor string `json:"hypervisor,omitempty"`
  98. Id string `json:"id,omitempty"`
  99. Ip6dns1 string `json:"ip6dns1,omitempty"`
  100. Ip6dns2 string `json:"ip6dns2,omitempty"`
  101. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  102. Linklocalip string `json:"linklocalip,omitempty"`
  103. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  104. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  105. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  106. Name string `json:"name,omitempty"`
  107. Networkdomain string `json:"networkdomain,omitempty"`
  108. Nic []struct {
  109. Broadcasturi string `json:"broadcasturi,omitempty"`
  110. Deviceid string `json:"deviceid,omitempty"`
  111. Gateway string `json:"gateway,omitempty"`
  112. Id string `json:"id,omitempty"`
  113. Ip6address string `json:"ip6address,omitempty"`
  114. Ip6cidr string `json:"ip6cidr,omitempty"`
  115. Ip6gateway string `json:"ip6gateway,omitempty"`
  116. Ipaddress string `json:"ipaddress,omitempty"`
  117. Isdefault bool `json:"isdefault,omitempty"`
  118. Isolationuri string `json:"isolationuri,omitempty"`
  119. Macaddress string `json:"macaddress,omitempty"`
  120. Netmask string `json:"netmask,omitempty"`
  121. Networkid string `json:"networkid,omitempty"`
  122. Networkname string `json:"networkname,omitempty"`
  123. Secondaryip []struct {
  124. Id string `json:"id,omitempty"`
  125. Ipaddress string `json:"ipaddress,omitempty"`
  126. } `json:"secondaryip,omitempty"`
  127. Traffictype string `json:"traffictype,omitempty"`
  128. Type string `json:"type,omitempty"`
  129. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  130. } `json:"nic,omitempty"`
  131. Podid string `json:"podid,omitempty"`
  132. Project string `json:"project,omitempty"`
  133. Projectid string `json:"projectid,omitempty"`
  134. Publicip string `json:"publicip,omitempty"`
  135. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  136. Publicnetmask string `json:"publicnetmask,omitempty"`
  137. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  138. Redundantstate string `json:"redundantstate,omitempty"`
  139. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  140. Role string `json:"role,omitempty"`
  141. Scriptsversion string `json:"scriptsversion,omitempty"`
  142. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  143. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  144. State string `json:"state,omitempty"`
  145. Templateid string `json:"templateid,omitempty"`
  146. Version string `json:"version,omitempty"`
  147. Vpcid string `json:"vpcid,omitempty"`
  148. Vpcname string `json:"vpcname,omitempty"`
  149. Zoneid string `json:"zoneid,omitempty"`
  150. Zonename string `json:"zonename,omitempty"`
  151. }
  152. type RebootRouterParams struct {
  153. p map[string]interface{}
  154. }
  155. func (p *RebootRouterParams) toURLValues() url.Values {
  156. u := url.Values{}
  157. if p.p == nil {
  158. return u
  159. }
  160. if v, found := p.p["id"]; found {
  161. u.Set("id", v.(string))
  162. }
  163. return u
  164. }
  165. func (p *RebootRouterParams) SetId(v string) {
  166. if p.p == nil {
  167. p.p = make(map[string]interface{})
  168. }
  169. p.p["id"] = v
  170. return
  171. }
  172. // You should always use this function to get a new RebootRouterParams instance,
  173. // as then you are sure you have configured all required params
  174. func (s *RouterService) NewRebootRouterParams(id string) *RebootRouterParams {
  175. p := &RebootRouterParams{}
  176. p.p = make(map[string]interface{})
  177. p.p["id"] = id
  178. return p
  179. }
  180. // Starts a router.
  181. func (s *RouterService) RebootRouter(p *RebootRouterParams) (*RebootRouterResponse, error) {
  182. resp, err := s.cs.newRequest("rebootRouter", p.toURLValues())
  183. if err != nil {
  184. return nil, err
  185. }
  186. var r RebootRouterResponse
  187. if err := json.Unmarshal(resp, &r); err != nil {
  188. return nil, err
  189. }
  190. // If we have a async client, we need to wait for the async result
  191. if s.cs.async {
  192. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  193. if err != nil {
  194. if err == AsyncTimeoutErr {
  195. return &r, err
  196. }
  197. return nil, err
  198. }
  199. b, err = getRawValue(b)
  200. if err != nil {
  201. return nil, err
  202. }
  203. if err := json.Unmarshal(b, &r); err != nil {
  204. return nil, err
  205. }
  206. }
  207. return &r, nil
  208. }
  209. type RebootRouterResponse struct {
  210. JobID string `json:"jobid,omitempty"`
  211. Account string `json:"account,omitempty"`
  212. Created string `json:"created,omitempty"`
  213. Dns1 string `json:"dns1,omitempty"`
  214. Dns2 string `json:"dns2,omitempty"`
  215. Domain string `json:"domain,omitempty"`
  216. Domainid string `json:"domainid,omitempty"`
  217. Gateway string `json:"gateway,omitempty"`
  218. Guestipaddress string `json:"guestipaddress,omitempty"`
  219. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  220. Guestnetmask string `json:"guestnetmask,omitempty"`
  221. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  222. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  223. Hostid string `json:"hostid,omitempty"`
  224. Hostname string `json:"hostname,omitempty"`
  225. Hypervisor string `json:"hypervisor,omitempty"`
  226. Id string `json:"id,omitempty"`
  227. Ip6dns1 string `json:"ip6dns1,omitempty"`
  228. Ip6dns2 string `json:"ip6dns2,omitempty"`
  229. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  230. Linklocalip string `json:"linklocalip,omitempty"`
  231. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  232. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  233. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  234. Name string `json:"name,omitempty"`
  235. Networkdomain string `json:"networkdomain,omitempty"`
  236. Nic []struct {
  237. Broadcasturi string `json:"broadcasturi,omitempty"`
  238. Deviceid string `json:"deviceid,omitempty"`
  239. Gateway string `json:"gateway,omitempty"`
  240. Id string `json:"id,omitempty"`
  241. Ip6address string `json:"ip6address,omitempty"`
  242. Ip6cidr string `json:"ip6cidr,omitempty"`
  243. Ip6gateway string `json:"ip6gateway,omitempty"`
  244. Ipaddress string `json:"ipaddress,omitempty"`
  245. Isdefault bool `json:"isdefault,omitempty"`
  246. Isolationuri string `json:"isolationuri,omitempty"`
  247. Macaddress string `json:"macaddress,omitempty"`
  248. Netmask string `json:"netmask,omitempty"`
  249. Networkid string `json:"networkid,omitempty"`
  250. Networkname string `json:"networkname,omitempty"`
  251. Secondaryip []struct {
  252. Id string `json:"id,omitempty"`
  253. Ipaddress string `json:"ipaddress,omitempty"`
  254. } `json:"secondaryip,omitempty"`
  255. Traffictype string `json:"traffictype,omitempty"`
  256. Type string `json:"type,omitempty"`
  257. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  258. } `json:"nic,omitempty"`
  259. Podid string `json:"podid,omitempty"`
  260. Project string `json:"project,omitempty"`
  261. Projectid string `json:"projectid,omitempty"`
  262. Publicip string `json:"publicip,omitempty"`
  263. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  264. Publicnetmask string `json:"publicnetmask,omitempty"`
  265. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  266. Redundantstate string `json:"redundantstate,omitempty"`
  267. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  268. Role string `json:"role,omitempty"`
  269. Scriptsversion string `json:"scriptsversion,omitempty"`
  270. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  271. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  272. State string `json:"state,omitempty"`
  273. Templateid string `json:"templateid,omitempty"`
  274. Version string `json:"version,omitempty"`
  275. Vpcid string `json:"vpcid,omitempty"`
  276. Vpcname string `json:"vpcname,omitempty"`
  277. Zoneid string `json:"zoneid,omitempty"`
  278. Zonename string `json:"zonename,omitempty"`
  279. }
  280. type StopRouterParams struct {
  281. p map[string]interface{}
  282. }
  283. func (p *StopRouterParams) toURLValues() url.Values {
  284. u := url.Values{}
  285. if p.p == nil {
  286. return u
  287. }
  288. if v, found := p.p["forced"]; found {
  289. vv := strconv.FormatBool(v.(bool))
  290. u.Set("forced", vv)
  291. }
  292. if v, found := p.p["id"]; found {
  293. u.Set("id", v.(string))
  294. }
  295. return u
  296. }
  297. func (p *StopRouterParams) SetForced(v bool) {
  298. if p.p == nil {
  299. p.p = make(map[string]interface{})
  300. }
  301. p.p["forced"] = v
  302. return
  303. }
  304. func (p *StopRouterParams) SetId(v string) {
  305. if p.p == nil {
  306. p.p = make(map[string]interface{})
  307. }
  308. p.p["id"] = v
  309. return
  310. }
  311. // You should always use this function to get a new StopRouterParams instance,
  312. // as then you are sure you have configured all required params
  313. func (s *RouterService) NewStopRouterParams(id string) *StopRouterParams {
  314. p := &StopRouterParams{}
  315. p.p = make(map[string]interface{})
  316. p.p["id"] = id
  317. return p
  318. }
  319. // Stops a router.
  320. func (s *RouterService) StopRouter(p *StopRouterParams) (*StopRouterResponse, error) {
  321. resp, err := s.cs.newRequest("stopRouter", p.toURLValues())
  322. if err != nil {
  323. return nil, err
  324. }
  325. var r StopRouterResponse
  326. if err := json.Unmarshal(resp, &r); err != nil {
  327. return nil, err
  328. }
  329. // If we have a async client, we need to wait for the async result
  330. if s.cs.async {
  331. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  332. if err != nil {
  333. if err == AsyncTimeoutErr {
  334. return &r, err
  335. }
  336. return nil, err
  337. }
  338. b, err = getRawValue(b)
  339. if err != nil {
  340. return nil, err
  341. }
  342. if err := json.Unmarshal(b, &r); err != nil {
  343. return nil, err
  344. }
  345. }
  346. return &r, nil
  347. }
  348. type StopRouterResponse struct {
  349. JobID string `json:"jobid,omitempty"`
  350. Account string `json:"account,omitempty"`
  351. Created string `json:"created,omitempty"`
  352. Dns1 string `json:"dns1,omitempty"`
  353. Dns2 string `json:"dns2,omitempty"`
  354. Domain string `json:"domain,omitempty"`
  355. Domainid string `json:"domainid,omitempty"`
  356. Gateway string `json:"gateway,omitempty"`
  357. Guestipaddress string `json:"guestipaddress,omitempty"`
  358. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  359. Guestnetmask string `json:"guestnetmask,omitempty"`
  360. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  361. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  362. Hostid string `json:"hostid,omitempty"`
  363. Hostname string `json:"hostname,omitempty"`
  364. Hypervisor string `json:"hypervisor,omitempty"`
  365. Id string `json:"id,omitempty"`
  366. Ip6dns1 string `json:"ip6dns1,omitempty"`
  367. Ip6dns2 string `json:"ip6dns2,omitempty"`
  368. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  369. Linklocalip string `json:"linklocalip,omitempty"`
  370. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  371. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  372. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  373. Name string `json:"name,omitempty"`
  374. Networkdomain string `json:"networkdomain,omitempty"`
  375. Nic []struct {
  376. Broadcasturi string `json:"broadcasturi,omitempty"`
  377. Deviceid string `json:"deviceid,omitempty"`
  378. Gateway string `json:"gateway,omitempty"`
  379. Id string `json:"id,omitempty"`
  380. Ip6address string `json:"ip6address,omitempty"`
  381. Ip6cidr string `json:"ip6cidr,omitempty"`
  382. Ip6gateway string `json:"ip6gateway,omitempty"`
  383. Ipaddress string `json:"ipaddress,omitempty"`
  384. Isdefault bool `json:"isdefault,omitempty"`
  385. Isolationuri string `json:"isolationuri,omitempty"`
  386. Macaddress string `json:"macaddress,omitempty"`
  387. Netmask string `json:"netmask,omitempty"`
  388. Networkid string `json:"networkid,omitempty"`
  389. Networkname string `json:"networkname,omitempty"`
  390. Secondaryip []struct {
  391. Id string `json:"id,omitempty"`
  392. Ipaddress string `json:"ipaddress,omitempty"`
  393. } `json:"secondaryip,omitempty"`
  394. Traffictype string `json:"traffictype,omitempty"`
  395. Type string `json:"type,omitempty"`
  396. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  397. } `json:"nic,omitempty"`
  398. Podid string `json:"podid,omitempty"`
  399. Project string `json:"project,omitempty"`
  400. Projectid string `json:"projectid,omitempty"`
  401. Publicip string `json:"publicip,omitempty"`
  402. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  403. Publicnetmask string `json:"publicnetmask,omitempty"`
  404. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  405. Redundantstate string `json:"redundantstate,omitempty"`
  406. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  407. Role string `json:"role,omitempty"`
  408. Scriptsversion string `json:"scriptsversion,omitempty"`
  409. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  410. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  411. State string `json:"state,omitempty"`
  412. Templateid string `json:"templateid,omitempty"`
  413. Version string `json:"version,omitempty"`
  414. Vpcid string `json:"vpcid,omitempty"`
  415. Vpcname string `json:"vpcname,omitempty"`
  416. Zoneid string `json:"zoneid,omitempty"`
  417. Zonename string `json:"zonename,omitempty"`
  418. }
  419. type DestroyRouterParams struct {
  420. p map[string]interface{}
  421. }
  422. func (p *DestroyRouterParams) toURLValues() url.Values {
  423. u := url.Values{}
  424. if p.p == nil {
  425. return u
  426. }
  427. if v, found := p.p["id"]; found {
  428. u.Set("id", v.(string))
  429. }
  430. return u
  431. }
  432. func (p *DestroyRouterParams) SetId(v string) {
  433. if p.p == nil {
  434. p.p = make(map[string]interface{})
  435. }
  436. p.p["id"] = v
  437. return
  438. }
  439. // You should always use this function to get a new DestroyRouterParams instance,
  440. // as then you are sure you have configured all required params
  441. func (s *RouterService) NewDestroyRouterParams(id string) *DestroyRouterParams {
  442. p := &DestroyRouterParams{}
  443. p.p = make(map[string]interface{})
  444. p.p["id"] = id
  445. return p
  446. }
  447. // Destroys a router.
  448. func (s *RouterService) DestroyRouter(p *DestroyRouterParams) (*DestroyRouterResponse, error) {
  449. resp, err := s.cs.newRequest("destroyRouter", p.toURLValues())
  450. if err != nil {
  451. return nil, err
  452. }
  453. var r DestroyRouterResponse
  454. if err := json.Unmarshal(resp, &r); err != nil {
  455. return nil, err
  456. }
  457. // If we have a async client, we need to wait for the async result
  458. if s.cs.async {
  459. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  460. if err != nil {
  461. if err == AsyncTimeoutErr {
  462. return &r, err
  463. }
  464. return nil, err
  465. }
  466. b, err = getRawValue(b)
  467. if err != nil {
  468. return nil, err
  469. }
  470. if err := json.Unmarshal(b, &r); err != nil {
  471. return nil, err
  472. }
  473. }
  474. return &r, nil
  475. }
  476. type DestroyRouterResponse struct {
  477. JobID string `json:"jobid,omitempty"`
  478. Account string `json:"account,omitempty"`
  479. Created string `json:"created,omitempty"`
  480. Dns1 string `json:"dns1,omitempty"`
  481. Dns2 string `json:"dns2,omitempty"`
  482. Domain string `json:"domain,omitempty"`
  483. Domainid string `json:"domainid,omitempty"`
  484. Gateway string `json:"gateway,omitempty"`
  485. Guestipaddress string `json:"guestipaddress,omitempty"`
  486. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  487. Guestnetmask string `json:"guestnetmask,omitempty"`
  488. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  489. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  490. Hostid string `json:"hostid,omitempty"`
  491. Hostname string `json:"hostname,omitempty"`
  492. Hypervisor string `json:"hypervisor,omitempty"`
  493. Id string `json:"id,omitempty"`
  494. Ip6dns1 string `json:"ip6dns1,omitempty"`
  495. Ip6dns2 string `json:"ip6dns2,omitempty"`
  496. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  497. Linklocalip string `json:"linklocalip,omitempty"`
  498. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  499. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  500. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  501. Name string `json:"name,omitempty"`
  502. Networkdomain string `json:"networkdomain,omitempty"`
  503. Nic []struct {
  504. Broadcasturi string `json:"broadcasturi,omitempty"`
  505. Deviceid string `json:"deviceid,omitempty"`
  506. Gateway string `json:"gateway,omitempty"`
  507. Id string `json:"id,omitempty"`
  508. Ip6address string `json:"ip6address,omitempty"`
  509. Ip6cidr string `json:"ip6cidr,omitempty"`
  510. Ip6gateway string `json:"ip6gateway,omitempty"`
  511. Ipaddress string `json:"ipaddress,omitempty"`
  512. Isdefault bool `json:"isdefault,omitempty"`
  513. Isolationuri string `json:"isolationuri,omitempty"`
  514. Macaddress string `json:"macaddress,omitempty"`
  515. Netmask string `json:"netmask,omitempty"`
  516. Networkid string `json:"networkid,omitempty"`
  517. Networkname string `json:"networkname,omitempty"`
  518. Secondaryip []struct {
  519. Id string `json:"id,omitempty"`
  520. Ipaddress string `json:"ipaddress,omitempty"`
  521. } `json:"secondaryip,omitempty"`
  522. Traffictype string `json:"traffictype,omitempty"`
  523. Type string `json:"type,omitempty"`
  524. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  525. } `json:"nic,omitempty"`
  526. Podid string `json:"podid,omitempty"`
  527. Project string `json:"project,omitempty"`
  528. Projectid string `json:"projectid,omitempty"`
  529. Publicip string `json:"publicip,omitempty"`
  530. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  531. Publicnetmask string `json:"publicnetmask,omitempty"`
  532. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  533. Redundantstate string `json:"redundantstate,omitempty"`
  534. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  535. Role string `json:"role,omitempty"`
  536. Scriptsversion string `json:"scriptsversion,omitempty"`
  537. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  538. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  539. State string `json:"state,omitempty"`
  540. Templateid string `json:"templateid,omitempty"`
  541. Version string `json:"version,omitempty"`
  542. Vpcid string `json:"vpcid,omitempty"`
  543. Vpcname string `json:"vpcname,omitempty"`
  544. Zoneid string `json:"zoneid,omitempty"`
  545. Zonename string `json:"zonename,omitempty"`
  546. }
  547. type ChangeServiceForRouterParams struct {
  548. p map[string]interface{}
  549. }
  550. func (p *ChangeServiceForRouterParams) toURLValues() url.Values {
  551. u := url.Values{}
  552. if p.p == nil {
  553. return u
  554. }
  555. if v, found := p.p["id"]; found {
  556. u.Set("id", v.(string))
  557. }
  558. if v, found := p.p["serviceofferingid"]; found {
  559. u.Set("serviceofferingid", v.(string))
  560. }
  561. return u
  562. }
  563. func (p *ChangeServiceForRouterParams) SetId(v string) {
  564. if p.p == nil {
  565. p.p = make(map[string]interface{})
  566. }
  567. p.p["id"] = v
  568. return
  569. }
  570. func (p *ChangeServiceForRouterParams) SetServiceofferingid(v string) {
  571. if p.p == nil {
  572. p.p = make(map[string]interface{})
  573. }
  574. p.p["serviceofferingid"] = v
  575. return
  576. }
  577. // You should always use this function to get a new ChangeServiceForRouterParams instance,
  578. // as then you are sure you have configured all required params
  579. func (s *RouterService) NewChangeServiceForRouterParams(id string, serviceofferingid string) *ChangeServiceForRouterParams {
  580. p := &ChangeServiceForRouterParams{}
  581. p.p = make(map[string]interface{})
  582. p.p["id"] = id
  583. p.p["serviceofferingid"] = serviceofferingid
  584. return p
  585. }
  586. // Upgrades domain router to a new service offering
  587. func (s *RouterService) ChangeServiceForRouter(p *ChangeServiceForRouterParams) (*ChangeServiceForRouterResponse, error) {
  588. resp, err := s.cs.newRequest("changeServiceForRouter", p.toURLValues())
  589. if err != nil {
  590. return nil, err
  591. }
  592. var r ChangeServiceForRouterResponse
  593. if err := json.Unmarshal(resp, &r); err != nil {
  594. return nil, err
  595. }
  596. return &r, nil
  597. }
  598. type ChangeServiceForRouterResponse struct {
  599. Account string `json:"account,omitempty"`
  600. Created string `json:"created,omitempty"`
  601. Dns1 string `json:"dns1,omitempty"`
  602. Dns2 string `json:"dns2,omitempty"`
  603. Domain string `json:"domain,omitempty"`
  604. Domainid string `json:"domainid,omitempty"`
  605. Gateway string `json:"gateway,omitempty"`
  606. Guestipaddress string `json:"guestipaddress,omitempty"`
  607. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  608. Guestnetmask string `json:"guestnetmask,omitempty"`
  609. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  610. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  611. Hostid string `json:"hostid,omitempty"`
  612. Hostname string `json:"hostname,omitempty"`
  613. Hypervisor string `json:"hypervisor,omitempty"`
  614. Id string `json:"id,omitempty"`
  615. Ip6dns1 string `json:"ip6dns1,omitempty"`
  616. Ip6dns2 string `json:"ip6dns2,omitempty"`
  617. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  618. Linklocalip string `json:"linklocalip,omitempty"`
  619. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  620. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  621. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  622. Name string `json:"name,omitempty"`
  623. Networkdomain string `json:"networkdomain,omitempty"`
  624. Nic []struct {
  625. Broadcasturi string `json:"broadcasturi,omitempty"`
  626. Deviceid string `json:"deviceid,omitempty"`
  627. Gateway string `json:"gateway,omitempty"`
  628. Id string `json:"id,omitempty"`
  629. Ip6address string `json:"ip6address,omitempty"`
  630. Ip6cidr string `json:"ip6cidr,omitempty"`
  631. Ip6gateway string `json:"ip6gateway,omitempty"`
  632. Ipaddress string `json:"ipaddress,omitempty"`
  633. Isdefault bool `json:"isdefault,omitempty"`
  634. Isolationuri string `json:"isolationuri,omitempty"`
  635. Macaddress string `json:"macaddress,omitempty"`
  636. Netmask string `json:"netmask,omitempty"`
  637. Networkid string `json:"networkid,omitempty"`
  638. Networkname string `json:"networkname,omitempty"`
  639. Secondaryip []struct {
  640. Id string `json:"id,omitempty"`
  641. Ipaddress string `json:"ipaddress,omitempty"`
  642. } `json:"secondaryip,omitempty"`
  643. Traffictype string `json:"traffictype,omitempty"`
  644. Type string `json:"type,omitempty"`
  645. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  646. } `json:"nic,omitempty"`
  647. Podid string `json:"podid,omitempty"`
  648. Project string `json:"project,omitempty"`
  649. Projectid string `json:"projectid,omitempty"`
  650. Publicip string `json:"publicip,omitempty"`
  651. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  652. Publicnetmask string `json:"publicnetmask,omitempty"`
  653. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  654. Redundantstate string `json:"redundantstate,omitempty"`
  655. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  656. Role string `json:"role,omitempty"`
  657. Scriptsversion string `json:"scriptsversion,omitempty"`
  658. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  659. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  660. State string `json:"state,omitempty"`
  661. Templateid string `json:"templateid,omitempty"`
  662. Version string `json:"version,omitempty"`
  663. Vpcid string `json:"vpcid,omitempty"`
  664. Vpcname string `json:"vpcname,omitempty"`
  665. Zoneid string `json:"zoneid,omitempty"`
  666. Zonename string `json:"zonename,omitempty"`
  667. }
  668. type ListRoutersParams struct {
  669. p map[string]interface{}
  670. }
  671. func (p *ListRoutersParams) toURLValues() url.Values {
  672. u := url.Values{}
  673. if p.p == nil {
  674. return u
  675. }
  676. if v, found := p.p["account"]; found {
  677. u.Set("account", v.(string))
  678. }
  679. if v, found := p.p["clusterid"]; found {
  680. u.Set("clusterid", v.(string))
  681. }
  682. if v, found := p.p["domainid"]; found {
  683. u.Set("domainid", v.(string))
  684. }
  685. if v, found := p.p["forvpc"]; found {
  686. vv := strconv.FormatBool(v.(bool))
  687. u.Set("forvpc", vv)
  688. }
  689. if v, found := p.p["hostid"]; found {
  690. u.Set("hostid", v.(string))
  691. }
  692. if v, found := p.p["id"]; found {
  693. u.Set("id", v.(string))
  694. }
  695. if v, found := p.p["isrecursive"]; found {
  696. vv := strconv.FormatBool(v.(bool))
  697. u.Set("isrecursive", vv)
  698. }
  699. if v, found := p.p["keyword"]; found {
  700. u.Set("keyword", v.(string))
  701. }
  702. if v, found := p.p["listall"]; found {
  703. vv := strconv.FormatBool(v.(bool))
  704. u.Set("listall", vv)
  705. }
  706. if v, found := p.p["name"]; found {
  707. u.Set("name", v.(string))
  708. }
  709. if v, found := p.p["networkid"]; found {
  710. u.Set("networkid", v.(string))
  711. }
  712. if v, found := p.p["page"]; found {
  713. vv := strconv.Itoa(v.(int))
  714. u.Set("page", vv)
  715. }
  716. if v, found := p.p["pagesize"]; found {
  717. vv := strconv.Itoa(v.(int))
  718. u.Set("pagesize", vv)
  719. }
  720. if v, found := p.p["podid"]; found {
  721. u.Set("podid", v.(string))
  722. }
  723. if v, found := p.p["projectid"]; found {
  724. u.Set("projectid", v.(string))
  725. }
  726. if v, found := p.p["state"]; found {
  727. u.Set("state", v.(string))
  728. }
  729. if v, found := p.p["version"]; found {
  730. u.Set("version", v.(string))
  731. }
  732. if v, found := p.p["vpcid"]; found {
  733. u.Set("vpcid", v.(string))
  734. }
  735. if v, found := p.p["zoneid"]; found {
  736. u.Set("zoneid", v.(string))
  737. }
  738. return u
  739. }
  740. func (p *ListRoutersParams) SetAccount(v string) {
  741. if p.p == nil {
  742. p.p = make(map[string]interface{})
  743. }
  744. p.p["account"] = v
  745. return
  746. }
  747. func (p *ListRoutersParams) SetClusterid(v string) {
  748. if p.p == nil {
  749. p.p = make(map[string]interface{})
  750. }
  751. p.p["clusterid"] = v
  752. return
  753. }
  754. func (p *ListRoutersParams) SetDomainid(v string) {
  755. if p.p == nil {
  756. p.p = make(map[string]interface{})
  757. }
  758. p.p["domainid"] = v
  759. return
  760. }
  761. func (p *ListRoutersParams) SetForvpc(v bool) {
  762. if p.p == nil {
  763. p.p = make(map[string]interface{})
  764. }
  765. p.p["forvpc"] = v
  766. return
  767. }
  768. func (p *ListRoutersParams) SetHostid(v string) {
  769. if p.p == nil {
  770. p.p = make(map[string]interface{})
  771. }
  772. p.p["hostid"] = v
  773. return
  774. }
  775. func (p *ListRoutersParams) SetId(v string) {
  776. if p.p == nil {
  777. p.p = make(map[string]interface{})
  778. }
  779. p.p["id"] = v
  780. return
  781. }
  782. func (p *ListRoutersParams) SetIsrecursive(v bool) {
  783. if p.p == nil {
  784. p.p = make(map[string]interface{})
  785. }
  786. p.p["isrecursive"] = v
  787. return
  788. }
  789. func (p *ListRoutersParams) SetKeyword(v string) {
  790. if p.p == nil {
  791. p.p = make(map[string]interface{})
  792. }
  793. p.p["keyword"] = v
  794. return
  795. }
  796. func (p *ListRoutersParams) SetListall(v bool) {
  797. if p.p == nil {
  798. p.p = make(map[string]interface{})
  799. }
  800. p.p["listall"] = v
  801. return
  802. }
  803. func (p *ListRoutersParams) SetName(v string) {
  804. if p.p == nil {
  805. p.p = make(map[string]interface{})
  806. }
  807. p.p["name"] = v
  808. return
  809. }
  810. func (p *ListRoutersParams) SetNetworkid(v string) {
  811. if p.p == nil {
  812. p.p = make(map[string]interface{})
  813. }
  814. p.p["networkid"] = v
  815. return
  816. }
  817. func (p *ListRoutersParams) SetPage(v int) {
  818. if p.p == nil {
  819. p.p = make(map[string]interface{})
  820. }
  821. p.p["page"] = v
  822. return
  823. }
  824. func (p *ListRoutersParams) SetPagesize(v int) {
  825. if p.p == nil {
  826. p.p = make(map[string]interface{})
  827. }
  828. p.p["pagesize"] = v
  829. return
  830. }
  831. func (p *ListRoutersParams) SetPodid(v string) {
  832. if p.p == nil {
  833. p.p = make(map[string]interface{})
  834. }
  835. p.p["podid"] = v
  836. return
  837. }
  838. func (p *ListRoutersParams) SetProjectid(v string) {
  839. if p.p == nil {
  840. p.p = make(map[string]interface{})
  841. }
  842. p.p["projectid"] = v
  843. return
  844. }
  845. func (p *ListRoutersParams) SetState(v string) {
  846. if p.p == nil {
  847. p.p = make(map[string]interface{})
  848. }
  849. p.p["state"] = v
  850. return
  851. }
  852. func (p *ListRoutersParams) SetVersion(v string) {
  853. if p.p == nil {
  854. p.p = make(map[string]interface{})
  855. }
  856. p.p["version"] = v
  857. return
  858. }
  859. func (p *ListRoutersParams) SetVpcid(v string) {
  860. if p.p == nil {
  861. p.p = make(map[string]interface{})
  862. }
  863. p.p["vpcid"] = v
  864. return
  865. }
  866. func (p *ListRoutersParams) SetZoneid(v string) {
  867. if p.p == nil {
  868. p.p = make(map[string]interface{})
  869. }
  870. p.p["zoneid"] = v
  871. return
  872. }
  873. // You should always use this function to get a new ListRoutersParams instance,
  874. // as then you are sure you have configured all required params
  875. func (s *RouterService) NewListRoutersParams() *ListRoutersParams {
  876. p := &ListRoutersParams{}
  877. p.p = make(map[string]interface{})
  878. return p
  879. }
  880. // This is a courtesy helper function, which in some cases may not work as expected!
  881. func (s *RouterService) GetRouterID(name string, opts ...OptionFunc) (string, int, error) {
  882. p := &ListRoutersParams{}
  883. p.p = make(map[string]interface{})
  884. p.p["name"] = name
  885. for _, fn := range opts {
  886. if err := fn(s.cs, p); err != nil {
  887. return "", -1, err
  888. }
  889. }
  890. l, err := s.ListRouters(p)
  891. if err != nil {
  892. return "", -1, err
  893. }
  894. if l.Count == 0 {
  895. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  896. }
  897. if l.Count == 1 {
  898. return l.Routers[0].Id, l.Count, nil
  899. }
  900. if l.Count > 1 {
  901. for _, v := range l.Routers {
  902. if v.Name == name {
  903. return v.Id, l.Count, nil
  904. }
  905. }
  906. }
  907. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  908. }
  909. // This is a courtesy helper function, which in some cases may not work as expected!
  910. func (s *RouterService) GetRouterByName(name string, opts ...OptionFunc) (*Router, int, error) {
  911. id, count, err := s.GetRouterID(name, opts...)
  912. if err != nil {
  913. return nil, count, err
  914. }
  915. r, count, err := s.GetRouterByID(id, opts...)
  916. if err != nil {
  917. return nil, count, err
  918. }
  919. return r, count, nil
  920. }
  921. // This is a courtesy helper function, which in some cases may not work as expected!
  922. func (s *RouterService) GetRouterByID(id string, opts ...OptionFunc) (*Router, int, error) {
  923. p := &ListRoutersParams{}
  924. p.p = make(map[string]interface{})
  925. p.p["id"] = id
  926. for _, fn := range opts {
  927. if err := fn(s.cs, p); err != nil {
  928. return nil, -1, err
  929. }
  930. }
  931. l, err := s.ListRouters(p)
  932. if err != nil {
  933. if strings.Contains(err.Error(), fmt.Sprintf(
  934. "Invalid parameter id value=%s due to incorrect long value format, "+
  935. "or entity does not exist", id)) {
  936. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  937. }
  938. return nil, -1, err
  939. }
  940. if l.Count == 0 {
  941. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  942. }
  943. if l.Count == 1 {
  944. return l.Routers[0], l.Count, nil
  945. }
  946. return nil, l.Count, fmt.Errorf("There is more then one result for Router UUID: %s!", id)
  947. }
  948. // List routers.
  949. func (s *RouterService) ListRouters(p *ListRoutersParams) (*ListRoutersResponse, error) {
  950. resp, err := s.cs.newRequest("listRouters", p.toURLValues())
  951. if err != nil {
  952. return nil, err
  953. }
  954. var r ListRoutersResponse
  955. if err := json.Unmarshal(resp, &r); err != nil {
  956. return nil, err
  957. }
  958. return &r, nil
  959. }
  960. type ListRoutersResponse struct {
  961. Count int `json:"count"`
  962. Routers []*Router `json:"router"`
  963. }
  964. type Router struct {
  965. Account string `json:"account,omitempty"`
  966. Created string `json:"created,omitempty"`
  967. Dns1 string `json:"dns1,omitempty"`
  968. Dns2 string `json:"dns2,omitempty"`
  969. Domain string `json:"domain,omitempty"`
  970. Domainid string `json:"domainid,omitempty"`
  971. Gateway string `json:"gateway,omitempty"`
  972. Guestipaddress string `json:"guestipaddress,omitempty"`
  973. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  974. Guestnetmask string `json:"guestnetmask,omitempty"`
  975. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  976. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  977. Hostid string `json:"hostid,omitempty"`
  978. Hostname string `json:"hostname,omitempty"`
  979. Hypervisor string `json:"hypervisor,omitempty"`
  980. Id string `json:"id,omitempty"`
  981. Ip6dns1 string `json:"ip6dns1,omitempty"`
  982. Ip6dns2 string `json:"ip6dns2,omitempty"`
  983. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  984. Linklocalip string `json:"linklocalip,omitempty"`
  985. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  986. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  987. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  988. Name string `json:"name,omitempty"`
  989. Networkdomain string `json:"networkdomain,omitempty"`
  990. Nic []struct {
  991. Broadcasturi string `json:"broadcasturi,omitempty"`
  992. Deviceid string `json:"deviceid,omitempty"`
  993. Gateway string `json:"gateway,omitempty"`
  994. Id string `json:"id,omitempty"`
  995. Ip6address string `json:"ip6address,omitempty"`
  996. Ip6cidr string `json:"ip6cidr,omitempty"`
  997. Ip6gateway string `json:"ip6gateway,omitempty"`
  998. Ipaddress string `json:"ipaddress,omitempty"`
  999. Isdefault bool `json:"isdefault,omitempty"`
  1000. Isolationuri string `json:"isolationuri,omitempty"`
  1001. Macaddress string `json:"macaddress,omitempty"`
  1002. Netmask string `json:"netmask,omitempty"`
  1003. Networkid string `json:"networkid,omitempty"`
  1004. Networkname string `json:"networkname,omitempty"`
  1005. Secondaryip []struct {
  1006. Id string `json:"id,omitempty"`
  1007. Ipaddress string `json:"ipaddress,omitempty"`
  1008. } `json:"secondaryip,omitempty"`
  1009. Traffictype string `json:"traffictype,omitempty"`
  1010. Type string `json:"type,omitempty"`
  1011. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  1012. } `json:"nic,omitempty"`
  1013. Podid string `json:"podid,omitempty"`
  1014. Project string `json:"project,omitempty"`
  1015. Projectid string `json:"projectid,omitempty"`
  1016. Publicip string `json:"publicip,omitempty"`
  1017. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  1018. Publicnetmask string `json:"publicnetmask,omitempty"`
  1019. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  1020. Redundantstate string `json:"redundantstate,omitempty"`
  1021. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  1022. Role string `json:"role,omitempty"`
  1023. Scriptsversion string `json:"scriptsversion,omitempty"`
  1024. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  1025. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  1026. State string `json:"state,omitempty"`
  1027. Templateid string `json:"templateid,omitempty"`
  1028. Version string `json:"version,omitempty"`
  1029. Vpcid string `json:"vpcid,omitempty"`
  1030. Vpcname string `json:"vpcname,omitempty"`
  1031. Zoneid string `json:"zoneid,omitempty"`
  1032. Zonename string `json:"zonename,omitempty"`
  1033. }
  1034. type ListVirtualRouterElementsParams struct {
  1035. p map[string]interface{}
  1036. }
  1037. func (p *ListVirtualRouterElementsParams) toURLValues() url.Values {
  1038. u := url.Values{}
  1039. if p.p == nil {
  1040. return u
  1041. }
  1042. if v, found := p.p["enabled"]; found {
  1043. vv := strconv.FormatBool(v.(bool))
  1044. u.Set("enabled", vv)
  1045. }
  1046. if v, found := p.p["id"]; found {
  1047. u.Set("id", v.(string))
  1048. }
  1049. if v, found := p.p["keyword"]; found {
  1050. u.Set("keyword", v.(string))
  1051. }
  1052. if v, found := p.p["nspid"]; found {
  1053. u.Set("nspid", v.(string))
  1054. }
  1055. if v, found := p.p["page"]; found {
  1056. vv := strconv.Itoa(v.(int))
  1057. u.Set("page", vv)
  1058. }
  1059. if v, found := p.p["pagesize"]; found {
  1060. vv := strconv.Itoa(v.(int))
  1061. u.Set("pagesize", vv)
  1062. }
  1063. return u
  1064. }
  1065. func (p *ListVirtualRouterElementsParams) SetEnabled(v bool) {
  1066. if p.p == nil {
  1067. p.p = make(map[string]interface{})
  1068. }
  1069. p.p["enabled"] = v
  1070. return
  1071. }
  1072. func (p *ListVirtualRouterElementsParams) SetId(v string) {
  1073. if p.p == nil {
  1074. p.p = make(map[string]interface{})
  1075. }
  1076. p.p["id"] = v
  1077. return
  1078. }
  1079. func (p *ListVirtualRouterElementsParams) SetKeyword(v string) {
  1080. if p.p == nil {
  1081. p.p = make(map[string]interface{})
  1082. }
  1083. p.p["keyword"] = v
  1084. return
  1085. }
  1086. func (p *ListVirtualRouterElementsParams) SetNspid(v string) {
  1087. if p.p == nil {
  1088. p.p = make(map[string]interface{})
  1089. }
  1090. p.p["nspid"] = v
  1091. return
  1092. }
  1093. func (p *ListVirtualRouterElementsParams) SetPage(v int) {
  1094. if p.p == nil {
  1095. p.p = make(map[string]interface{})
  1096. }
  1097. p.p["page"] = v
  1098. return
  1099. }
  1100. func (p *ListVirtualRouterElementsParams) SetPagesize(v int) {
  1101. if p.p == nil {
  1102. p.p = make(map[string]interface{})
  1103. }
  1104. p.p["pagesize"] = v
  1105. return
  1106. }
  1107. // You should always use this function to get a new ListVirtualRouterElementsParams instance,
  1108. // as then you are sure you have configured all required params
  1109. func (s *RouterService) NewListVirtualRouterElementsParams() *ListVirtualRouterElementsParams {
  1110. p := &ListVirtualRouterElementsParams{}
  1111. p.p = make(map[string]interface{})
  1112. return p
  1113. }
  1114. // This is a courtesy helper function, which in some cases may not work as expected!
  1115. func (s *RouterService) GetVirtualRouterElementByID(id string, opts ...OptionFunc) (*VirtualRouterElement, int, error) {
  1116. p := &ListVirtualRouterElementsParams{}
  1117. p.p = make(map[string]interface{})
  1118. p.p["id"] = id
  1119. for _, fn := range opts {
  1120. if err := fn(s.cs, p); err != nil {
  1121. return nil, -1, err
  1122. }
  1123. }
  1124. l, err := s.ListVirtualRouterElements(p)
  1125. if err != nil {
  1126. if strings.Contains(err.Error(), fmt.Sprintf(
  1127. "Invalid parameter id value=%s due to incorrect long value format, "+
  1128. "or entity does not exist", id)) {
  1129. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1130. }
  1131. return nil, -1, err
  1132. }
  1133. if l.Count == 0 {
  1134. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1135. }
  1136. if l.Count == 1 {
  1137. return l.VirtualRouterElements[0], l.Count, nil
  1138. }
  1139. return nil, l.Count, fmt.Errorf("There is more then one result for VirtualRouterElement UUID: %s!", id)
  1140. }
  1141. // Lists all available virtual router elements.
  1142. func (s *RouterService) ListVirtualRouterElements(p *ListVirtualRouterElementsParams) (*ListVirtualRouterElementsResponse, error) {
  1143. resp, err := s.cs.newRequest("listVirtualRouterElements", p.toURLValues())
  1144. if err != nil {
  1145. return nil, err
  1146. }
  1147. var r ListVirtualRouterElementsResponse
  1148. if err := json.Unmarshal(resp, &r); err != nil {
  1149. return nil, err
  1150. }
  1151. return &r, nil
  1152. }
  1153. type ListVirtualRouterElementsResponse struct {
  1154. Count int `json:"count"`
  1155. VirtualRouterElements []*VirtualRouterElement `json:"virtualrouterelement"`
  1156. }
  1157. type VirtualRouterElement struct {
  1158. Account string `json:"account,omitempty"`
  1159. Domain string `json:"domain,omitempty"`
  1160. Domainid string `json:"domainid,omitempty"`
  1161. Enabled bool `json:"enabled,omitempty"`
  1162. Id string `json:"id,omitempty"`
  1163. Nspid string `json:"nspid,omitempty"`
  1164. Project string `json:"project,omitempty"`
  1165. Projectid string `json:"projectid,omitempty"`
  1166. }
  1167. type ConfigureVirtualRouterElementParams struct {
  1168. p map[string]interface{}
  1169. }
  1170. func (p *ConfigureVirtualRouterElementParams) toURLValues() url.Values {
  1171. u := url.Values{}
  1172. if p.p == nil {
  1173. return u
  1174. }
  1175. if v, found := p.p["enabled"]; found {
  1176. vv := strconv.FormatBool(v.(bool))
  1177. u.Set("enabled", vv)
  1178. }
  1179. if v, found := p.p["id"]; found {
  1180. u.Set("id", v.(string))
  1181. }
  1182. return u
  1183. }
  1184. func (p *ConfigureVirtualRouterElementParams) SetEnabled(v bool) {
  1185. if p.p == nil {
  1186. p.p = make(map[string]interface{})
  1187. }
  1188. p.p["enabled"] = v
  1189. return
  1190. }
  1191. func (p *ConfigureVirtualRouterElementParams) SetId(v string) {
  1192. if p.p == nil {
  1193. p.p = make(map[string]interface{})
  1194. }
  1195. p.p["id"] = v
  1196. return
  1197. }
  1198. // You should always use this function to get a new ConfigureVirtualRouterElementParams instance,
  1199. // as then you are sure you have configured all required params
  1200. func (s *RouterService) NewConfigureVirtualRouterElementParams(enabled bool, id string) *ConfigureVirtualRouterElementParams {
  1201. p := &ConfigureVirtualRouterElementParams{}
  1202. p.p = make(map[string]interface{})
  1203. p.p["enabled"] = enabled
  1204. p.p["id"] = id
  1205. return p
  1206. }
  1207. // Configures a virtual router element.
  1208. func (s *RouterService) ConfigureVirtualRouterElement(p *ConfigureVirtualRouterElementParams) (*ConfigureVirtualRouterElementResponse, error) {
  1209. resp, err := s.cs.newRequest("configureVirtualRouterElement", p.toURLValues())
  1210. if err != nil {
  1211. return nil, err
  1212. }
  1213. var r ConfigureVirtualRouterElementResponse
  1214. if err := json.Unmarshal(resp, &r); err != nil {
  1215. return nil, err
  1216. }
  1217. // If we have a async client, we need to wait for the async result
  1218. if s.cs.async {
  1219. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1220. if err != nil {
  1221. if err == AsyncTimeoutErr {
  1222. return &r, err
  1223. }
  1224. return nil, err
  1225. }
  1226. b, err = getRawValue(b)
  1227. if err != nil {
  1228. return nil, err
  1229. }
  1230. if err := json.Unmarshal(b, &r); err != nil {
  1231. return nil, err
  1232. }
  1233. }
  1234. return &r, nil
  1235. }
  1236. type ConfigureVirtualRouterElementResponse struct {
  1237. JobID string `json:"jobid,omitempty"`
  1238. Account string `json:"account,omitempty"`
  1239. Domain string `json:"domain,omitempty"`
  1240. Domainid string `json:"domainid,omitempty"`
  1241. Enabled bool `json:"enabled,omitempty"`
  1242. Id string `json:"id,omitempty"`
  1243. Nspid string `json:"nspid,omitempty"`
  1244. Project string `json:"project,omitempty"`
  1245. Projectid string `json:"projectid,omitempty"`
  1246. }
  1247. type CreateVirtualRouterElementParams struct {
  1248. p map[string]interface{}
  1249. }
  1250. func (p *CreateVirtualRouterElementParams) toURLValues() url.Values {
  1251. u := url.Values{}
  1252. if p.p == nil {
  1253. return u
  1254. }
  1255. if v, found := p.p["nspid"]; found {
  1256. u.Set("nspid", v.(string))
  1257. }
  1258. if v, found := p.p["providertype"]; found {
  1259. u.Set("providertype", v.(string))
  1260. }
  1261. return u
  1262. }
  1263. func (p *CreateVirtualRouterElementParams) SetNspid(v string) {
  1264. if p.p == nil {
  1265. p.p = make(map[string]interface{})
  1266. }
  1267. p.p["nspid"] = v
  1268. return
  1269. }
  1270. func (p *CreateVirtualRouterElementParams) SetProvidertype(v string) {
  1271. if p.p == nil {
  1272. p.p = make(map[string]interface{})
  1273. }
  1274. p.p["providertype"] = v
  1275. return
  1276. }
  1277. // You should always use this function to get a new CreateVirtualRouterElementParams instance,
  1278. // as then you are sure you have configured all required params
  1279. func (s *RouterService) NewCreateVirtualRouterElementParams(nspid string) *CreateVirtualRouterElementParams {
  1280. p := &CreateVirtualRouterElementParams{}
  1281. p.p = make(map[string]interface{})
  1282. p.p["nspid"] = nspid
  1283. return p
  1284. }
  1285. // Create a virtual router element.
  1286. func (s *RouterService) CreateVirtualRouterElement(p *CreateVirtualRouterElementParams) (*CreateVirtualRouterElementResponse, error) {
  1287. resp, err := s.cs.newRequest("createVirtualRouterElement", p.toURLValues())
  1288. if err != nil {
  1289. return nil, err
  1290. }
  1291. var r CreateVirtualRouterElementResponse
  1292. if err := json.Unmarshal(resp, &r); err != nil {
  1293. return nil, err
  1294. }
  1295. // If we have a async client, we need to wait for the async result
  1296. if s.cs.async {
  1297. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1298. if err != nil {
  1299. if err == AsyncTimeoutErr {
  1300. return &r, err
  1301. }
  1302. return nil, err
  1303. }
  1304. b, err = getRawValue(b)
  1305. if err != nil {
  1306. return nil, err
  1307. }
  1308. if err := json.Unmarshal(b, &r); err != nil {
  1309. return nil, err
  1310. }
  1311. }
  1312. return &r, nil
  1313. }
  1314. type CreateVirtualRouterElementResponse struct {
  1315. JobID string `json:"jobid,omitempty"`
  1316. Account string `json:"account,omitempty"`
  1317. Domain string `json:"domain,omitempty"`
  1318. Domainid string `json:"domainid,omitempty"`
  1319. Enabled bool `json:"enabled,omitempty"`
  1320. Id string `json:"id,omitempty"`
  1321. Nspid string `json:"nspid,omitempty"`
  1322. Project string `json:"project,omitempty"`
  1323. Projectid string `json:"projectid,omitempty"`
  1324. }