ImageStoreService.go 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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 AddImageStoreParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *AddImageStoreParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["details"]; found {
  33. i := 0
  34. for k, vv := range v.(map[string]string) {
  35. u.Set(fmt.Sprintf("details[%d].key", i), k)
  36. u.Set(fmt.Sprintf("details[%d].value", i), vv)
  37. i++
  38. }
  39. }
  40. if v, found := p.p["name"]; found {
  41. u.Set("name", v.(string))
  42. }
  43. if v, found := p.p["provider"]; found {
  44. u.Set("provider", v.(string))
  45. }
  46. if v, found := p.p["url"]; found {
  47. u.Set("url", v.(string))
  48. }
  49. if v, found := p.p["zoneid"]; found {
  50. u.Set("zoneid", v.(string))
  51. }
  52. return u
  53. }
  54. func (p *AddImageStoreParams) SetDetails(v map[string]string) {
  55. if p.p == nil {
  56. p.p = make(map[string]interface{})
  57. }
  58. p.p["details"] = v
  59. return
  60. }
  61. func (p *AddImageStoreParams) SetName(v string) {
  62. if p.p == nil {
  63. p.p = make(map[string]interface{})
  64. }
  65. p.p["name"] = v
  66. return
  67. }
  68. func (p *AddImageStoreParams) SetProvider(v string) {
  69. if p.p == nil {
  70. p.p = make(map[string]interface{})
  71. }
  72. p.p["provider"] = v
  73. return
  74. }
  75. func (p *AddImageStoreParams) SetUrl(v string) {
  76. if p.p == nil {
  77. p.p = make(map[string]interface{})
  78. }
  79. p.p["url"] = v
  80. return
  81. }
  82. func (p *AddImageStoreParams) SetZoneid(v string) {
  83. if p.p == nil {
  84. p.p = make(map[string]interface{})
  85. }
  86. p.p["zoneid"] = v
  87. return
  88. }
  89. // You should always use this function to get a new AddImageStoreParams instance,
  90. // as then you are sure you have configured all required params
  91. func (s *ImageStoreService) NewAddImageStoreParams(provider string) *AddImageStoreParams {
  92. p := &AddImageStoreParams{}
  93. p.p = make(map[string]interface{})
  94. p.p["provider"] = provider
  95. return p
  96. }
  97. // Adds backup image store.
  98. func (s *ImageStoreService) AddImageStore(p *AddImageStoreParams) (*AddImageStoreResponse, error) {
  99. resp, err := s.cs.newRequest("addImageStore", p.toURLValues())
  100. if err != nil {
  101. return nil, err
  102. }
  103. var r AddImageStoreResponse
  104. if err := json.Unmarshal(resp, &r); err != nil {
  105. return nil, err
  106. }
  107. return &r, nil
  108. }
  109. type AddImageStoreResponse struct {
  110. Details []string `json:"details,omitempty"`
  111. Id string `json:"id,omitempty"`
  112. Name string `json:"name,omitempty"`
  113. Protocol string `json:"protocol,omitempty"`
  114. Providername string `json:"providername,omitempty"`
  115. Scope string `json:"scope,omitempty"`
  116. Url string `json:"url,omitempty"`
  117. Zoneid string `json:"zoneid,omitempty"`
  118. Zonename string `json:"zonename,omitempty"`
  119. }
  120. type AddImageStoreS3Params struct {
  121. p map[string]interface{}
  122. }
  123. func (p *AddImageStoreS3Params) toURLValues() url.Values {
  124. u := url.Values{}
  125. if p.p == nil {
  126. return u
  127. }
  128. if v, found := p.p["accesskey"]; found {
  129. u.Set("accesskey", v.(string))
  130. }
  131. if v, found := p.p["bucket"]; found {
  132. u.Set("bucket", v.(string))
  133. }
  134. if v, found := p.p["connectiontimeout"]; found {
  135. vv := strconv.Itoa(v.(int))
  136. u.Set("connectiontimeout", vv)
  137. }
  138. if v, found := p.p["connectionttl"]; found {
  139. vv := strconv.Itoa(v.(int))
  140. u.Set("connectionttl", vv)
  141. }
  142. if v, found := p.p["endpoint"]; found {
  143. u.Set("endpoint", v.(string))
  144. }
  145. if v, found := p.p["maxerrorretry"]; found {
  146. vv := strconv.Itoa(v.(int))
  147. u.Set("maxerrorretry", vv)
  148. }
  149. if v, found := p.p["s3signer"]; found {
  150. u.Set("s3signer", v.(string))
  151. }
  152. if v, found := p.p["secretkey"]; found {
  153. u.Set("secretkey", v.(string))
  154. }
  155. if v, found := p.p["sockettimeout"]; found {
  156. vv := strconv.Itoa(v.(int))
  157. u.Set("sockettimeout", vv)
  158. }
  159. if v, found := p.p["usehttps"]; found {
  160. vv := strconv.FormatBool(v.(bool))
  161. u.Set("usehttps", vv)
  162. }
  163. if v, found := p.p["usetcpkeepalive"]; found {
  164. vv := strconv.FormatBool(v.(bool))
  165. u.Set("usetcpkeepalive", vv)
  166. }
  167. return u
  168. }
  169. func (p *AddImageStoreS3Params) SetAccesskey(v string) {
  170. if p.p == nil {
  171. p.p = make(map[string]interface{})
  172. }
  173. p.p["accesskey"] = v
  174. return
  175. }
  176. func (p *AddImageStoreS3Params) SetBucket(v string) {
  177. if p.p == nil {
  178. p.p = make(map[string]interface{})
  179. }
  180. p.p["bucket"] = v
  181. return
  182. }
  183. func (p *AddImageStoreS3Params) SetConnectiontimeout(v int) {
  184. if p.p == nil {
  185. p.p = make(map[string]interface{})
  186. }
  187. p.p["connectiontimeout"] = v
  188. return
  189. }
  190. func (p *AddImageStoreS3Params) SetConnectionttl(v int) {
  191. if p.p == nil {
  192. p.p = make(map[string]interface{})
  193. }
  194. p.p["connectionttl"] = v
  195. return
  196. }
  197. func (p *AddImageStoreS3Params) SetEndpoint(v string) {
  198. if p.p == nil {
  199. p.p = make(map[string]interface{})
  200. }
  201. p.p["endpoint"] = v
  202. return
  203. }
  204. func (p *AddImageStoreS3Params) SetMaxerrorretry(v int) {
  205. if p.p == nil {
  206. p.p = make(map[string]interface{})
  207. }
  208. p.p["maxerrorretry"] = v
  209. return
  210. }
  211. func (p *AddImageStoreS3Params) SetS3signer(v string) {
  212. if p.p == nil {
  213. p.p = make(map[string]interface{})
  214. }
  215. p.p["s3signer"] = v
  216. return
  217. }
  218. func (p *AddImageStoreS3Params) SetSecretkey(v string) {
  219. if p.p == nil {
  220. p.p = make(map[string]interface{})
  221. }
  222. p.p["secretkey"] = v
  223. return
  224. }
  225. func (p *AddImageStoreS3Params) SetSockettimeout(v int) {
  226. if p.p == nil {
  227. p.p = make(map[string]interface{})
  228. }
  229. p.p["sockettimeout"] = v
  230. return
  231. }
  232. func (p *AddImageStoreS3Params) SetUsehttps(v bool) {
  233. if p.p == nil {
  234. p.p = make(map[string]interface{})
  235. }
  236. p.p["usehttps"] = v
  237. return
  238. }
  239. func (p *AddImageStoreS3Params) SetUsetcpkeepalive(v bool) {
  240. if p.p == nil {
  241. p.p = make(map[string]interface{})
  242. }
  243. p.p["usetcpkeepalive"] = v
  244. return
  245. }
  246. // You should always use this function to get a new AddImageStoreS3Params instance,
  247. // as then you are sure you have configured all required params
  248. func (s *ImageStoreService) NewAddImageStoreS3Params(accesskey string, bucket string, endpoint string, secretkey string) *AddImageStoreS3Params {
  249. p := &AddImageStoreS3Params{}
  250. p.p = make(map[string]interface{})
  251. p.p["accesskey"] = accesskey
  252. p.p["bucket"] = bucket
  253. p.p["endpoint"] = endpoint
  254. p.p["secretkey"] = secretkey
  255. return p
  256. }
  257. // Adds S3 Image Store
  258. func (s *ImageStoreService) AddImageStoreS3(p *AddImageStoreS3Params) (*AddImageStoreS3Response, error) {
  259. resp, err := s.cs.newRequest("addImageStoreS3", p.toURLValues())
  260. if err != nil {
  261. return nil, err
  262. }
  263. var r AddImageStoreS3Response
  264. if err := json.Unmarshal(resp, &r); err != nil {
  265. return nil, err
  266. }
  267. return &r, nil
  268. }
  269. type AddImageStoreS3Response struct {
  270. Details []string `json:"details,omitempty"`
  271. Id string `json:"id,omitempty"`
  272. Name string `json:"name,omitempty"`
  273. Protocol string `json:"protocol,omitempty"`
  274. Providername string `json:"providername,omitempty"`
  275. Scope string `json:"scope,omitempty"`
  276. Url string `json:"url,omitempty"`
  277. Zoneid string `json:"zoneid,omitempty"`
  278. Zonename string `json:"zonename,omitempty"`
  279. }
  280. type ListImageStoresParams struct {
  281. p map[string]interface{}
  282. }
  283. func (p *ListImageStoresParams) toURLValues() url.Values {
  284. u := url.Values{}
  285. if p.p == nil {
  286. return u
  287. }
  288. if v, found := p.p["id"]; found {
  289. u.Set("id", v.(string))
  290. }
  291. if v, found := p.p["keyword"]; found {
  292. u.Set("keyword", v.(string))
  293. }
  294. if v, found := p.p["name"]; found {
  295. u.Set("name", v.(string))
  296. }
  297. if v, found := p.p["page"]; found {
  298. vv := strconv.Itoa(v.(int))
  299. u.Set("page", vv)
  300. }
  301. if v, found := p.p["pagesize"]; found {
  302. vv := strconv.Itoa(v.(int))
  303. u.Set("pagesize", vv)
  304. }
  305. if v, found := p.p["protocol"]; found {
  306. u.Set("protocol", v.(string))
  307. }
  308. if v, found := p.p["provider"]; found {
  309. u.Set("provider", v.(string))
  310. }
  311. if v, found := p.p["zoneid"]; found {
  312. u.Set("zoneid", v.(string))
  313. }
  314. return u
  315. }
  316. func (p *ListImageStoresParams) SetId(v string) {
  317. if p.p == nil {
  318. p.p = make(map[string]interface{})
  319. }
  320. p.p["id"] = v
  321. return
  322. }
  323. func (p *ListImageStoresParams) SetKeyword(v string) {
  324. if p.p == nil {
  325. p.p = make(map[string]interface{})
  326. }
  327. p.p["keyword"] = v
  328. return
  329. }
  330. func (p *ListImageStoresParams) SetName(v string) {
  331. if p.p == nil {
  332. p.p = make(map[string]interface{})
  333. }
  334. p.p["name"] = v
  335. return
  336. }
  337. func (p *ListImageStoresParams) SetPage(v int) {
  338. if p.p == nil {
  339. p.p = make(map[string]interface{})
  340. }
  341. p.p["page"] = v
  342. return
  343. }
  344. func (p *ListImageStoresParams) SetPagesize(v int) {
  345. if p.p == nil {
  346. p.p = make(map[string]interface{})
  347. }
  348. p.p["pagesize"] = v
  349. return
  350. }
  351. func (p *ListImageStoresParams) SetProtocol(v string) {
  352. if p.p == nil {
  353. p.p = make(map[string]interface{})
  354. }
  355. p.p["protocol"] = v
  356. return
  357. }
  358. func (p *ListImageStoresParams) SetProvider(v string) {
  359. if p.p == nil {
  360. p.p = make(map[string]interface{})
  361. }
  362. p.p["provider"] = v
  363. return
  364. }
  365. func (p *ListImageStoresParams) SetZoneid(v string) {
  366. if p.p == nil {
  367. p.p = make(map[string]interface{})
  368. }
  369. p.p["zoneid"] = v
  370. return
  371. }
  372. // You should always use this function to get a new ListImageStoresParams instance,
  373. // as then you are sure you have configured all required params
  374. func (s *ImageStoreService) NewListImageStoresParams() *ListImageStoresParams {
  375. p := &ListImageStoresParams{}
  376. p.p = make(map[string]interface{})
  377. return p
  378. }
  379. // This is a courtesy helper function, which in some cases may not work as expected!
  380. func (s *ImageStoreService) GetImageStoreID(name string, opts ...OptionFunc) (string, int, error) {
  381. p := &ListImageStoresParams{}
  382. p.p = make(map[string]interface{})
  383. p.p["name"] = name
  384. for _, fn := range opts {
  385. if err := fn(s.cs, p); err != nil {
  386. return "", -1, err
  387. }
  388. }
  389. l, err := s.ListImageStores(p)
  390. if err != nil {
  391. return "", -1, err
  392. }
  393. if l.Count == 0 {
  394. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  395. }
  396. if l.Count == 1 {
  397. return l.ImageStores[0].Id, l.Count, nil
  398. }
  399. if l.Count > 1 {
  400. for _, v := range l.ImageStores {
  401. if v.Name == name {
  402. return v.Id, l.Count, nil
  403. }
  404. }
  405. }
  406. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  407. }
  408. // This is a courtesy helper function, which in some cases may not work as expected!
  409. func (s *ImageStoreService) GetImageStoreByName(name string, opts ...OptionFunc) (*ImageStore, int, error) {
  410. id, count, err := s.GetImageStoreID(name, opts...)
  411. if err != nil {
  412. return nil, count, err
  413. }
  414. r, count, err := s.GetImageStoreByID(id, opts...)
  415. if err != nil {
  416. return nil, count, err
  417. }
  418. return r, count, nil
  419. }
  420. // This is a courtesy helper function, which in some cases may not work as expected!
  421. func (s *ImageStoreService) GetImageStoreByID(id string, opts ...OptionFunc) (*ImageStore, int, error) {
  422. p := &ListImageStoresParams{}
  423. p.p = make(map[string]interface{})
  424. p.p["id"] = id
  425. for _, fn := range opts {
  426. if err := fn(s.cs, p); err != nil {
  427. return nil, -1, err
  428. }
  429. }
  430. l, err := s.ListImageStores(p)
  431. if err != nil {
  432. if strings.Contains(err.Error(), fmt.Sprintf(
  433. "Invalid parameter id value=%s due to incorrect long value format, "+
  434. "or entity does not exist", id)) {
  435. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  436. }
  437. return nil, -1, err
  438. }
  439. if l.Count == 0 {
  440. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  441. }
  442. if l.Count == 1 {
  443. return l.ImageStores[0], l.Count, nil
  444. }
  445. return nil, l.Count, fmt.Errorf("There is more then one result for ImageStore UUID: %s!", id)
  446. }
  447. // Lists image stores.
  448. func (s *ImageStoreService) ListImageStores(p *ListImageStoresParams) (*ListImageStoresResponse, error) {
  449. resp, err := s.cs.newRequest("listImageStores", p.toURLValues())
  450. if err != nil {
  451. return nil, err
  452. }
  453. var r ListImageStoresResponse
  454. if err := json.Unmarshal(resp, &r); err != nil {
  455. return nil, err
  456. }
  457. return &r, nil
  458. }
  459. type ListImageStoresResponse struct {
  460. Count int `json:"count"`
  461. ImageStores []*ImageStore `json:"imagestore"`
  462. }
  463. type ImageStore struct {
  464. Details []string `json:"details,omitempty"`
  465. Id string `json:"id,omitempty"`
  466. Name string `json:"name,omitempty"`
  467. Protocol string `json:"protocol,omitempty"`
  468. Providername string `json:"providername,omitempty"`
  469. Scope string `json:"scope,omitempty"`
  470. Url string `json:"url,omitempty"`
  471. Zoneid string `json:"zoneid,omitempty"`
  472. Zonename string `json:"zonename,omitempty"`
  473. }
  474. type DeleteImageStoreParams struct {
  475. p map[string]interface{}
  476. }
  477. func (p *DeleteImageStoreParams) toURLValues() url.Values {
  478. u := url.Values{}
  479. if p.p == nil {
  480. return u
  481. }
  482. if v, found := p.p["id"]; found {
  483. u.Set("id", v.(string))
  484. }
  485. return u
  486. }
  487. func (p *DeleteImageStoreParams) SetId(v string) {
  488. if p.p == nil {
  489. p.p = make(map[string]interface{})
  490. }
  491. p.p["id"] = v
  492. return
  493. }
  494. // You should always use this function to get a new DeleteImageStoreParams instance,
  495. // as then you are sure you have configured all required params
  496. func (s *ImageStoreService) NewDeleteImageStoreParams(id string) *DeleteImageStoreParams {
  497. p := &DeleteImageStoreParams{}
  498. p.p = make(map[string]interface{})
  499. p.p["id"] = id
  500. return p
  501. }
  502. // Deletes an image store or Secondary Storage.
  503. func (s *ImageStoreService) DeleteImageStore(p *DeleteImageStoreParams) (*DeleteImageStoreResponse, error) {
  504. resp, err := s.cs.newRequest("deleteImageStore", p.toURLValues())
  505. if err != nil {
  506. return nil, err
  507. }
  508. var r DeleteImageStoreResponse
  509. if err := json.Unmarshal(resp, &r); err != nil {
  510. return nil, err
  511. }
  512. return &r, nil
  513. }
  514. type DeleteImageStoreResponse struct {
  515. Displaytext string `json:"displaytext,omitempty"`
  516. Success string `json:"success,omitempty"`
  517. }
  518. type CreateSecondaryStagingStoreParams struct {
  519. p map[string]interface{}
  520. }
  521. func (p *CreateSecondaryStagingStoreParams) toURLValues() url.Values {
  522. u := url.Values{}
  523. if p.p == nil {
  524. return u
  525. }
  526. if v, found := p.p["details"]; found {
  527. i := 0
  528. for k, vv := range v.(map[string]string) {
  529. u.Set(fmt.Sprintf("details[%d].key", i), k)
  530. u.Set(fmt.Sprintf("details[%d].value", i), vv)
  531. i++
  532. }
  533. }
  534. if v, found := p.p["provider"]; found {
  535. u.Set("provider", v.(string))
  536. }
  537. if v, found := p.p["scope"]; found {
  538. u.Set("scope", v.(string))
  539. }
  540. if v, found := p.p["url"]; found {
  541. u.Set("url", v.(string))
  542. }
  543. if v, found := p.p["zoneid"]; found {
  544. u.Set("zoneid", v.(string))
  545. }
  546. return u
  547. }
  548. func (p *CreateSecondaryStagingStoreParams) SetDetails(v map[string]string) {
  549. if p.p == nil {
  550. p.p = make(map[string]interface{})
  551. }
  552. p.p["details"] = v
  553. return
  554. }
  555. func (p *CreateSecondaryStagingStoreParams) SetProvider(v string) {
  556. if p.p == nil {
  557. p.p = make(map[string]interface{})
  558. }
  559. p.p["provider"] = v
  560. return
  561. }
  562. func (p *CreateSecondaryStagingStoreParams) SetScope(v string) {
  563. if p.p == nil {
  564. p.p = make(map[string]interface{})
  565. }
  566. p.p["scope"] = v
  567. return
  568. }
  569. func (p *CreateSecondaryStagingStoreParams) SetUrl(v string) {
  570. if p.p == nil {
  571. p.p = make(map[string]interface{})
  572. }
  573. p.p["url"] = v
  574. return
  575. }
  576. func (p *CreateSecondaryStagingStoreParams) SetZoneid(v string) {
  577. if p.p == nil {
  578. p.p = make(map[string]interface{})
  579. }
  580. p.p["zoneid"] = v
  581. return
  582. }
  583. // You should always use this function to get a new CreateSecondaryStagingStoreParams instance,
  584. // as then you are sure you have configured all required params
  585. func (s *ImageStoreService) NewCreateSecondaryStagingStoreParams(url string) *CreateSecondaryStagingStoreParams {
  586. p := &CreateSecondaryStagingStoreParams{}
  587. p.p = make(map[string]interface{})
  588. p.p["url"] = url
  589. return p
  590. }
  591. // create secondary staging store.
  592. func (s *ImageStoreService) CreateSecondaryStagingStore(p *CreateSecondaryStagingStoreParams) (*CreateSecondaryStagingStoreResponse, error) {
  593. resp, err := s.cs.newRequest("createSecondaryStagingStore", p.toURLValues())
  594. if err != nil {
  595. return nil, err
  596. }
  597. var r CreateSecondaryStagingStoreResponse
  598. if err := json.Unmarshal(resp, &r); err != nil {
  599. return nil, err
  600. }
  601. return &r, nil
  602. }
  603. type CreateSecondaryStagingStoreResponse struct {
  604. Details []string `json:"details,omitempty"`
  605. Id string `json:"id,omitempty"`
  606. Name string `json:"name,omitempty"`
  607. Protocol string `json:"protocol,omitempty"`
  608. Providername string `json:"providername,omitempty"`
  609. Scope string `json:"scope,omitempty"`
  610. Url string `json:"url,omitempty"`
  611. Zoneid string `json:"zoneid,omitempty"`
  612. Zonename string `json:"zonename,omitempty"`
  613. }
  614. type ListSecondaryStagingStoresParams struct {
  615. p map[string]interface{}
  616. }
  617. func (p *ListSecondaryStagingStoresParams) toURLValues() url.Values {
  618. u := url.Values{}
  619. if p.p == nil {
  620. return u
  621. }
  622. if v, found := p.p["id"]; found {
  623. u.Set("id", v.(string))
  624. }
  625. if v, found := p.p["keyword"]; found {
  626. u.Set("keyword", v.(string))
  627. }
  628. if v, found := p.p["name"]; found {
  629. u.Set("name", v.(string))
  630. }
  631. if v, found := p.p["page"]; found {
  632. vv := strconv.Itoa(v.(int))
  633. u.Set("page", vv)
  634. }
  635. if v, found := p.p["pagesize"]; found {
  636. vv := strconv.Itoa(v.(int))
  637. u.Set("pagesize", vv)
  638. }
  639. if v, found := p.p["protocol"]; found {
  640. u.Set("protocol", v.(string))
  641. }
  642. if v, found := p.p["provider"]; found {
  643. u.Set("provider", v.(string))
  644. }
  645. if v, found := p.p["zoneid"]; found {
  646. u.Set("zoneid", v.(string))
  647. }
  648. return u
  649. }
  650. func (p *ListSecondaryStagingStoresParams) SetId(v string) {
  651. if p.p == nil {
  652. p.p = make(map[string]interface{})
  653. }
  654. p.p["id"] = v
  655. return
  656. }
  657. func (p *ListSecondaryStagingStoresParams) SetKeyword(v string) {
  658. if p.p == nil {
  659. p.p = make(map[string]interface{})
  660. }
  661. p.p["keyword"] = v
  662. return
  663. }
  664. func (p *ListSecondaryStagingStoresParams) SetName(v string) {
  665. if p.p == nil {
  666. p.p = make(map[string]interface{})
  667. }
  668. p.p["name"] = v
  669. return
  670. }
  671. func (p *ListSecondaryStagingStoresParams) SetPage(v int) {
  672. if p.p == nil {
  673. p.p = make(map[string]interface{})
  674. }
  675. p.p["page"] = v
  676. return
  677. }
  678. func (p *ListSecondaryStagingStoresParams) SetPagesize(v int) {
  679. if p.p == nil {
  680. p.p = make(map[string]interface{})
  681. }
  682. p.p["pagesize"] = v
  683. return
  684. }
  685. func (p *ListSecondaryStagingStoresParams) SetProtocol(v string) {
  686. if p.p == nil {
  687. p.p = make(map[string]interface{})
  688. }
  689. p.p["protocol"] = v
  690. return
  691. }
  692. func (p *ListSecondaryStagingStoresParams) SetProvider(v string) {
  693. if p.p == nil {
  694. p.p = make(map[string]interface{})
  695. }
  696. p.p["provider"] = v
  697. return
  698. }
  699. func (p *ListSecondaryStagingStoresParams) SetZoneid(v string) {
  700. if p.p == nil {
  701. p.p = make(map[string]interface{})
  702. }
  703. p.p["zoneid"] = v
  704. return
  705. }
  706. // You should always use this function to get a new ListSecondaryStagingStoresParams instance,
  707. // as then you are sure you have configured all required params
  708. func (s *ImageStoreService) NewListSecondaryStagingStoresParams() *ListSecondaryStagingStoresParams {
  709. p := &ListSecondaryStagingStoresParams{}
  710. p.p = make(map[string]interface{})
  711. return p
  712. }
  713. // This is a courtesy helper function, which in some cases may not work as expected!
  714. func (s *ImageStoreService) GetSecondaryStagingStoreID(name string, opts ...OptionFunc) (string, int, error) {
  715. p := &ListSecondaryStagingStoresParams{}
  716. p.p = make(map[string]interface{})
  717. p.p["name"] = name
  718. for _, fn := range opts {
  719. if err := fn(s.cs, p); err != nil {
  720. return "", -1, err
  721. }
  722. }
  723. l, err := s.ListSecondaryStagingStores(p)
  724. if err != nil {
  725. return "", -1, err
  726. }
  727. if l.Count == 0 {
  728. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  729. }
  730. if l.Count == 1 {
  731. return l.SecondaryStagingStores[0].Id, l.Count, nil
  732. }
  733. if l.Count > 1 {
  734. for _, v := range l.SecondaryStagingStores {
  735. if v.Name == name {
  736. return v.Id, l.Count, nil
  737. }
  738. }
  739. }
  740. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  741. }
  742. // This is a courtesy helper function, which in some cases may not work as expected!
  743. func (s *ImageStoreService) GetSecondaryStagingStoreByName(name string, opts ...OptionFunc) (*SecondaryStagingStore, int, error) {
  744. id, count, err := s.GetSecondaryStagingStoreID(name, opts...)
  745. if err != nil {
  746. return nil, count, err
  747. }
  748. r, count, err := s.GetSecondaryStagingStoreByID(id, opts...)
  749. if err != nil {
  750. return nil, count, err
  751. }
  752. return r, count, nil
  753. }
  754. // This is a courtesy helper function, which in some cases may not work as expected!
  755. func (s *ImageStoreService) GetSecondaryStagingStoreByID(id string, opts ...OptionFunc) (*SecondaryStagingStore, int, error) {
  756. p := &ListSecondaryStagingStoresParams{}
  757. p.p = make(map[string]interface{})
  758. p.p["id"] = id
  759. for _, fn := range opts {
  760. if err := fn(s.cs, p); err != nil {
  761. return nil, -1, err
  762. }
  763. }
  764. l, err := s.ListSecondaryStagingStores(p)
  765. if err != nil {
  766. if strings.Contains(err.Error(), fmt.Sprintf(
  767. "Invalid parameter id value=%s due to incorrect long value format, "+
  768. "or entity does not exist", id)) {
  769. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  770. }
  771. return nil, -1, err
  772. }
  773. if l.Count == 0 {
  774. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  775. }
  776. if l.Count == 1 {
  777. return l.SecondaryStagingStores[0], l.Count, nil
  778. }
  779. return nil, l.Count, fmt.Errorf("There is more then one result for SecondaryStagingStore UUID: %s!", id)
  780. }
  781. // Lists secondary staging stores.
  782. func (s *ImageStoreService) ListSecondaryStagingStores(p *ListSecondaryStagingStoresParams) (*ListSecondaryStagingStoresResponse, error) {
  783. resp, err := s.cs.newRequest("listSecondaryStagingStores", p.toURLValues())
  784. if err != nil {
  785. return nil, err
  786. }
  787. var r ListSecondaryStagingStoresResponse
  788. if err := json.Unmarshal(resp, &r); err != nil {
  789. return nil, err
  790. }
  791. return &r, nil
  792. }
  793. type ListSecondaryStagingStoresResponse struct {
  794. Count int `json:"count"`
  795. SecondaryStagingStores []*SecondaryStagingStore `json:"secondarystagingstore"`
  796. }
  797. type SecondaryStagingStore struct {
  798. Details []string `json:"details,omitempty"`
  799. Id string `json:"id,omitempty"`
  800. Name string `json:"name,omitempty"`
  801. Protocol string `json:"protocol,omitempty"`
  802. Providername string `json:"providername,omitempty"`
  803. Scope string `json:"scope,omitempty"`
  804. Url string `json:"url,omitempty"`
  805. Zoneid string `json:"zoneid,omitempty"`
  806. Zonename string `json:"zonename,omitempty"`
  807. }
  808. type DeleteSecondaryStagingStoreParams struct {
  809. p map[string]interface{}
  810. }
  811. func (p *DeleteSecondaryStagingStoreParams) toURLValues() url.Values {
  812. u := url.Values{}
  813. if p.p == nil {
  814. return u
  815. }
  816. if v, found := p.p["id"]; found {
  817. u.Set("id", v.(string))
  818. }
  819. return u
  820. }
  821. func (p *DeleteSecondaryStagingStoreParams) SetId(v string) {
  822. if p.p == nil {
  823. p.p = make(map[string]interface{})
  824. }
  825. p.p["id"] = v
  826. return
  827. }
  828. // You should always use this function to get a new DeleteSecondaryStagingStoreParams instance,
  829. // as then you are sure you have configured all required params
  830. func (s *ImageStoreService) NewDeleteSecondaryStagingStoreParams(id string) *DeleteSecondaryStagingStoreParams {
  831. p := &DeleteSecondaryStagingStoreParams{}
  832. p.p = make(map[string]interface{})
  833. p.p["id"] = id
  834. return p
  835. }
  836. // Deletes a secondary staging store .
  837. func (s *ImageStoreService) DeleteSecondaryStagingStore(p *DeleteSecondaryStagingStoreParams) (*DeleteSecondaryStagingStoreResponse, error) {
  838. resp, err := s.cs.newRequest("deleteSecondaryStagingStore", p.toURLValues())
  839. if err != nil {
  840. return nil, err
  841. }
  842. var r DeleteSecondaryStagingStoreResponse
  843. if err := json.Unmarshal(resp, &r); err != nil {
  844. return nil, err
  845. }
  846. return &r, nil
  847. }
  848. type DeleteSecondaryStagingStoreResponse struct {
  849. Displaytext string `json:"displaytext,omitempty"`
  850. Success string `json:"success,omitempty"`
  851. }
  852. type UpdateCloudToUseObjectStoreParams struct {
  853. p map[string]interface{}
  854. }
  855. func (p *UpdateCloudToUseObjectStoreParams) toURLValues() url.Values {
  856. u := url.Values{}
  857. if p.p == nil {
  858. return u
  859. }
  860. if v, found := p.p["details"]; found {
  861. i := 0
  862. for k, vv := range v.(map[string]string) {
  863. u.Set(fmt.Sprintf("details[%d].key", i), k)
  864. u.Set(fmt.Sprintf("details[%d].value", i), vv)
  865. i++
  866. }
  867. }
  868. if v, found := p.p["name"]; found {
  869. u.Set("name", v.(string))
  870. }
  871. if v, found := p.p["provider"]; found {
  872. u.Set("provider", v.(string))
  873. }
  874. if v, found := p.p["url"]; found {
  875. u.Set("url", v.(string))
  876. }
  877. return u
  878. }
  879. func (p *UpdateCloudToUseObjectStoreParams) SetDetails(v map[string]string) {
  880. if p.p == nil {
  881. p.p = make(map[string]interface{})
  882. }
  883. p.p["details"] = v
  884. return
  885. }
  886. func (p *UpdateCloudToUseObjectStoreParams) SetName(v string) {
  887. if p.p == nil {
  888. p.p = make(map[string]interface{})
  889. }
  890. p.p["name"] = v
  891. return
  892. }
  893. func (p *UpdateCloudToUseObjectStoreParams) SetProvider(v string) {
  894. if p.p == nil {
  895. p.p = make(map[string]interface{})
  896. }
  897. p.p["provider"] = v
  898. return
  899. }
  900. func (p *UpdateCloudToUseObjectStoreParams) SetUrl(v string) {
  901. if p.p == nil {
  902. p.p = make(map[string]interface{})
  903. }
  904. p.p["url"] = v
  905. return
  906. }
  907. // You should always use this function to get a new UpdateCloudToUseObjectStoreParams instance,
  908. // as then you are sure you have configured all required params
  909. func (s *ImageStoreService) NewUpdateCloudToUseObjectStoreParams(provider string) *UpdateCloudToUseObjectStoreParams {
  910. p := &UpdateCloudToUseObjectStoreParams{}
  911. p.p = make(map[string]interface{})
  912. p.p["provider"] = provider
  913. return p
  914. }
  915. // Migrate current NFS secondary storages to use object store.
  916. func (s *ImageStoreService) UpdateCloudToUseObjectStore(p *UpdateCloudToUseObjectStoreParams) (*UpdateCloudToUseObjectStoreResponse, error) {
  917. resp, err := s.cs.newRequest("updateCloudToUseObjectStore", p.toURLValues())
  918. if err != nil {
  919. return nil, err
  920. }
  921. var r UpdateCloudToUseObjectStoreResponse
  922. if err := json.Unmarshal(resp, &r); err != nil {
  923. return nil, err
  924. }
  925. return &r, nil
  926. }
  927. type UpdateCloudToUseObjectStoreResponse struct {
  928. Details []string `json:"details,omitempty"`
  929. Id string `json:"id,omitempty"`
  930. Name string `json:"name,omitempty"`
  931. Protocol string `json:"protocol,omitempty"`
  932. Providername string `json:"providername,omitempty"`
  933. Scope string `json:"scope,omitempty"`
  934. Url string `json:"url,omitempty"`
  935. Zoneid string `json:"zoneid,omitempty"`
  936. Zonename string `json:"zonename,omitempty"`
  937. }