InternalLBService.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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 ConfigureInternalLoadBalancerElementParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *ConfigureInternalLoadBalancerElementParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["enabled"]; found {
  33. vv := strconv.FormatBool(v.(bool))
  34. u.Set("enabled", vv)
  35. }
  36. if v, found := p.p["id"]; found {
  37. u.Set("id", v.(string))
  38. }
  39. return u
  40. }
  41. func (p *ConfigureInternalLoadBalancerElementParams) SetEnabled(v bool) {
  42. if p.p == nil {
  43. p.p = make(map[string]interface{})
  44. }
  45. p.p["enabled"] = v
  46. return
  47. }
  48. func (p *ConfigureInternalLoadBalancerElementParams) SetId(v string) {
  49. if p.p == nil {
  50. p.p = make(map[string]interface{})
  51. }
  52. p.p["id"] = v
  53. return
  54. }
  55. // You should always use this function to get a new ConfigureInternalLoadBalancerElementParams instance,
  56. // as then you are sure you have configured all required params
  57. func (s *InternalLBService) NewConfigureInternalLoadBalancerElementParams(enabled bool, id string) *ConfigureInternalLoadBalancerElementParams {
  58. p := &ConfigureInternalLoadBalancerElementParams{}
  59. p.p = make(map[string]interface{})
  60. p.p["enabled"] = enabled
  61. p.p["id"] = id
  62. return p
  63. }
  64. // Configures an Internal Load Balancer element.
  65. func (s *InternalLBService) ConfigureInternalLoadBalancerElement(p *ConfigureInternalLoadBalancerElementParams) (*ConfigureInternalLoadBalancerElementResponse, error) {
  66. resp, err := s.cs.newRequest("configureInternalLoadBalancerElement", p.toURLValues())
  67. if err != nil {
  68. return nil, err
  69. }
  70. var r ConfigureInternalLoadBalancerElementResponse
  71. if err := json.Unmarshal(resp, &r); err != nil {
  72. return nil, err
  73. }
  74. // If we have a async client, we need to wait for the async result
  75. if s.cs.async {
  76. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  77. if err != nil {
  78. if err == AsyncTimeoutErr {
  79. return &r, err
  80. }
  81. return nil, err
  82. }
  83. b, err = getRawValue(b)
  84. if err != nil {
  85. return nil, err
  86. }
  87. if err := json.Unmarshal(b, &r); err != nil {
  88. return nil, err
  89. }
  90. }
  91. return &r, nil
  92. }
  93. type ConfigureInternalLoadBalancerElementResponse struct {
  94. JobID string `json:"jobid,omitempty"`
  95. Enabled bool `json:"enabled,omitempty"`
  96. Id string `json:"id,omitempty"`
  97. Nspid string `json:"nspid,omitempty"`
  98. }
  99. type CreateInternalLoadBalancerElementParams struct {
  100. p map[string]interface{}
  101. }
  102. func (p *CreateInternalLoadBalancerElementParams) toURLValues() url.Values {
  103. u := url.Values{}
  104. if p.p == nil {
  105. return u
  106. }
  107. if v, found := p.p["nspid"]; found {
  108. u.Set("nspid", v.(string))
  109. }
  110. return u
  111. }
  112. func (p *CreateInternalLoadBalancerElementParams) SetNspid(v string) {
  113. if p.p == nil {
  114. p.p = make(map[string]interface{})
  115. }
  116. p.p["nspid"] = v
  117. return
  118. }
  119. // You should always use this function to get a new CreateInternalLoadBalancerElementParams instance,
  120. // as then you are sure you have configured all required params
  121. func (s *InternalLBService) NewCreateInternalLoadBalancerElementParams(nspid string) *CreateInternalLoadBalancerElementParams {
  122. p := &CreateInternalLoadBalancerElementParams{}
  123. p.p = make(map[string]interface{})
  124. p.p["nspid"] = nspid
  125. return p
  126. }
  127. // Create an Internal Load Balancer element.
  128. func (s *InternalLBService) CreateInternalLoadBalancerElement(p *CreateInternalLoadBalancerElementParams) (*CreateInternalLoadBalancerElementResponse, error) {
  129. resp, err := s.cs.newRequest("createInternalLoadBalancerElement", p.toURLValues())
  130. if err != nil {
  131. return nil, err
  132. }
  133. var r CreateInternalLoadBalancerElementResponse
  134. if err := json.Unmarshal(resp, &r); err != nil {
  135. return nil, err
  136. }
  137. // If we have a async client, we need to wait for the async result
  138. if s.cs.async {
  139. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  140. if err != nil {
  141. if err == AsyncTimeoutErr {
  142. return &r, err
  143. }
  144. return nil, err
  145. }
  146. b, err = getRawValue(b)
  147. if err != nil {
  148. return nil, err
  149. }
  150. if err := json.Unmarshal(b, &r); err != nil {
  151. return nil, err
  152. }
  153. }
  154. return &r, nil
  155. }
  156. type CreateInternalLoadBalancerElementResponse struct {
  157. JobID string `json:"jobid,omitempty"`
  158. Enabled bool `json:"enabled,omitempty"`
  159. Id string `json:"id,omitempty"`
  160. Nspid string `json:"nspid,omitempty"`
  161. }
  162. type ListInternalLoadBalancerElementsParams struct {
  163. p map[string]interface{}
  164. }
  165. func (p *ListInternalLoadBalancerElementsParams) toURLValues() url.Values {
  166. u := url.Values{}
  167. if p.p == nil {
  168. return u
  169. }
  170. if v, found := p.p["enabled"]; found {
  171. vv := strconv.FormatBool(v.(bool))
  172. u.Set("enabled", vv)
  173. }
  174. if v, found := p.p["id"]; found {
  175. u.Set("id", v.(string))
  176. }
  177. if v, found := p.p["keyword"]; found {
  178. u.Set("keyword", v.(string))
  179. }
  180. if v, found := p.p["nspid"]; found {
  181. u.Set("nspid", v.(string))
  182. }
  183. if v, found := p.p["page"]; found {
  184. vv := strconv.Itoa(v.(int))
  185. u.Set("page", vv)
  186. }
  187. if v, found := p.p["pagesize"]; found {
  188. vv := strconv.Itoa(v.(int))
  189. u.Set("pagesize", vv)
  190. }
  191. return u
  192. }
  193. func (p *ListInternalLoadBalancerElementsParams) SetEnabled(v bool) {
  194. if p.p == nil {
  195. p.p = make(map[string]interface{})
  196. }
  197. p.p["enabled"] = v
  198. return
  199. }
  200. func (p *ListInternalLoadBalancerElementsParams) SetId(v string) {
  201. if p.p == nil {
  202. p.p = make(map[string]interface{})
  203. }
  204. p.p["id"] = v
  205. return
  206. }
  207. func (p *ListInternalLoadBalancerElementsParams) SetKeyword(v string) {
  208. if p.p == nil {
  209. p.p = make(map[string]interface{})
  210. }
  211. p.p["keyword"] = v
  212. return
  213. }
  214. func (p *ListInternalLoadBalancerElementsParams) SetNspid(v string) {
  215. if p.p == nil {
  216. p.p = make(map[string]interface{})
  217. }
  218. p.p["nspid"] = v
  219. return
  220. }
  221. func (p *ListInternalLoadBalancerElementsParams) SetPage(v int) {
  222. if p.p == nil {
  223. p.p = make(map[string]interface{})
  224. }
  225. p.p["page"] = v
  226. return
  227. }
  228. func (p *ListInternalLoadBalancerElementsParams) SetPagesize(v int) {
  229. if p.p == nil {
  230. p.p = make(map[string]interface{})
  231. }
  232. p.p["pagesize"] = v
  233. return
  234. }
  235. // You should always use this function to get a new ListInternalLoadBalancerElementsParams instance,
  236. // as then you are sure you have configured all required params
  237. func (s *InternalLBService) NewListInternalLoadBalancerElementsParams() *ListInternalLoadBalancerElementsParams {
  238. p := &ListInternalLoadBalancerElementsParams{}
  239. p.p = make(map[string]interface{})
  240. return p
  241. }
  242. // This is a courtesy helper function, which in some cases may not work as expected!
  243. func (s *InternalLBService) GetInternalLoadBalancerElementByID(id string, opts ...OptionFunc) (*InternalLoadBalancerElement, int, error) {
  244. p := &ListInternalLoadBalancerElementsParams{}
  245. p.p = make(map[string]interface{})
  246. p.p["id"] = id
  247. for _, fn := range opts {
  248. if err := fn(s.cs, p); err != nil {
  249. return nil, -1, err
  250. }
  251. }
  252. l, err := s.ListInternalLoadBalancerElements(p)
  253. if err != nil {
  254. if strings.Contains(err.Error(), fmt.Sprintf(
  255. "Invalid parameter id value=%s due to incorrect long value format, "+
  256. "or entity does not exist", id)) {
  257. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  258. }
  259. return nil, -1, err
  260. }
  261. if l.Count == 0 {
  262. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  263. }
  264. if l.Count == 1 {
  265. return l.InternalLoadBalancerElements[0], l.Count, nil
  266. }
  267. return nil, l.Count, fmt.Errorf("There is more then one result for InternalLoadBalancerElement UUID: %s!", id)
  268. }
  269. // Lists all available Internal Load Balancer elements.
  270. func (s *InternalLBService) ListInternalLoadBalancerElements(p *ListInternalLoadBalancerElementsParams) (*ListInternalLoadBalancerElementsResponse, error) {
  271. resp, err := s.cs.newRequest("listInternalLoadBalancerElements", p.toURLValues())
  272. if err != nil {
  273. return nil, err
  274. }
  275. var r ListInternalLoadBalancerElementsResponse
  276. if err := json.Unmarshal(resp, &r); err != nil {
  277. return nil, err
  278. }
  279. return &r, nil
  280. }
  281. type ListInternalLoadBalancerElementsResponse struct {
  282. Count int `json:"count"`
  283. InternalLoadBalancerElements []*InternalLoadBalancerElement `json:"internalloadbalancerelement"`
  284. }
  285. type InternalLoadBalancerElement struct {
  286. Enabled bool `json:"enabled,omitempty"`
  287. Id string `json:"id,omitempty"`
  288. Nspid string `json:"nspid,omitempty"`
  289. }
  290. type StopInternalLoadBalancerVMParams struct {
  291. p map[string]interface{}
  292. }
  293. func (p *StopInternalLoadBalancerVMParams) toURLValues() url.Values {
  294. u := url.Values{}
  295. if p.p == nil {
  296. return u
  297. }
  298. if v, found := p.p["forced"]; found {
  299. vv := strconv.FormatBool(v.(bool))
  300. u.Set("forced", vv)
  301. }
  302. if v, found := p.p["id"]; found {
  303. u.Set("id", v.(string))
  304. }
  305. return u
  306. }
  307. func (p *StopInternalLoadBalancerVMParams) SetForced(v bool) {
  308. if p.p == nil {
  309. p.p = make(map[string]interface{})
  310. }
  311. p.p["forced"] = v
  312. return
  313. }
  314. func (p *StopInternalLoadBalancerVMParams) SetId(v string) {
  315. if p.p == nil {
  316. p.p = make(map[string]interface{})
  317. }
  318. p.p["id"] = v
  319. return
  320. }
  321. // You should always use this function to get a new StopInternalLoadBalancerVMParams instance,
  322. // as then you are sure you have configured all required params
  323. func (s *InternalLBService) NewStopInternalLoadBalancerVMParams(id string) *StopInternalLoadBalancerVMParams {
  324. p := &StopInternalLoadBalancerVMParams{}
  325. p.p = make(map[string]interface{})
  326. p.p["id"] = id
  327. return p
  328. }
  329. // Stops an Internal LB vm.
  330. func (s *InternalLBService) StopInternalLoadBalancerVM(p *StopInternalLoadBalancerVMParams) (*StopInternalLoadBalancerVMResponse, error) {
  331. resp, err := s.cs.newRequest("stopInternalLoadBalancerVM", p.toURLValues())
  332. if err != nil {
  333. return nil, err
  334. }
  335. var r StopInternalLoadBalancerVMResponse
  336. if err := json.Unmarshal(resp, &r); err != nil {
  337. return nil, err
  338. }
  339. // If we have a async client, we need to wait for the async result
  340. if s.cs.async {
  341. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  342. if err != nil {
  343. if err == AsyncTimeoutErr {
  344. return &r, err
  345. }
  346. return nil, err
  347. }
  348. b, err = getRawValue(b)
  349. if err != nil {
  350. return nil, err
  351. }
  352. if err := json.Unmarshal(b, &r); err != nil {
  353. return nil, err
  354. }
  355. }
  356. return &r, nil
  357. }
  358. type StopInternalLoadBalancerVMResponse struct {
  359. JobID string `json:"jobid,omitempty"`
  360. Account string `json:"account,omitempty"`
  361. Created string `json:"created,omitempty"`
  362. Dns1 string `json:"dns1,omitempty"`
  363. Dns2 string `json:"dns2,omitempty"`
  364. Domain string `json:"domain,omitempty"`
  365. Domainid string `json:"domainid,omitempty"`
  366. Gateway string `json:"gateway,omitempty"`
  367. Guestipaddress string `json:"guestipaddress,omitempty"`
  368. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  369. Guestnetmask string `json:"guestnetmask,omitempty"`
  370. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  371. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  372. Hostid string `json:"hostid,omitempty"`
  373. Hostname string `json:"hostname,omitempty"`
  374. Hypervisor string `json:"hypervisor,omitempty"`
  375. Id string `json:"id,omitempty"`
  376. Ip6dns1 string `json:"ip6dns1,omitempty"`
  377. Ip6dns2 string `json:"ip6dns2,omitempty"`
  378. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  379. Linklocalip string `json:"linklocalip,omitempty"`
  380. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  381. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  382. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  383. Name string `json:"name,omitempty"`
  384. Networkdomain string `json:"networkdomain,omitempty"`
  385. Nic []struct {
  386. Broadcasturi string `json:"broadcasturi,omitempty"`
  387. Deviceid string `json:"deviceid,omitempty"`
  388. Gateway string `json:"gateway,omitempty"`
  389. Id string `json:"id,omitempty"`
  390. Ip6address string `json:"ip6address,omitempty"`
  391. Ip6cidr string `json:"ip6cidr,omitempty"`
  392. Ip6gateway string `json:"ip6gateway,omitempty"`
  393. Ipaddress string `json:"ipaddress,omitempty"`
  394. Isdefault bool `json:"isdefault,omitempty"`
  395. Isolationuri string `json:"isolationuri,omitempty"`
  396. Macaddress string `json:"macaddress,omitempty"`
  397. Netmask string `json:"netmask,omitempty"`
  398. Networkid string `json:"networkid,omitempty"`
  399. Networkname string `json:"networkname,omitempty"`
  400. Secondaryip []struct {
  401. Id string `json:"id,omitempty"`
  402. Ipaddress string `json:"ipaddress,omitempty"`
  403. } `json:"secondaryip,omitempty"`
  404. Traffictype string `json:"traffictype,omitempty"`
  405. Type string `json:"type,omitempty"`
  406. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  407. } `json:"nic,omitempty"`
  408. Podid string `json:"podid,omitempty"`
  409. Project string `json:"project,omitempty"`
  410. Projectid string `json:"projectid,omitempty"`
  411. Publicip string `json:"publicip,omitempty"`
  412. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  413. Publicnetmask string `json:"publicnetmask,omitempty"`
  414. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  415. Redundantstate string `json:"redundantstate,omitempty"`
  416. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  417. Role string `json:"role,omitempty"`
  418. Scriptsversion string `json:"scriptsversion,omitempty"`
  419. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  420. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  421. State string `json:"state,omitempty"`
  422. Templateid string `json:"templateid,omitempty"`
  423. Version string `json:"version,omitempty"`
  424. Vpcid string `json:"vpcid,omitempty"`
  425. Vpcname string `json:"vpcname,omitempty"`
  426. Zoneid string `json:"zoneid,omitempty"`
  427. Zonename string `json:"zonename,omitempty"`
  428. }
  429. type StartInternalLoadBalancerVMParams struct {
  430. p map[string]interface{}
  431. }
  432. func (p *StartInternalLoadBalancerVMParams) toURLValues() url.Values {
  433. u := url.Values{}
  434. if p.p == nil {
  435. return u
  436. }
  437. if v, found := p.p["id"]; found {
  438. u.Set("id", v.(string))
  439. }
  440. return u
  441. }
  442. func (p *StartInternalLoadBalancerVMParams) SetId(v string) {
  443. if p.p == nil {
  444. p.p = make(map[string]interface{})
  445. }
  446. p.p["id"] = v
  447. return
  448. }
  449. // You should always use this function to get a new StartInternalLoadBalancerVMParams instance,
  450. // as then you are sure you have configured all required params
  451. func (s *InternalLBService) NewStartInternalLoadBalancerVMParams(id string) *StartInternalLoadBalancerVMParams {
  452. p := &StartInternalLoadBalancerVMParams{}
  453. p.p = make(map[string]interface{})
  454. p.p["id"] = id
  455. return p
  456. }
  457. // Starts an existing internal lb vm.
  458. func (s *InternalLBService) StartInternalLoadBalancerVM(p *StartInternalLoadBalancerVMParams) (*StartInternalLoadBalancerVMResponse, error) {
  459. resp, err := s.cs.newRequest("startInternalLoadBalancerVM", p.toURLValues())
  460. if err != nil {
  461. return nil, err
  462. }
  463. var r StartInternalLoadBalancerVMResponse
  464. if err := json.Unmarshal(resp, &r); err != nil {
  465. return nil, err
  466. }
  467. // If we have a async client, we need to wait for the async result
  468. if s.cs.async {
  469. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  470. if err != nil {
  471. if err == AsyncTimeoutErr {
  472. return &r, err
  473. }
  474. return nil, err
  475. }
  476. b, err = getRawValue(b)
  477. if err != nil {
  478. return nil, err
  479. }
  480. if err := json.Unmarshal(b, &r); err != nil {
  481. return nil, err
  482. }
  483. }
  484. return &r, nil
  485. }
  486. type StartInternalLoadBalancerVMResponse struct {
  487. JobID string `json:"jobid,omitempty"`
  488. Account string `json:"account,omitempty"`
  489. Created string `json:"created,omitempty"`
  490. Dns1 string `json:"dns1,omitempty"`
  491. Dns2 string `json:"dns2,omitempty"`
  492. Domain string `json:"domain,omitempty"`
  493. Domainid string `json:"domainid,omitempty"`
  494. Gateway string `json:"gateway,omitempty"`
  495. Guestipaddress string `json:"guestipaddress,omitempty"`
  496. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  497. Guestnetmask string `json:"guestnetmask,omitempty"`
  498. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  499. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  500. Hostid string `json:"hostid,omitempty"`
  501. Hostname string `json:"hostname,omitempty"`
  502. Hypervisor string `json:"hypervisor,omitempty"`
  503. Id string `json:"id,omitempty"`
  504. Ip6dns1 string `json:"ip6dns1,omitempty"`
  505. Ip6dns2 string `json:"ip6dns2,omitempty"`
  506. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  507. Linklocalip string `json:"linklocalip,omitempty"`
  508. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  509. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  510. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  511. Name string `json:"name,omitempty"`
  512. Networkdomain string `json:"networkdomain,omitempty"`
  513. Nic []struct {
  514. Broadcasturi string `json:"broadcasturi,omitempty"`
  515. Deviceid string `json:"deviceid,omitempty"`
  516. Gateway string `json:"gateway,omitempty"`
  517. Id string `json:"id,omitempty"`
  518. Ip6address string `json:"ip6address,omitempty"`
  519. Ip6cidr string `json:"ip6cidr,omitempty"`
  520. Ip6gateway string `json:"ip6gateway,omitempty"`
  521. Ipaddress string `json:"ipaddress,omitempty"`
  522. Isdefault bool `json:"isdefault,omitempty"`
  523. Isolationuri string `json:"isolationuri,omitempty"`
  524. Macaddress string `json:"macaddress,omitempty"`
  525. Netmask string `json:"netmask,omitempty"`
  526. Networkid string `json:"networkid,omitempty"`
  527. Networkname string `json:"networkname,omitempty"`
  528. Secondaryip []struct {
  529. Id string `json:"id,omitempty"`
  530. Ipaddress string `json:"ipaddress,omitempty"`
  531. } `json:"secondaryip,omitempty"`
  532. Traffictype string `json:"traffictype,omitempty"`
  533. Type string `json:"type,omitempty"`
  534. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  535. } `json:"nic,omitempty"`
  536. Podid string `json:"podid,omitempty"`
  537. Project string `json:"project,omitempty"`
  538. Projectid string `json:"projectid,omitempty"`
  539. Publicip string `json:"publicip,omitempty"`
  540. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  541. Publicnetmask string `json:"publicnetmask,omitempty"`
  542. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  543. Redundantstate string `json:"redundantstate,omitempty"`
  544. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  545. Role string `json:"role,omitempty"`
  546. Scriptsversion string `json:"scriptsversion,omitempty"`
  547. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  548. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  549. State string `json:"state,omitempty"`
  550. Templateid string `json:"templateid,omitempty"`
  551. Version string `json:"version,omitempty"`
  552. Vpcid string `json:"vpcid,omitempty"`
  553. Vpcname string `json:"vpcname,omitempty"`
  554. Zoneid string `json:"zoneid,omitempty"`
  555. Zonename string `json:"zonename,omitempty"`
  556. }
  557. type ListInternalLoadBalancerVMsParams struct {
  558. p map[string]interface{}
  559. }
  560. func (p *ListInternalLoadBalancerVMsParams) toURLValues() url.Values {
  561. u := url.Values{}
  562. if p.p == nil {
  563. return u
  564. }
  565. if v, found := p.p["account"]; found {
  566. u.Set("account", v.(string))
  567. }
  568. if v, found := p.p["domainid"]; found {
  569. u.Set("domainid", v.(string))
  570. }
  571. if v, found := p.p["forvpc"]; found {
  572. vv := strconv.FormatBool(v.(bool))
  573. u.Set("forvpc", vv)
  574. }
  575. if v, found := p.p["hostid"]; found {
  576. u.Set("hostid", v.(string))
  577. }
  578. if v, found := p.p["id"]; found {
  579. u.Set("id", v.(string))
  580. }
  581. if v, found := p.p["isrecursive"]; found {
  582. vv := strconv.FormatBool(v.(bool))
  583. u.Set("isrecursive", vv)
  584. }
  585. if v, found := p.p["keyword"]; found {
  586. u.Set("keyword", v.(string))
  587. }
  588. if v, found := p.p["listall"]; found {
  589. vv := strconv.FormatBool(v.(bool))
  590. u.Set("listall", vv)
  591. }
  592. if v, found := p.p["name"]; found {
  593. u.Set("name", v.(string))
  594. }
  595. if v, found := p.p["networkid"]; found {
  596. u.Set("networkid", v.(string))
  597. }
  598. if v, found := p.p["page"]; found {
  599. vv := strconv.Itoa(v.(int))
  600. u.Set("page", vv)
  601. }
  602. if v, found := p.p["pagesize"]; found {
  603. vv := strconv.Itoa(v.(int))
  604. u.Set("pagesize", vv)
  605. }
  606. if v, found := p.p["podid"]; found {
  607. u.Set("podid", v.(string))
  608. }
  609. if v, found := p.p["projectid"]; found {
  610. u.Set("projectid", v.(string))
  611. }
  612. if v, found := p.p["state"]; found {
  613. u.Set("state", v.(string))
  614. }
  615. if v, found := p.p["vpcid"]; found {
  616. u.Set("vpcid", v.(string))
  617. }
  618. if v, found := p.p["zoneid"]; found {
  619. u.Set("zoneid", v.(string))
  620. }
  621. return u
  622. }
  623. func (p *ListInternalLoadBalancerVMsParams) SetAccount(v string) {
  624. if p.p == nil {
  625. p.p = make(map[string]interface{})
  626. }
  627. p.p["account"] = v
  628. return
  629. }
  630. func (p *ListInternalLoadBalancerVMsParams) SetDomainid(v string) {
  631. if p.p == nil {
  632. p.p = make(map[string]interface{})
  633. }
  634. p.p["domainid"] = v
  635. return
  636. }
  637. func (p *ListInternalLoadBalancerVMsParams) SetForvpc(v bool) {
  638. if p.p == nil {
  639. p.p = make(map[string]interface{})
  640. }
  641. p.p["forvpc"] = v
  642. return
  643. }
  644. func (p *ListInternalLoadBalancerVMsParams) SetHostid(v string) {
  645. if p.p == nil {
  646. p.p = make(map[string]interface{})
  647. }
  648. p.p["hostid"] = v
  649. return
  650. }
  651. func (p *ListInternalLoadBalancerVMsParams) SetId(v string) {
  652. if p.p == nil {
  653. p.p = make(map[string]interface{})
  654. }
  655. p.p["id"] = v
  656. return
  657. }
  658. func (p *ListInternalLoadBalancerVMsParams) SetIsrecursive(v bool) {
  659. if p.p == nil {
  660. p.p = make(map[string]interface{})
  661. }
  662. p.p["isrecursive"] = v
  663. return
  664. }
  665. func (p *ListInternalLoadBalancerVMsParams) SetKeyword(v string) {
  666. if p.p == nil {
  667. p.p = make(map[string]interface{})
  668. }
  669. p.p["keyword"] = v
  670. return
  671. }
  672. func (p *ListInternalLoadBalancerVMsParams) SetListall(v bool) {
  673. if p.p == nil {
  674. p.p = make(map[string]interface{})
  675. }
  676. p.p["listall"] = v
  677. return
  678. }
  679. func (p *ListInternalLoadBalancerVMsParams) SetName(v string) {
  680. if p.p == nil {
  681. p.p = make(map[string]interface{})
  682. }
  683. p.p["name"] = v
  684. return
  685. }
  686. func (p *ListInternalLoadBalancerVMsParams) SetNetworkid(v string) {
  687. if p.p == nil {
  688. p.p = make(map[string]interface{})
  689. }
  690. p.p["networkid"] = v
  691. return
  692. }
  693. func (p *ListInternalLoadBalancerVMsParams) SetPage(v int) {
  694. if p.p == nil {
  695. p.p = make(map[string]interface{})
  696. }
  697. p.p["page"] = v
  698. return
  699. }
  700. func (p *ListInternalLoadBalancerVMsParams) SetPagesize(v int) {
  701. if p.p == nil {
  702. p.p = make(map[string]interface{})
  703. }
  704. p.p["pagesize"] = v
  705. return
  706. }
  707. func (p *ListInternalLoadBalancerVMsParams) SetPodid(v string) {
  708. if p.p == nil {
  709. p.p = make(map[string]interface{})
  710. }
  711. p.p["podid"] = v
  712. return
  713. }
  714. func (p *ListInternalLoadBalancerVMsParams) SetProjectid(v string) {
  715. if p.p == nil {
  716. p.p = make(map[string]interface{})
  717. }
  718. p.p["projectid"] = v
  719. return
  720. }
  721. func (p *ListInternalLoadBalancerVMsParams) SetState(v string) {
  722. if p.p == nil {
  723. p.p = make(map[string]interface{})
  724. }
  725. p.p["state"] = v
  726. return
  727. }
  728. func (p *ListInternalLoadBalancerVMsParams) SetVpcid(v string) {
  729. if p.p == nil {
  730. p.p = make(map[string]interface{})
  731. }
  732. p.p["vpcid"] = v
  733. return
  734. }
  735. func (p *ListInternalLoadBalancerVMsParams) SetZoneid(v string) {
  736. if p.p == nil {
  737. p.p = make(map[string]interface{})
  738. }
  739. p.p["zoneid"] = v
  740. return
  741. }
  742. // You should always use this function to get a new ListInternalLoadBalancerVMsParams instance,
  743. // as then you are sure you have configured all required params
  744. func (s *InternalLBService) NewListInternalLoadBalancerVMsParams() *ListInternalLoadBalancerVMsParams {
  745. p := &ListInternalLoadBalancerVMsParams{}
  746. p.p = make(map[string]interface{})
  747. return p
  748. }
  749. // This is a courtesy helper function, which in some cases may not work as expected!
  750. func (s *InternalLBService) GetInternalLoadBalancerVMID(name string, opts ...OptionFunc) (string, int, error) {
  751. p := &ListInternalLoadBalancerVMsParams{}
  752. p.p = make(map[string]interface{})
  753. p.p["name"] = name
  754. for _, fn := range opts {
  755. if err := fn(s.cs, p); err != nil {
  756. return "", -1, err
  757. }
  758. }
  759. l, err := s.ListInternalLoadBalancerVMs(p)
  760. if err != nil {
  761. return "", -1, err
  762. }
  763. if l.Count == 0 {
  764. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  765. }
  766. if l.Count == 1 {
  767. return l.InternalLoadBalancerVMs[0].Id, l.Count, nil
  768. }
  769. if l.Count > 1 {
  770. for _, v := range l.InternalLoadBalancerVMs {
  771. if v.Name == name {
  772. return v.Id, l.Count, nil
  773. }
  774. }
  775. }
  776. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  777. }
  778. // This is a courtesy helper function, which in some cases may not work as expected!
  779. func (s *InternalLBService) GetInternalLoadBalancerVMByName(name string, opts ...OptionFunc) (*InternalLoadBalancerVM, int, error) {
  780. id, count, err := s.GetInternalLoadBalancerVMID(name, opts...)
  781. if err != nil {
  782. return nil, count, err
  783. }
  784. r, count, err := s.GetInternalLoadBalancerVMByID(id, opts...)
  785. if err != nil {
  786. return nil, count, err
  787. }
  788. return r, count, nil
  789. }
  790. // This is a courtesy helper function, which in some cases may not work as expected!
  791. func (s *InternalLBService) GetInternalLoadBalancerVMByID(id string, opts ...OptionFunc) (*InternalLoadBalancerVM, int, error) {
  792. p := &ListInternalLoadBalancerVMsParams{}
  793. p.p = make(map[string]interface{})
  794. p.p["id"] = id
  795. for _, fn := range opts {
  796. if err := fn(s.cs, p); err != nil {
  797. return nil, -1, err
  798. }
  799. }
  800. l, err := s.ListInternalLoadBalancerVMs(p)
  801. if err != nil {
  802. if strings.Contains(err.Error(), fmt.Sprintf(
  803. "Invalid parameter id value=%s due to incorrect long value format, "+
  804. "or entity does not exist", id)) {
  805. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  806. }
  807. return nil, -1, err
  808. }
  809. if l.Count == 0 {
  810. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  811. }
  812. if l.Count == 1 {
  813. return l.InternalLoadBalancerVMs[0], l.Count, nil
  814. }
  815. return nil, l.Count, fmt.Errorf("There is more then one result for InternalLoadBalancerVM UUID: %s!", id)
  816. }
  817. // List internal LB VMs.
  818. func (s *InternalLBService) ListInternalLoadBalancerVMs(p *ListInternalLoadBalancerVMsParams) (*ListInternalLoadBalancerVMsResponse, error) {
  819. resp, err := s.cs.newRequest("listInternalLoadBalancerVMs", p.toURLValues())
  820. if err != nil {
  821. return nil, err
  822. }
  823. var r ListInternalLoadBalancerVMsResponse
  824. if err := json.Unmarshal(resp, &r); err != nil {
  825. return nil, err
  826. }
  827. return &r, nil
  828. }
  829. type ListInternalLoadBalancerVMsResponse struct {
  830. Count int `json:"count"`
  831. InternalLoadBalancerVMs []*InternalLoadBalancerVM `json:"internalloadbalancervm"`
  832. }
  833. type InternalLoadBalancerVM struct {
  834. Account string `json:"account,omitempty"`
  835. Created string `json:"created,omitempty"`
  836. Dns1 string `json:"dns1,omitempty"`
  837. Dns2 string `json:"dns2,omitempty"`
  838. Domain string `json:"domain,omitempty"`
  839. Domainid string `json:"domainid,omitempty"`
  840. Gateway string `json:"gateway,omitempty"`
  841. Guestipaddress string `json:"guestipaddress,omitempty"`
  842. Guestmacaddress string `json:"guestmacaddress,omitempty"`
  843. Guestnetmask string `json:"guestnetmask,omitempty"`
  844. Guestnetworkid string `json:"guestnetworkid,omitempty"`
  845. Guestnetworkname string `json:"guestnetworkname,omitempty"`
  846. Hostid string `json:"hostid,omitempty"`
  847. Hostname string `json:"hostname,omitempty"`
  848. Hypervisor string `json:"hypervisor,omitempty"`
  849. Id string `json:"id,omitempty"`
  850. Ip6dns1 string `json:"ip6dns1,omitempty"`
  851. Ip6dns2 string `json:"ip6dns2,omitempty"`
  852. Isredundantrouter bool `json:"isredundantrouter,omitempty"`
  853. Linklocalip string `json:"linklocalip,omitempty"`
  854. Linklocalmacaddress string `json:"linklocalmacaddress,omitempty"`
  855. Linklocalnetmask string `json:"linklocalnetmask,omitempty"`
  856. Linklocalnetworkid string `json:"linklocalnetworkid,omitempty"`
  857. Name string `json:"name,omitempty"`
  858. Networkdomain string `json:"networkdomain,omitempty"`
  859. Nic []struct {
  860. Broadcasturi string `json:"broadcasturi,omitempty"`
  861. Deviceid string `json:"deviceid,omitempty"`
  862. Gateway string `json:"gateway,omitempty"`
  863. Id string `json:"id,omitempty"`
  864. Ip6address string `json:"ip6address,omitempty"`
  865. Ip6cidr string `json:"ip6cidr,omitempty"`
  866. Ip6gateway string `json:"ip6gateway,omitempty"`
  867. Ipaddress string `json:"ipaddress,omitempty"`
  868. Isdefault bool `json:"isdefault,omitempty"`
  869. Isolationuri string `json:"isolationuri,omitempty"`
  870. Macaddress string `json:"macaddress,omitempty"`
  871. Netmask string `json:"netmask,omitempty"`
  872. Networkid string `json:"networkid,omitempty"`
  873. Networkname string `json:"networkname,omitempty"`
  874. Secondaryip []struct {
  875. Id string `json:"id,omitempty"`
  876. Ipaddress string `json:"ipaddress,omitempty"`
  877. } `json:"secondaryip,omitempty"`
  878. Traffictype string `json:"traffictype,omitempty"`
  879. Type string `json:"type,omitempty"`
  880. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  881. } `json:"nic,omitempty"`
  882. Podid string `json:"podid,omitempty"`
  883. Project string `json:"project,omitempty"`
  884. Projectid string `json:"projectid,omitempty"`
  885. Publicip string `json:"publicip,omitempty"`
  886. Publicmacaddress string `json:"publicmacaddress,omitempty"`
  887. Publicnetmask string `json:"publicnetmask,omitempty"`
  888. Publicnetworkid string `json:"publicnetworkid,omitempty"`
  889. Redundantstate string `json:"redundantstate,omitempty"`
  890. Requiresupgrade bool `json:"requiresupgrade,omitempty"`
  891. Role string `json:"role,omitempty"`
  892. Scriptsversion string `json:"scriptsversion,omitempty"`
  893. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  894. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  895. State string `json:"state,omitempty"`
  896. Templateid string `json:"templateid,omitempty"`
  897. Version string `json:"version,omitempty"`
  898. Vpcid string `json:"vpcid,omitempty"`
  899. Vpcname string `json:"vpcname,omitempty"`
  900. Zoneid string `json:"zoneid,omitempty"`
  901. Zonename string `json:"zonename,omitempty"`
  902. }