AffinityGroupService.go 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  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 CreateAffinityGroupParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *CreateAffinityGroupParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["account"]; found {
  33. u.Set("account", v.(string))
  34. }
  35. if v, found := p.p["description"]; found {
  36. u.Set("description", v.(string))
  37. }
  38. if v, found := p.p["domainid"]; found {
  39. u.Set("domainid", v.(string))
  40. }
  41. if v, found := p.p["name"]; found {
  42. u.Set("name", v.(string))
  43. }
  44. if v, found := p.p["projectid"]; found {
  45. u.Set("projectid", v.(string))
  46. }
  47. if v, found := p.p["type"]; found {
  48. u.Set("type", v.(string))
  49. }
  50. return u
  51. }
  52. func (p *CreateAffinityGroupParams) SetAccount(v string) {
  53. if p.p == nil {
  54. p.p = make(map[string]interface{})
  55. }
  56. p.p["account"] = v
  57. return
  58. }
  59. func (p *CreateAffinityGroupParams) SetDescription(v string) {
  60. if p.p == nil {
  61. p.p = make(map[string]interface{})
  62. }
  63. p.p["description"] = v
  64. return
  65. }
  66. func (p *CreateAffinityGroupParams) SetDomainid(v string) {
  67. if p.p == nil {
  68. p.p = make(map[string]interface{})
  69. }
  70. p.p["domainid"] = v
  71. return
  72. }
  73. func (p *CreateAffinityGroupParams) SetName(v string) {
  74. if p.p == nil {
  75. p.p = make(map[string]interface{})
  76. }
  77. p.p["name"] = v
  78. return
  79. }
  80. func (p *CreateAffinityGroupParams) SetProjectid(v string) {
  81. if p.p == nil {
  82. p.p = make(map[string]interface{})
  83. }
  84. p.p["projectid"] = v
  85. return
  86. }
  87. func (p *CreateAffinityGroupParams) SetType(v string) {
  88. if p.p == nil {
  89. p.p = make(map[string]interface{})
  90. }
  91. p.p["affinityGroupType"] = v
  92. return
  93. }
  94. // You should always use this function to get a new CreateAffinityGroupParams instance,
  95. // as then you are sure you have configured all required params
  96. func (s *AffinityGroupService) NewCreateAffinityGroupParams(name string, affinityGroupType string) *CreateAffinityGroupParams {
  97. p := &CreateAffinityGroupParams{}
  98. p.p = make(map[string]interface{})
  99. p.p["name"] = name
  100. p.p["affinityGroupType"] = affinityGroupType
  101. return p
  102. }
  103. // Creates an affinity/anti-affinity group
  104. func (s *AffinityGroupService) CreateAffinityGroup(p *CreateAffinityGroupParams) (*CreateAffinityGroupResponse, error) {
  105. resp, err := s.cs.newRequest("createAffinityGroup", p.toURLValues())
  106. if err != nil {
  107. return nil, err
  108. }
  109. var r CreateAffinityGroupResponse
  110. if err := json.Unmarshal(resp, &r); err != nil {
  111. return nil, err
  112. }
  113. // If we have a async client, we need to wait for the async result
  114. if s.cs.async {
  115. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  116. if err != nil {
  117. if err == AsyncTimeoutErr {
  118. return &r, err
  119. }
  120. return nil, err
  121. }
  122. b, err = getRawValue(b)
  123. if err != nil {
  124. return nil, err
  125. }
  126. if err := json.Unmarshal(b, &r); err != nil {
  127. return nil, err
  128. }
  129. }
  130. return &r, nil
  131. }
  132. type CreateAffinityGroupResponse struct {
  133. JobID string `json:"jobid,omitempty"`
  134. Account string `json:"account,omitempty"`
  135. Description string `json:"description,omitempty"`
  136. Domain string `json:"domain,omitempty"`
  137. Domainid string `json:"domainid,omitempty"`
  138. Id string `json:"id,omitempty"`
  139. Name string `json:"name,omitempty"`
  140. Project string `json:"project,omitempty"`
  141. Projectid string `json:"projectid,omitempty"`
  142. Type string `json:"type,omitempty"`
  143. VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
  144. }
  145. type DeleteAffinityGroupParams struct {
  146. p map[string]interface{}
  147. }
  148. func (p *DeleteAffinityGroupParams) toURLValues() url.Values {
  149. u := url.Values{}
  150. if p.p == nil {
  151. return u
  152. }
  153. if v, found := p.p["account"]; found {
  154. u.Set("account", v.(string))
  155. }
  156. if v, found := p.p["domainid"]; found {
  157. u.Set("domainid", v.(string))
  158. }
  159. if v, found := p.p["id"]; found {
  160. u.Set("id", v.(string))
  161. }
  162. if v, found := p.p["name"]; found {
  163. u.Set("name", v.(string))
  164. }
  165. if v, found := p.p["projectid"]; found {
  166. u.Set("projectid", v.(string))
  167. }
  168. return u
  169. }
  170. func (p *DeleteAffinityGroupParams) SetAccount(v string) {
  171. if p.p == nil {
  172. p.p = make(map[string]interface{})
  173. }
  174. p.p["account"] = v
  175. return
  176. }
  177. func (p *DeleteAffinityGroupParams) SetDomainid(v string) {
  178. if p.p == nil {
  179. p.p = make(map[string]interface{})
  180. }
  181. p.p["domainid"] = v
  182. return
  183. }
  184. func (p *DeleteAffinityGroupParams) SetId(v string) {
  185. if p.p == nil {
  186. p.p = make(map[string]interface{})
  187. }
  188. p.p["id"] = v
  189. return
  190. }
  191. func (p *DeleteAffinityGroupParams) SetName(v string) {
  192. if p.p == nil {
  193. p.p = make(map[string]interface{})
  194. }
  195. p.p["name"] = v
  196. return
  197. }
  198. func (p *DeleteAffinityGroupParams) SetProjectid(v string) {
  199. if p.p == nil {
  200. p.p = make(map[string]interface{})
  201. }
  202. p.p["projectid"] = v
  203. return
  204. }
  205. // You should always use this function to get a new DeleteAffinityGroupParams instance,
  206. // as then you are sure you have configured all required params
  207. func (s *AffinityGroupService) NewDeleteAffinityGroupParams() *DeleteAffinityGroupParams {
  208. p := &DeleteAffinityGroupParams{}
  209. p.p = make(map[string]interface{})
  210. return p
  211. }
  212. // Deletes affinity group
  213. func (s *AffinityGroupService) DeleteAffinityGroup(p *DeleteAffinityGroupParams) (*DeleteAffinityGroupResponse, error) {
  214. resp, err := s.cs.newRequest("deleteAffinityGroup", p.toURLValues())
  215. if err != nil {
  216. return nil, err
  217. }
  218. var r DeleteAffinityGroupResponse
  219. if err := json.Unmarshal(resp, &r); err != nil {
  220. return nil, err
  221. }
  222. // If we have a async client, we need to wait for the async result
  223. if s.cs.async {
  224. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  225. if err != nil {
  226. if err == AsyncTimeoutErr {
  227. return &r, err
  228. }
  229. return nil, err
  230. }
  231. if err := json.Unmarshal(b, &r); err != nil {
  232. return nil, err
  233. }
  234. }
  235. return &r, nil
  236. }
  237. type DeleteAffinityGroupResponse struct {
  238. JobID string `json:"jobid,omitempty"`
  239. Displaytext string `json:"displaytext,omitempty"`
  240. Success bool `json:"success,omitempty"`
  241. }
  242. type ListAffinityGroupsParams struct {
  243. p map[string]interface{}
  244. }
  245. func (p *ListAffinityGroupsParams) toURLValues() url.Values {
  246. u := url.Values{}
  247. if p.p == nil {
  248. return u
  249. }
  250. if v, found := p.p["account"]; found {
  251. u.Set("account", v.(string))
  252. }
  253. if v, found := p.p["domainid"]; found {
  254. u.Set("domainid", v.(string))
  255. }
  256. if v, found := p.p["id"]; found {
  257. u.Set("id", v.(string))
  258. }
  259. if v, found := p.p["isrecursive"]; found {
  260. vv := strconv.FormatBool(v.(bool))
  261. u.Set("isrecursive", vv)
  262. }
  263. if v, found := p.p["keyword"]; found {
  264. u.Set("keyword", v.(string))
  265. }
  266. if v, found := p.p["listall"]; found {
  267. vv := strconv.FormatBool(v.(bool))
  268. u.Set("listall", vv)
  269. }
  270. if v, found := p.p["name"]; found {
  271. u.Set("name", v.(string))
  272. }
  273. if v, found := p.p["page"]; found {
  274. vv := strconv.Itoa(v.(int))
  275. u.Set("page", vv)
  276. }
  277. if v, found := p.p["pagesize"]; found {
  278. vv := strconv.Itoa(v.(int))
  279. u.Set("pagesize", vv)
  280. }
  281. if v, found := p.p["projectid"]; found {
  282. u.Set("projectid", v.(string))
  283. }
  284. if v, found := p.p["type"]; found {
  285. u.Set("type", v.(string))
  286. }
  287. if v, found := p.p["virtualmachineid"]; found {
  288. u.Set("virtualmachineid", v.(string))
  289. }
  290. return u
  291. }
  292. func (p *ListAffinityGroupsParams) SetAccount(v string) {
  293. if p.p == nil {
  294. p.p = make(map[string]interface{})
  295. }
  296. p.p["account"] = v
  297. return
  298. }
  299. func (p *ListAffinityGroupsParams) SetDomainid(v string) {
  300. if p.p == nil {
  301. p.p = make(map[string]interface{})
  302. }
  303. p.p["domainid"] = v
  304. return
  305. }
  306. func (p *ListAffinityGroupsParams) SetId(v string) {
  307. if p.p == nil {
  308. p.p = make(map[string]interface{})
  309. }
  310. p.p["id"] = v
  311. return
  312. }
  313. func (p *ListAffinityGroupsParams) SetIsrecursive(v bool) {
  314. if p.p == nil {
  315. p.p = make(map[string]interface{})
  316. }
  317. p.p["isrecursive"] = v
  318. return
  319. }
  320. func (p *ListAffinityGroupsParams) SetKeyword(v string) {
  321. if p.p == nil {
  322. p.p = make(map[string]interface{})
  323. }
  324. p.p["keyword"] = v
  325. return
  326. }
  327. func (p *ListAffinityGroupsParams) SetListall(v bool) {
  328. if p.p == nil {
  329. p.p = make(map[string]interface{})
  330. }
  331. p.p["listall"] = v
  332. return
  333. }
  334. func (p *ListAffinityGroupsParams) SetName(v string) {
  335. if p.p == nil {
  336. p.p = make(map[string]interface{})
  337. }
  338. p.p["name"] = v
  339. return
  340. }
  341. func (p *ListAffinityGroupsParams) SetPage(v int) {
  342. if p.p == nil {
  343. p.p = make(map[string]interface{})
  344. }
  345. p.p["page"] = v
  346. return
  347. }
  348. func (p *ListAffinityGroupsParams) SetPagesize(v int) {
  349. if p.p == nil {
  350. p.p = make(map[string]interface{})
  351. }
  352. p.p["pagesize"] = v
  353. return
  354. }
  355. func (p *ListAffinityGroupsParams) SetProjectid(v string) {
  356. if p.p == nil {
  357. p.p = make(map[string]interface{})
  358. }
  359. p.p["projectid"] = v
  360. return
  361. }
  362. func (p *ListAffinityGroupsParams) SetType(v string) {
  363. if p.p == nil {
  364. p.p = make(map[string]interface{})
  365. }
  366. p.p["affinityGroupType"] = v
  367. return
  368. }
  369. func (p *ListAffinityGroupsParams) SetVirtualmachineid(v string) {
  370. if p.p == nil {
  371. p.p = make(map[string]interface{})
  372. }
  373. p.p["virtualmachineid"] = v
  374. return
  375. }
  376. // You should always use this function to get a new ListAffinityGroupsParams instance,
  377. // as then you are sure you have configured all required params
  378. func (s *AffinityGroupService) NewListAffinityGroupsParams() *ListAffinityGroupsParams {
  379. p := &ListAffinityGroupsParams{}
  380. p.p = make(map[string]interface{})
  381. return p
  382. }
  383. // This is a courtesy helper function, which in some cases may not work as expected!
  384. func (s *AffinityGroupService) GetAffinityGroupID(name string, opts ...OptionFunc) (string, int, error) {
  385. p := &ListAffinityGroupsParams{}
  386. p.p = make(map[string]interface{})
  387. p.p["name"] = name
  388. for _, fn := range opts {
  389. if err := fn(s.cs, p); err != nil {
  390. return "", -1, err
  391. }
  392. }
  393. l, err := s.ListAffinityGroups(p)
  394. if err != nil {
  395. return "", -1, err
  396. }
  397. if l.Count == 0 {
  398. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  399. }
  400. if l.Count == 1 {
  401. return l.AffinityGroups[0].Id, l.Count, nil
  402. }
  403. if l.Count > 1 {
  404. for _, v := range l.AffinityGroups {
  405. if v.Name == name {
  406. return v.Id, l.Count, nil
  407. }
  408. }
  409. }
  410. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  411. }
  412. // This is a courtesy helper function, which in some cases may not work as expected!
  413. func (s *AffinityGroupService) GetAffinityGroupByName(name string, opts ...OptionFunc) (*AffinityGroup, int, error) {
  414. id, count, err := s.GetAffinityGroupID(name, opts...)
  415. if err != nil {
  416. return nil, count, err
  417. }
  418. r, count, err := s.GetAffinityGroupByID(id, opts...)
  419. if err != nil {
  420. return nil, count, err
  421. }
  422. return r, count, nil
  423. }
  424. // This is a courtesy helper function, which in some cases may not work as expected!
  425. func (s *AffinityGroupService) GetAffinityGroupByID(id string, opts ...OptionFunc) (*AffinityGroup, int, error) {
  426. p := &ListAffinityGroupsParams{}
  427. p.p = make(map[string]interface{})
  428. p.p["id"] = id
  429. for _, fn := range opts {
  430. if err := fn(s.cs, p); err != nil {
  431. return nil, -1, err
  432. }
  433. }
  434. l, err := s.ListAffinityGroups(p)
  435. if err != nil {
  436. if strings.Contains(err.Error(), fmt.Sprintf(
  437. "Invalid parameter id value=%s due to incorrect long value format, "+
  438. "or entity does not exist", id)) {
  439. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  440. }
  441. return nil, -1, err
  442. }
  443. if l.Count == 0 {
  444. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  445. }
  446. if l.Count == 1 {
  447. return l.AffinityGroups[0], l.Count, nil
  448. }
  449. return nil, l.Count, fmt.Errorf("There is more then one result for AffinityGroup UUID: %s!", id)
  450. }
  451. // Lists affinity groups
  452. func (s *AffinityGroupService) ListAffinityGroups(p *ListAffinityGroupsParams) (*ListAffinityGroupsResponse, error) {
  453. resp, err := s.cs.newRequest("listAffinityGroups", p.toURLValues())
  454. if err != nil {
  455. return nil, err
  456. }
  457. var r ListAffinityGroupsResponse
  458. if err := json.Unmarshal(resp, &r); err != nil {
  459. return nil, err
  460. }
  461. return &r, nil
  462. }
  463. type ListAffinityGroupsResponse struct {
  464. Count int `json:"count"`
  465. AffinityGroups []*AffinityGroup `json:"affinitygroup"`
  466. }
  467. type AffinityGroup struct {
  468. Account string `json:"account,omitempty"`
  469. Description string `json:"description,omitempty"`
  470. Domain string `json:"domain,omitempty"`
  471. Domainid string `json:"domainid,omitempty"`
  472. Id string `json:"id,omitempty"`
  473. Name string `json:"name,omitempty"`
  474. Project string `json:"project,omitempty"`
  475. Projectid string `json:"projectid,omitempty"`
  476. Type string `json:"type,omitempty"`
  477. VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
  478. }
  479. type UpdateVMAffinityGroupParams struct {
  480. p map[string]interface{}
  481. }
  482. func (p *UpdateVMAffinityGroupParams) toURLValues() url.Values {
  483. u := url.Values{}
  484. if p.p == nil {
  485. return u
  486. }
  487. if v, found := p.p["affinitygroupids"]; found {
  488. vv := strings.Join(v.([]string), ",")
  489. u.Set("affinitygroupids", vv)
  490. }
  491. if v, found := p.p["affinitygroupnames"]; found {
  492. vv := strings.Join(v.([]string), ",")
  493. u.Set("affinitygroupnames", vv)
  494. }
  495. if v, found := p.p["id"]; found {
  496. u.Set("id", v.(string))
  497. }
  498. return u
  499. }
  500. func (p *UpdateVMAffinityGroupParams) SetAffinitygroupids(v []string) {
  501. if p.p == nil {
  502. p.p = make(map[string]interface{})
  503. }
  504. p.p["affinitygroupids"] = v
  505. return
  506. }
  507. func (p *UpdateVMAffinityGroupParams) SetAffinitygroupnames(v []string) {
  508. if p.p == nil {
  509. p.p = make(map[string]interface{})
  510. }
  511. p.p["affinitygroupnames"] = v
  512. return
  513. }
  514. func (p *UpdateVMAffinityGroupParams) SetId(v string) {
  515. if p.p == nil {
  516. p.p = make(map[string]interface{})
  517. }
  518. p.p["id"] = v
  519. return
  520. }
  521. // You should always use this function to get a new UpdateVMAffinityGroupParams instance,
  522. // as then you are sure you have configured all required params
  523. func (s *AffinityGroupService) NewUpdateVMAffinityGroupParams(id string) *UpdateVMAffinityGroupParams {
  524. p := &UpdateVMAffinityGroupParams{}
  525. p.p = make(map[string]interface{})
  526. p.p["id"] = id
  527. return p
  528. }
  529. // Updates the affinity/anti-affinity group associations of a virtual machine. The VM has to be stopped and restarted for the new properties to take effect.
  530. func (s *AffinityGroupService) UpdateVMAffinityGroup(p *UpdateVMAffinityGroupParams) (*UpdateVMAffinityGroupResponse, error) {
  531. resp, err := s.cs.newRequest("updateVMAffinityGroup", p.toURLValues())
  532. if err != nil {
  533. return nil, err
  534. }
  535. var r UpdateVMAffinityGroupResponse
  536. if err := json.Unmarshal(resp, &r); err != nil {
  537. return nil, err
  538. }
  539. // If we have a async client, we need to wait for the async result
  540. if s.cs.async {
  541. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  542. if err != nil {
  543. if err == AsyncTimeoutErr {
  544. return &r, err
  545. }
  546. return nil, err
  547. }
  548. b, err = getRawValue(b)
  549. if err != nil {
  550. return nil, err
  551. }
  552. if err := json.Unmarshal(b, &r); err != nil {
  553. return nil, err
  554. }
  555. }
  556. return &r, nil
  557. }
  558. type UpdateVMAffinityGroupResponse struct {
  559. JobID string `json:"jobid,omitempty"`
  560. Account string `json:"account,omitempty"`
  561. Affinitygroup []struct {
  562. Account string `json:"account,omitempty"`
  563. Description string `json:"description,omitempty"`
  564. Domain string `json:"domain,omitempty"`
  565. Domainid string `json:"domainid,omitempty"`
  566. Id string `json:"id,omitempty"`
  567. Name string `json:"name,omitempty"`
  568. Project string `json:"project,omitempty"`
  569. Projectid string `json:"projectid,omitempty"`
  570. Type string `json:"type,omitempty"`
  571. VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
  572. } `json:"affinitygroup,omitempty"`
  573. Cpunumber int `json:"cpunumber,omitempty"`
  574. Cpuspeed int `json:"cpuspeed,omitempty"`
  575. Cpuused string `json:"cpuused,omitempty"`
  576. Created string `json:"created,omitempty"`
  577. Details map[string]string `json:"details,omitempty"`
  578. Diskioread int64 `json:"diskioread,omitempty"`
  579. Diskiowrite int64 `json:"diskiowrite,omitempty"`
  580. Diskkbsread int64 `json:"diskkbsread,omitempty"`
  581. Diskkbswrite int64 `json:"diskkbswrite,omitempty"`
  582. Diskofferingid string `json:"diskofferingid,omitempty"`
  583. Diskofferingname string `json:"diskofferingname,omitempty"`
  584. Displayname string `json:"displayname,omitempty"`
  585. Displayvm bool `json:"displayvm,omitempty"`
  586. Domain string `json:"domain,omitempty"`
  587. Domainid string `json:"domainid,omitempty"`
  588. Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
  589. Group string `json:"group,omitempty"`
  590. Groupid string `json:"groupid,omitempty"`
  591. Guestosid string `json:"guestosid,omitempty"`
  592. Haenable bool `json:"haenable,omitempty"`
  593. Hostid string `json:"hostid,omitempty"`
  594. Hostname string `json:"hostname,omitempty"`
  595. Hypervisor string `json:"hypervisor,omitempty"`
  596. Id string `json:"id,omitempty"`
  597. Instancename string `json:"instancename,omitempty"`
  598. Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
  599. Isodisplaytext string `json:"isodisplaytext,omitempty"`
  600. Isoid string `json:"isoid,omitempty"`
  601. Isoname string `json:"isoname,omitempty"`
  602. Keypair string `json:"keypair,omitempty"`
  603. Memory int `json:"memory,omitempty"`
  604. Name string `json:"name,omitempty"`
  605. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  606. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  607. Nic []struct {
  608. Broadcasturi string `json:"broadcasturi,omitempty"`
  609. Deviceid string `json:"deviceid,omitempty"`
  610. Gateway string `json:"gateway,omitempty"`
  611. Id string `json:"id,omitempty"`
  612. Ip6address string `json:"ip6address,omitempty"`
  613. Ip6cidr string `json:"ip6cidr,omitempty"`
  614. Ip6gateway string `json:"ip6gateway,omitempty"`
  615. Ipaddress string `json:"ipaddress,omitempty"`
  616. Isdefault bool `json:"isdefault,omitempty"`
  617. Isolationuri string `json:"isolationuri,omitempty"`
  618. Macaddress string `json:"macaddress,omitempty"`
  619. Netmask string `json:"netmask,omitempty"`
  620. Networkid string `json:"networkid,omitempty"`
  621. Networkname string `json:"networkname,omitempty"`
  622. Secondaryip []struct {
  623. Id string `json:"id,omitempty"`
  624. Ipaddress string `json:"ipaddress,omitempty"`
  625. } `json:"secondaryip,omitempty"`
  626. Traffictype string `json:"traffictype,omitempty"`
  627. Type string `json:"type,omitempty"`
  628. Virtualmachineid string `json:"virtualmachineid,omitempty"`
  629. } `json:"nic,omitempty"`
  630. Ostypeid int64 `json:"ostypeid,omitempty"`
  631. Password string `json:"password,omitempty"`
  632. Passwordenabled bool `json:"passwordenabled,omitempty"`
  633. Project string `json:"project,omitempty"`
  634. Projectid string `json:"projectid,omitempty"`
  635. Publicip string `json:"publicip,omitempty"`
  636. Publicipid string `json:"publicipid,omitempty"`
  637. Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
  638. Rootdevicetype string `json:"rootdevicetype,omitempty"`
  639. Securitygroup []struct {
  640. Account string `json:"account,omitempty"`
  641. Description string `json:"description,omitempty"`
  642. Domain string `json:"domain,omitempty"`
  643. Domainid string `json:"domainid,omitempty"`
  644. Egressrule []struct {
  645. Account string `json:"account,omitempty"`
  646. Cidr string `json:"cidr,omitempty"`
  647. Endport int `json:"endport,omitempty"`
  648. Icmpcode int `json:"icmpcode,omitempty"`
  649. Icmptype int `json:"icmptype,omitempty"`
  650. Protocol string `json:"protocol,omitempty"`
  651. Ruleid string `json:"ruleid,omitempty"`
  652. Securitygroupname string `json:"securitygroupname,omitempty"`
  653. Startport int `json:"startport,omitempty"`
  654. Tags []struct {
  655. Account string `json:"account,omitempty"`
  656. Customer string `json:"customer,omitempty"`
  657. Domain string `json:"domain,omitempty"`
  658. Domainid string `json:"domainid,omitempty"`
  659. Key string `json:"key,omitempty"`
  660. Project string `json:"project,omitempty"`
  661. Projectid string `json:"projectid,omitempty"`
  662. Resourceid string `json:"resourceid,omitempty"`
  663. Resourcetype string `json:"resourcetype,omitempty"`
  664. Value string `json:"value,omitempty"`
  665. } `json:"tags,omitempty"`
  666. } `json:"egressrule,omitempty"`
  667. Id string `json:"id,omitempty"`
  668. Ingressrule []struct {
  669. Account string `json:"account,omitempty"`
  670. Cidr string `json:"cidr,omitempty"`
  671. Endport int `json:"endport,omitempty"`
  672. Icmpcode int `json:"icmpcode,omitempty"`
  673. Icmptype int `json:"icmptype,omitempty"`
  674. Protocol string `json:"protocol,omitempty"`
  675. Ruleid string `json:"ruleid,omitempty"`
  676. Securitygroupname string `json:"securitygroupname,omitempty"`
  677. Startport int `json:"startport,omitempty"`
  678. Tags []struct {
  679. Account string `json:"account,omitempty"`
  680. Customer string `json:"customer,omitempty"`
  681. Domain string `json:"domain,omitempty"`
  682. Domainid string `json:"domainid,omitempty"`
  683. Key string `json:"key,omitempty"`
  684. Project string `json:"project,omitempty"`
  685. Projectid string `json:"projectid,omitempty"`
  686. Resourceid string `json:"resourceid,omitempty"`
  687. Resourcetype string `json:"resourcetype,omitempty"`
  688. Value string `json:"value,omitempty"`
  689. } `json:"tags,omitempty"`
  690. } `json:"ingressrule,omitempty"`
  691. Name string `json:"name,omitempty"`
  692. Project string `json:"project,omitempty"`
  693. Projectid string `json:"projectid,omitempty"`
  694. Tags []struct {
  695. Account string `json:"account,omitempty"`
  696. Customer string `json:"customer,omitempty"`
  697. Domain string `json:"domain,omitempty"`
  698. Domainid string `json:"domainid,omitempty"`
  699. Key string `json:"key,omitempty"`
  700. Project string `json:"project,omitempty"`
  701. Projectid string `json:"projectid,omitempty"`
  702. Resourceid string `json:"resourceid,omitempty"`
  703. Resourcetype string `json:"resourcetype,omitempty"`
  704. Value string `json:"value,omitempty"`
  705. } `json:"tags,omitempty"`
  706. Virtualmachinecount int `json:"virtualmachinecount,omitempty"`
  707. Virtualmachineids []string `json:"virtualmachineids,omitempty"`
  708. } `json:"securitygroup,omitempty"`
  709. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  710. Serviceofferingname string `json:"serviceofferingname,omitempty"`
  711. Servicestate string `json:"servicestate,omitempty"`
  712. State string `json:"state,omitempty"`
  713. Tags []struct {
  714. Account string `json:"account,omitempty"`
  715. Customer string `json:"customer,omitempty"`
  716. Domain string `json:"domain,omitempty"`
  717. Domainid string `json:"domainid,omitempty"`
  718. Key string `json:"key,omitempty"`
  719. Project string `json:"project,omitempty"`
  720. Projectid string `json:"projectid,omitempty"`
  721. Resourceid string `json:"resourceid,omitempty"`
  722. Resourcetype string `json:"resourcetype,omitempty"`
  723. Value string `json:"value,omitempty"`
  724. } `json:"tags,omitempty"`
  725. Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
  726. Templateid string `json:"templateid,omitempty"`
  727. Templatename string `json:"templatename,omitempty"`
  728. Userid string `json:"userid,omitempty"`
  729. Username string `json:"username,omitempty"`
  730. Vgpu string `json:"vgpu,omitempty"`
  731. Zoneid string `json:"zoneid,omitempty"`
  732. Zonename string `json:"zonename,omitempty"`
  733. }
  734. type ListAffinityGroupTypesParams struct {
  735. p map[string]interface{}
  736. }
  737. func (p *ListAffinityGroupTypesParams) toURLValues() url.Values {
  738. u := url.Values{}
  739. if p.p == nil {
  740. return u
  741. }
  742. if v, found := p.p["keyword"]; found {
  743. u.Set("keyword", v.(string))
  744. }
  745. if v, found := p.p["page"]; found {
  746. vv := strconv.Itoa(v.(int))
  747. u.Set("page", vv)
  748. }
  749. if v, found := p.p["pagesize"]; found {
  750. vv := strconv.Itoa(v.(int))
  751. u.Set("pagesize", vv)
  752. }
  753. return u
  754. }
  755. func (p *ListAffinityGroupTypesParams) SetKeyword(v string) {
  756. if p.p == nil {
  757. p.p = make(map[string]interface{})
  758. }
  759. p.p["keyword"] = v
  760. return
  761. }
  762. func (p *ListAffinityGroupTypesParams) SetPage(v int) {
  763. if p.p == nil {
  764. p.p = make(map[string]interface{})
  765. }
  766. p.p["page"] = v
  767. return
  768. }
  769. func (p *ListAffinityGroupTypesParams) SetPagesize(v int) {
  770. if p.p == nil {
  771. p.p = make(map[string]interface{})
  772. }
  773. p.p["pagesize"] = v
  774. return
  775. }
  776. // You should always use this function to get a new ListAffinityGroupTypesParams instance,
  777. // as then you are sure you have configured all required params
  778. func (s *AffinityGroupService) NewListAffinityGroupTypesParams() *ListAffinityGroupTypesParams {
  779. p := &ListAffinityGroupTypesParams{}
  780. p.p = make(map[string]interface{})
  781. return p
  782. }
  783. // Lists affinity group types available
  784. func (s *AffinityGroupService) ListAffinityGroupTypes(p *ListAffinityGroupTypesParams) (*ListAffinityGroupTypesResponse, error) {
  785. resp, err := s.cs.newRequest("listAffinityGroupTypes", p.toURLValues())
  786. if err != nil {
  787. return nil, err
  788. }
  789. var r ListAffinityGroupTypesResponse
  790. if err := json.Unmarshal(resp, &r); err != nil {
  791. return nil, err
  792. }
  793. return &r, nil
  794. }
  795. type ListAffinityGroupTypesResponse struct {
  796. Count int `json:"count"`
  797. AffinityGroupTypes []*AffinityGroupType `json:"affinitygrouptype"`
  798. }
  799. type AffinityGroupType struct {
  800. Type string `json:"type,omitempty"`
  801. }