ServiceOfferingService.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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 CreateServiceOfferingParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *CreateServiceOfferingParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["bytesreadrate"]; found {
  33. vv := strconv.FormatInt(v.(int64), 10)
  34. u.Set("bytesreadrate", vv)
  35. }
  36. if v, found := p.p["byteswriterate"]; found {
  37. vv := strconv.FormatInt(v.(int64), 10)
  38. u.Set("byteswriterate", vv)
  39. }
  40. if v, found := p.p["cpunumber"]; found {
  41. vv := strconv.Itoa(v.(int))
  42. u.Set("cpunumber", vv)
  43. }
  44. if v, found := p.p["cpuspeed"]; found {
  45. vv := strconv.Itoa(v.(int))
  46. u.Set("cpuspeed", vv)
  47. }
  48. if v, found := p.p["customizediops"]; found {
  49. vv := strconv.FormatBool(v.(bool))
  50. u.Set("customizediops", vv)
  51. }
  52. if v, found := p.p["deploymentplanner"]; found {
  53. u.Set("deploymentplanner", v.(string))
  54. }
  55. if v, found := p.p["displaytext"]; found {
  56. u.Set("displaytext", v.(string))
  57. }
  58. if v, found := p.p["domainid"]; found {
  59. u.Set("domainid", v.(string))
  60. }
  61. if v, found := p.p["hosttags"]; found {
  62. u.Set("hosttags", v.(string))
  63. }
  64. if v, found := p.p["hypervisorsnapshotreserve"]; found {
  65. vv := strconv.Itoa(v.(int))
  66. u.Set("hypervisorsnapshotreserve", vv)
  67. }
  68. if v, found := p.p["iopsreadrate"]; found {
  69. vv := strconv.FormatInt(v.(int64), 10)
  70. u.Set("iopsreadrate", vv)
  71. }
  72. if v, found := p.p["iopswriterate"]; found {
  73. vv := strconv.FormatInt(v.(int64), 10)
  74. u.Set("iopswriterate", vv)
  75. }
  76. if v, found := p.p["issystem"]; found {
  77. vv := strconv.FormatBool(v.(bool))
  78. u.Set("issystem", vv)
  79. }
  80. if v, found := p.p["isvolatile"]; found {
  81. vv := strconv.FormatBool(v.(bool))
  82. u.Set("isvolatile", vv)
  83. }
  84. if v, found := p.p["limitcpuuse"]; found {
  85. vv := strconv.FormatBool(v.(bool))
  86. u.Set("limitcpuuse", vv)
  87. }
  88. if v, found := p.p["maxiops"]; found {
  89. vv := strconv.FormatInt(v.(int64), 10)
  90. u.Set("maxiops", vv)
  91. }
  92. if v, found := p.p["memory"]; found {
  93. vv := strconv.Itoa(v.(int))
  94. u.Set("memory", vv)
  95. }
  96. if v, found := p.p["miniops"]; found {
  97. vv := strconv.FormatInt(v.(int64), 10)
  98. u.Set("miniops", vv)
  99. }
  100. if v, found := p.p["name"]; found {
  101. u.Set("name", v.(string))
  102. }
  103. if v, found := p.p["networkrate"]; found {
  104. vv := strconv.Itoa(v.(int))
  105. u.Set("networkrate", vv)
  106. }
  107. if v, found := p.p["offerha"]; found {
  108. vv := strconv.FormatBool(v.(bool))
  109. u.Set("offerha", vv)
  110. }
  111. if v, found := p.p["provisioningtype"]; found {
  112. u.Set("provisioningtype", v.(string))
  113. }
  114. if v, found := p.p["serviceofferingdetails"]; found {
  115. i := 0
  116. for k, vv := range v.(map[string]string) {
  117. u.Set(fmt.Sprintf("serviceofferingdetails[%d].key", i), k)
  118. u.Set(fmt.Sprintf("serviceofferingdetails[%d].value", i), vv)
  119. i++
  120. }
  121. }
  122. if v, found := p.p["storagetype"]; found {
  123. u.Set("storagetype", v.(string))
  124. }
  125. if v, found := p.p["systemvmtype"]; found {
  126. u.Set("systemvmtype", v.(string))
  127. }
  128. if v, found := p.p["tags"]; found {
  129. u.Set("tags", v.(string))
  130. }
  131. return u
  132. }
  133. func (p *CreateServiceOfferingParams) SetBytesreadrate(v int64) {
  134. if p.p == nil {
  135. p.p = make(map[string]interface{})
  136. }
  137. p.p["bytesreadrate"] = v
  138. return
  139. }
  140. func (p *CreateServiceOfferingParams) SetByteswriterate(v int64) {
  141. if p.p == nil {
  142. p.p = make(map[string]interface{})
  143. }
  144. p.p["byteswriterate"] = v
  145. return
  146. }
  147. func (p *CreateServiceOfferingParams) SetCpunumber(v int) {
  148. if p.p == nil {
  149. p.p = make(map[string]interface{})
  150. }
  151. p.p["cpunumber"] = v
  152. return
  153. }
  154. func (p *CreateServiceOfferingParams) SetCpuspeed(v int) {
  155. if p.p == nil {
  156. p.p = make(map[string]interface{})
  157. }
  158. p.p["cpuspeed"] = v
  159. return
  160. }
  161. func (p *CreateServiceOfferingParams) SetCustomizediops(v bool) {
  162. if p.p == nil {
  163. p.p = make(map[string]interface{})
  164. }
  165. p.p["customizediops"] = v
  166. return
  167. }
  168. func (p *CreateServiceOfferingParams) SetDeploymentplanner(v string) {
  169. if p.p == nil {
  170. p.p = make(map[string]interface{})
  171. }
  172. p.p["deploymentplanner"] = v
  173. return
  174. }
  175. func (p *CreateServiceOfferingParams) SetDisplaytext(v string) {
  176. if p.p == nil {
  177. p.p = make(map[string]interface{})
  178. }
  179. p.p["displaytext"] = v
  180. return
  181. }
  182. func (p *CreateServiceOfferingParams) SetDomainid(v string) {
  183. if p.p == nil {
  184. p.p = make(map[string]interface{})
  185. }
  186. p.p["domainid"] = v
  187. return
  188. }
  189. func (p *CreateServiceOfferingParams) SetHosttags(v string) {
  190. if p.p == nil {
  191. p.p = make(map[string]interface{})
  192. }
  193. p.p["hosttags"] = v
  194. return
  195. }
  196. func (p *CreateServiceOfferingParams) SetHypervisorsnapshotreserve(v int) {
  197. if p.p == nil {
  198. p.p = make(map[string]interface{})
  199. }
  200. p.p["hypervisorsnapshotreserve"] = v
  201. return
  202. }
  203. func (p *CreateServiceOfferingParams) SetIopsreadrate(v int64) {
  204. if p.p == nil {
  205. p.p = make(map[string]interface{})
  206. }
  207. p.p["iopsreadrate"] = v
  208. return
  209. }
  210. func (p *CreateServiceOfferingParams) SetIopswriterate(v int64) {
  211. if p.p == nil {
  212. p.p = make(map[string]interface{})
  213. }
  214. p.p["iopswriterate"] = v
  215. return
  216. }
  217. func (p *CreateServiceOfferingParams) SetIssystem(v bool) {
  218. if p.p == nil {
  219. p.p = make(map[string]interface{})
  220. }
  221. p.p["issystem"] = v
  222. return
  223. }
  224. func (p *CreateServiceOfferingParams) SetIsvolatile(v bool) {
  225. if p.p == nil {
  226. p.p = make(map[string]interface{})
  227. }
  228. p.p["isvolatile"] = v
  229. return
  230. }
  231. func (p *CreateServiceOfferingParams) SetLimitcpuuse(v bool) {
  232. if p.p == nil {
  233. p.p = make(map[string]interface{})
  234. }
  235. p.p["limitcpuuse"] = v
  236. return
  237. }
  238. func (p *CreateServiceOfferingParams) SetMaxiops(v int64) {
  239. if p.p == nil {
  240. p.p = make(map[string]interface{})
  241. }
  242. p.p["maxiops"] = v
  243. return
  244. }
  245. func (p *CreateServiceOfferingParams) SetMemory(v int) {
  246. if p.p == nil {
  247. p.p = make(map[string]interface{})
  248. }
  249. p.p["memory"] = v
  250. return
  251. }
  252. func (p *CreateServiceOfferingParams) SetMiniops(v int64) {
  253. if p.p == nil {
  254. p.p = make(map[string]interface{})
  255. }
  256. p.p["miniops"] = v
  257. return
  258. }
  259. func (p *CreateServiceOfferingParams) SetName(v string) {
  260. if p.p == nil {
  261. p.p = make(map[string]interface{})
  262. }
  263. p.p["name"] = v
  264. return
  265. }
  266. func (p *CreateServiceOfferingParams) SetNetworkrate(v int) {
  267. if p.p == nil {
  268. p.p = make(map[string]interface{})
  269. }
  270. p.p["networkrate"] = v
  271. return
  272. }
  273. func (p *CreateServiceOfferingParams) SetOfferha(v bool) {
  274. if p.p == nil {
  275. p.p = make(map[string]interface{})
  276. }
  277. p.p["offerha"] = v
  278. return
  279. }
  280. func (p *CreateServiceOfferingParams) SetProvisioningtype(v string) {
  281. if p.p == nil {
  282. p.p = make(map[string]interface{})
  283. }
  284. p.p["provisioningtype"] = v
  285. return
  286. }
  287. func (p *CreateServiceOfferingParams) SetServiceofferingdetails(v map[string]string) {
  288. if p.p == nil {
  289. p.p = make(map[string]interface{})
  290. }
  291. p.p["serviceofferingdetails"] = v
  292. return
  293. }
  294. func (p *CreateServiceOfferingParams) SetStoragetype(v string) {
  295. if p.p == nil {
  296. p.p = make(map[string]interface{})
  297. }
  298. p.p["storagetype"] = v
  299. return
  300. }
  301. func (p *CreateServiceOfferingParams) SetSystemvmtype(v string) {
  302. if p.p == nil {
  303. p.p = make(map[string]interface{})
  304. }
  305. p.p["systemvmtype"] = v
  306. return
  307. }
  308. func (p *CreateServiceOfferingParams) SetTags(v string) {
  309. if p.p == nil {
  310. p.p = make(map[string]interface{})
  311. }
  312. p.p["tags"] = v
  313. return
  314. }
  315. // You should always use this function to get a new CreateServiceOfferingParams instance,
  316. // as then you are sure you have configured all required params
  317. func (s *ServiceOfferingService) NewCreateServiceOfferingParams(displaytext string, name string) *CreateServiceOfferingParams {
  318. p := &CreateServiceOfferingParams{}
  319. p.p = make(map[string]interface{})
  320. p.p["displaytext"] = displaytext
  321. p.p["name"] = name
  322. return p
  323. }
  324. // Creates a service offering.
  325. func (s *ServiceOfferingService) CreateServiceOffering(p *CreateServiceOfferingParams) (*CreateServiceOfferingResponse, error) {
  326. resp, err := s.cs.newRequest("createServiceOffering", p.toURLValues())
  327. if err != nil {
  328. return nil, err
  329. }
  330. if resp, err = getRawValue(resp); err != nil {
  331. return nil, err
  332. }
  333. var r CreateServiceOfferingResponse
  334. if err := json.Unmarshal(resp, &r); err != nil {
  335. return nil, err
  336. }
  337. return &r, nil
  338. }
  339. type CreateServiceOfferingResponse struct {
  340. Cpunumber int `json:"cpunumber,omitempty"`
  341. Cpuspeed int `json:"cpuspeed,omitempty"`
  342. Created string `json:"created,omitempty"`
  343. Defaultuse bool `json:"defaultuse,omitempty"`
  344. Deploymentplanner string `json:"deploymentplanner,omitempty"`
  345. DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
  346. DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
  347. DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
  348. DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
  349. Displaytext string `json:"displaytext,omitempty"`
  350. Domain string `json:"domain,omitempty"`
  351. Domainid string `json:"domainid,omitempty"`
  352. Hosttags string `json:"hosttags,omitempty"`
  353. Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
  354. Id string `json:"id,omitempty"`
  355. Iscustomized bool `json:"iscustomized,omitempty"`
  356. Iscustomizediops bool `json:"iscustomizediops,omitempty"`
  357. Issystem bool `json:"issystem,omitempty"`
  358. Isvolatile bool `json:"isvolatile,omitempty"`
  359. Limitcpuuse bool `json:"limitcpuuse,omitempty"`
  360. Maxiops int64 `json:"maxiops,omitempty"`
  361. Memory int `json:"memory,omitempty"`
  362. Miniops int64 `json:"miniops,omitempty"`
  363. Name string `json:"name,omitempty"`
  364. Networkrate int `json:"networkrate,omitempty"`
  365. Offerha bool `json:"offerha,omitempty"`
  366. Provisioningtype string `json:"provisioningtype,omitempty"`
  367. Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
  368. Storagetype string `json:"storagetype,omitempty"`
  369. Systemvmtype string `json:"systemvmtype,omitempty"`
  370. Tags string `json:"tags,omitempty"`
  371. }
  372. type DeleteServiceOfferingParams struct {
  373. p map[string]interface{}
  374. }
  375. func (p *DeleteServiceOfferingParams) toURLValues() url.Values {
  376. u := url.Values{}
  377. if p.p == nil {
  378. return u
  379. }
  380. if v, found := p.p["id"]; found {
  381. u.Set("id", v.(string))
  382. }
  383. return u
  384. }
  385. func (p *DeleteServiceOfferingParams) SetId(v string) {
  386. if p.p == nil {
  387. p.p = make(map[string]interface{})
  388. }
  389. p.p["id"] = v
  390. return
  391. }
  392. // You should always use this function to get a new DeleteServiceOfferingParams instance,
  393. // as then you are sure you have configured all required params
  394. func (s *ServiceOfferingService) NewDeleteServiceOfferingParams(id string) *DeleteServiceOfferingParams {
  395. p := &DeleteServiceOfferingParams{}
  396. p.p = make(map[string]interface{})
  397. p.p["id"] = id
  398. return p
  399. }
  400. // Deletes a service offering.
  401. func (s *ServiceOfferingService) DeleteServiceOffering(p *DeleteServiceOfferingParams) (*DeleteServiceOfferingResponse, error) {
  402. resp, err := s.cs.newRequest("deleteServiceOffering", p.toURLValues())
  403. if err != nil {
  404. return nil, err
  405. }
  406. var r DeleteServiceOfferingResponse
  407. if err := json.Unmarshal(resp, &r); err != nil {
  408. return nil, err
  409. }
  410. return &r, nil
  411. }
  412. type DeleteServiceOfferingResponse struct {
  413. Displaytext string `json:"displaytext,omitempty"`
  414. Success string `json:"success,omitempty"`
  415. }
  416. type UpdateServiceOfferingParams struct {
  417. p map[string]interface{}
  418. }
  419. func (p *UpdateServiceOfferingParams) toURLValues() url.Values {
  420. u := url.Values{}
  421. if p.p == nil {
  422. return u
  423. }
  424. if v, found := p.p["displaytext"]; found {
  425. u.Set("displaytext", v.(string))
  426. }
  427. if v, found := p.p["id"]; found {
  428. u.Set("id", v.(string))
  429. }
  430. if v, found := p.p["name"]; found {
  431. u.Set("name", v.(string))
  432. }
  433. if v, found := p.p["sortkey"]; found {
  434. vv := strconv.Itoa(v.(int))
  435. u.Set("sortkey", vv)
  436. }
  437. return u
  438. }
  439. func (p *UpdateServiceOfferingParams) SetDisplaytext(v string) {
  440. if p.p == nil {
  441. p.p = make(map[string]interface{})
  442. }
  443. p.p["displaytext"] = v
  444. return
  445. }
  446. func (p *UpdateServiceOfferingParams) SetId(v string) {
  447. if p.p == nil {
  448. p.p = make(map[string]interface{})
  449. }
  450. p.p["id"] = v
  451. return
  452. }
  453. func (p *UpdateServiceOfferingParams) SetName(v string) {
  454. if p.p == nil {
  455. p.p = make(map[string]interface{})
  456. }
  457. p.p["name"] = v
  458. return
  459. }
  460. func (p *UpdateServiceOfferingParams) SetSortkey(v int) {
  461. if p.p == nil {
  462. p.p = make(map[string]interface{})
  463. }
  464. p.p["sortkey"] = v
  465. return
  466. }
  467. // You should always use this function to get a new UpdateServiceOfferingParams instance,
  468. // as then you are sure you have configured all required params
  469. func (s *ServiceOfferingService) NewUpdateServiceOfferingParams(id string) *UpdateServiceOfferingParams {
  470. p := &UpdateServiceOfferingParams{}
  471. p.p = make(map[string]interface{})
  472. p.p["id"] = id
  473. return p
  474. }
  475. // Updates a service offering.
  476. func (s *ServiceOfferingService) UpdateServiceOffering(p *UpdateServiceOfferingParams) (*UpdateServiceOfferingResponse, error) {
  477. resp, err := s.cs.newRequest("updateServiceOffering", p.toURLValues())
  478. if err != nil {
  479. return nil, err
  480. }
  481. var r UpdateServiceOfferingResponse
  482. if err := json.Unmarshal(resp, &r); err != nil {
  483. return nil, err
  484. }
  485. return &r, nil
  486. }
  487. type UpdateServiceOfferingResponse struct {
  488. Cpunumber int `json:"cpunumber,omitempty"`
  489. Cpuspeed int `json:"cpuspeed,omitempty"`
  490. Created string `json:"created,omitempty"`
  491. Defaultuse bool `json:"defaultuse,omitempty"`
  492. Deploymentplanner string `json:"deploymentplanner,omitempty"`
  493. DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
  494. DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
  495. DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
  496. DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
  497. Displaytext string `json:"displaytext,omitempty"`
  498. Domain string `json:"domain,omitempty"`
  499. Domainid string `json:"domainid,omitempty"`
  500. Hosttags string `json:"hosttags,omitempty"`
  501. Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
  502. Id string `json:"id,omitempty"`
  503. Iscustomized bool `json:"iscustomized,omitempty"`
  504. Iscustomizediops bool `json:"iscustomizediops,omitempty"`
  505. Issystem bool `json:"issystem,omitempty"`
  506. Isvolatile bool `json:"isvolatile,omitempty"`
  507. Limitcpuuse bool `json:"limitcpuuse,omitempty"`
  508. Maxiops int64 `json:"maxiops,omitempty"`
  509. Memory int `json:"memory,omitempty"`
  510. Miniops int64 `json:"miniops,omitempty"`
  511. Name string `json:"name,omitempty"`
  512. Networkrate int `json:"networkrate,omitempty"`
  513. Offerha bool `json:"offerha,omitempty"`
  514. Provisioningtype string `json:"provisioningtype,omitempty"`
  515. Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
  516. Storagetype string `json:"storagetype,omitempty"`
  517. Systemvmtype string `json:"systemvmtype,omitempty"`
  518. Tags string `json:"tags,omitempty"`
  519. }
  520. type ListServiceOfferingsParams struct {
  521. p map[string]interface{}
  522. }
  523. func (p *ListServiceOfferingsParams) toURLValues() url.Values {
  524. u := url.Values{}
  525. if p.p == nil {
  526. return u
  527. }
  528. if v, found := p.p["domainid"]; found {
  529. u.Set("domainid", v.(string))
  530. }
  531. if v, found := p.p["id"]; found {
  532. u.Set("id", v.(string))
  533. }
  534. if v, found := p.p["isrecursive"]; found {
  535. vv := strconv.FormatBool(v.(bool))
  536. u.Set("isrecursive", vv)
  537. }
  538. if v, found := p.p["issystem"]; found {
  539. vv := strconv.FormatBool(v.(bool))
  540. u.Set("issystem", vv)
  541. }
  542. if v, found := p.p["keyword"]; found {
  543. u.Set("keyword", v.(string))
  544. }
  545. if v, found := p.p["listall"]; found {
  546. vv := strconv.FormatBool(v.(bool))
  547. u.Set("listall", vv)
  548. }
  549. if v, found := p.p["name"]; found {
  550. u.Set("name", v.(string))
  551. }
  552. if v, found := p.p["page"]; found {
  553. vv := strconv.Itoa(v.(int))
  554. u.Set("page", vv)
  555. }
  556. if v, found := p.p["pagesize"]; found {
  557. vv := strconv.Itoa(v.(int))
  558. u.Set("pagesize", vv)
  559. }
  560. if v, found := p.p["systemvmtype"]; found {
  561. u.Set("systemvmtype", v.(string))
  562. }
  563. if v, found := p.p["virtualmachineid"]; found {
  564. u.Set("virtualmachineid", v.(string))
  565. }
  566. return u
  567. }
  568. func (p *ListServiceOfferingsParams) SetDomainid(v string) {
  569. if p.p == nil {
  570. p.p = make(map[string]interface{})
  571. }
  572. p.p["domainid"] = v
  573. return
  574. }
  575. func (p *ListServiceOfferingsParams) SetId(v string) {
  576. if p.p == nil {
  577. p.p = make(map[string]interface{})
  578. }
  579. p.p["id"] = v
  580. return
  581. }
  582. func (p *ListServiceOfferingsParams) SetIsrecursive(v bool) {
  583. if p.p == nil {
  584. p.p = make(map[string]interface{})
  585. }
  586. p.p["isrecursive"] = v
  587. return
  588. }
  589. func (p *ListServiceOfferingsParams) SetIssystem(v bool) {
  590. if p.p == nil {
  591. p.p = make(map[string]interface{})
  592. }
  593. p.p["issystem"] = v
  594. return
  595. }
  596. func (p *ListServiceOfferingsParams) SetKeyword(v string) {
  597. if p.p == nil {
  598. p.p = make(map[string]interface{})
  599. }
  600. p.p["keyword"] = v
  601. return
  602. }
  603. func (p *ListServiceOfferingsParams) SetListall(v bool) {
  604. if p.p == nil {
  605. p.p = make(map[string]interface{})
  606. }
  607. p.p["listall"] = v
  608. return
  609. }
  610. func (p *ListServiceOfferingsParams) SetName(v string) {
  611. if p.p == nil {
  612. p.p = make(map[string]interface{})
  613. }
  614. p.p["name"] = v
  615. return
  616. }
  617. func (p *ListServiceOfferingsParams) SetPage(v int) {
  618. if p.p == nil {
  619. p.p = make(map[string]interface{})
  620. }
  621. p.p["page"] = v
  622. return
  623. }
  624. func (p *ListServiceOfferingsParams) SetPagesize(v int) {
  625. if p.p == nil {
  626. p.p = make(map[string]interface{})
  627. }
  628. p.p["pagesize"] = v
  629. return
  630. }
  631. func (p *ListServiceOfferingsParams) SetSystemvmtype(v string) {
  632. if p.p == nil {
  633. p.p = make(map[string]interface{})
  634. }
  635. p.p["systemvmtype"] = v
  636. return
  637. }
  638. func (p *ListServiceOfferingsParams) SetVirtualmachineid(v string) {
  639. if p.p == nil {
  640. p.p = make(map[string]interface{})
  641. }
  642. p.p["virtualmachineid"] = v
  643. return
  644. }
  645. // You should always use this function to get a new ListServiceOfferingsParams instance,
  646. // as then you are sure you have configured all required params
  647. func (s *ServiceOfferingService) NewListServiceOfferingsParams() *ListServiceOfferingsParams {
  648. p := &ListServiceOfferingsParams{}
  649. p.p = make(map[string]interface{})
  650. return p
  651. }
  652. // This is a courtesy helper function, which in some cases may not work as expected!
  653. func (s *ServiceOfferingService) GetServiceOfferingID(name string, opts ...OptionFunc) (string, int, error) {
  654. p := &ListServiceOfferingsParams{}
  655. p.p = make(map[string]interface{})
  656. p.p["name"] = name
  657. for _, fn := range opts {
  658. if err := fn(s.cs, p); err != nil {
  659. return "", -1, err
  660. }
  661. }
  662. l, err := s.ListServiceOfferings(p)
  663. if err != nil {
  664. return "", -1, err
  665. }
  666. if l.Count == 0 {
  667. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  668. }
  669. if l.Count == 1 {
  670. return l.ServiceOfferings[0].Id, l.Count, nil
  671. }
  672. if l.Count > 1 {
  673. for _, v := range l.ServiceOfferings {
  674. if v.Name == name {
  675. return v.Id, l.Count, nil
  676. }
  677. }
  678. }
  679. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  680. }
  681. // This is a courtesy helper function, which in some cases may not work as expected!
  682. func (s *ServiceOfferingService) GetServiceOfferingByName(name string, opts ...OptionFunc) (*ServiceOffering, int, error) {
  683. id, count, err := s.GetServiceOfferingID(name, opts...)
  684. if err != nil {
  685. return nil, count, err
  686. }
  687. r, count, err := s.GetServiceOfferingByID(id, opts...)
  688. if err != nil {
  689. return nil, count, err
  690. }
  691. return r, count, nil
  692. }
  693. // This is a courtesy helper function, which in some cases may not work as expected!
  694. func (s *ServiceOfferingService) GetServiceOfferingByID(id string, opts ...OptionFunc) (*ServiceOffering, int, error) {
  695. p := &ListServiceOfferingsParams{}
  696. p.p = make(map[string]interface{})
  697. p.p["id"] = id
  698. for _, fn := range opts {
  699. if err := fn(s.cs, p); err != nil {
  700. return nil, -1, err
  701. }
  702. }
  703. l, err := s.ListServiceOfferings(p)
  704. if err != nil {
  705. if strings.Contains(err.Error(), fmt.Sprintf(
  706. "Invalid parameter id value=%s due to incorrect long value format, "+
  707. "or entity does not exist", id)) {
  708. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  709. }
  710. return nil, -1, err
  711. }
  712. if l.Count == 0 {
  713. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  714. }
  715. if l.Count == 1 {
  716. return l.ServiceOfferings[0], l.Count, nil
  717. }
  718. return nil, l.Count, fmt.Errorf("There is more then one result for ServiceOffering UUID: %s!", id)
  719. }
  720. // Lists all available service offerings.
  721. func (s *ServiceOfferingService) ListServiceOfferings(p *ListServiceOfferingsParams) (*ListServiceOfferingsResponse, error) {
  722. resp, err := s.cs.newRequest("listServiceOfferings", p.toURLValues())
  723. if err != nil {
  724. return nil, err
  725. }
  726. var r ListServiceOfferingsResponse
  727. if err := json.Unmarshal(resp, &r); err != nil {
  728. return nil, err
  729. }
  730. return &r, nil
  731. }
  732. type ListServiceOfferingsResponse struct {
  733. Count int `json:"count"`
  734. ServiceOfferings []*ServiceOffering `json:"serviceoffering"`
  735. }
  736. type ServiceOffering struct {
  737. Cpunumber int `json:"cpunumber,omitempty"`
  738. Cpuspeed int `json:"cpuspeed,omitempty"`
  739. Created string `json:"created,omitempty"`
  740. Defaultuse bool `json:"defaultuse,omitempty"`
  741. Deploymentplanner string `json:"deploymentplanner,omitempty"`
  742. DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
  743. DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
  744. DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
  745. DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
  746. Displaytext string `json:"displaytext,omitempty"`
  747. Domain string `json:"domain,omitempty"`
  748. Domainid string `json:"domainid,omitempty"`
  749. Hosttags string `json:"hosttags,omitempty"`
  750. Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
  751. Id string `json:"id,omitempty"`
  752. Iscustomized bool `json:"iscustomized,omitempty"`
  753. Iscustomizediops bool `json:"iscustomizediops,omitempty"`
  754. Issystem bool `json:"issystem,omitempty"`
  755. Isvolatile bool `json:"isvolatile,omitempty"`
  756. Limitcpuuse bool `json:"limitcpuuse,omitempty"`
  757. Maxiops int64 `json:"maxiops,omitempty"`
  758. Memory int `json:"memory,omitempty"`
  759. Miniops int64 `json:"miniops,omitempty"`
  760. Name string `json:"name,omitempty"`
  761. Networkrate int `json:"networkrate,omitempty"`
  762. Offerha bool `json:"offerha,omitempty"`
  763. Provisioningtype string `json:"provisioningtype,omitempty"`
  764. Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
  765. Storagetype string `json:"storagetype,omitempty"`
  766. Systemvmtype string `json:"systemvmtype,omitempty"`
  767. Tags string `json:"tags,omitempty"`
  768. }