1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063 |
- //
- // Copyright 2016, Sander van Harmelen
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- // See the License for the specific language governing permissions and
- // limitations under the License.
- //
- package cloudstack
- import (
- "encoding/json"
- "fmt"
- "net/url"
- "strconv"
- "strings"
- )
- type AddImageStoreParams struct {
- p map[string]interface{}
- }
- func (p *AddImageStoreParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["details"]; found {
- i := 0
- for k, vv := range v.(map[string]string) {
- u.Set(fmt.Sprintf("details[%d].key", i), k)
- u.Set(fmt.Sprintf("details[%d].value", i), vv)
- i++
- }
- }
- if v, found := p.p["name"]; found {
- u.Set("name", v.(string))
- }
- if v, found := p.p["provider"]; found {
- u.Set("provider", v.(string))
- }
- if v, found := p.p["url"]; found {
- u.Set("url", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *AddImageStoreParams) SetDetails(v map[string]string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["details"] = v
- return
- }
- func (p *AddImageStoreParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *AddImageStoreParams) SetProvider(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["provider"] = v
- return
- }
- func (p *AddImageStoreParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- func (p *AddImageStoreParams) SetZoneid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["zoneid"] = v
- return
- }
- // You should always use this function to get a new AddImageStoreParams instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewAddImageStoreParams(provider string) *AddImageStoreParams {
- p := &AddImageStoreParams{}
- p.p = make(map[string]interface{})
- p.p["provider"] = provider
- return p
- }
- // Adds backup image store.
- func (s *ImageStoreService) AddImageStore(p *AddImageStoreParams) (*AddImageStoreResponse, error) {
- resp, err := s.cs.newRequest("addImageStore", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r AddImageStoreResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type AddImageStoreResponse struct {
- Details []string `json:"details,omitempty"`
- Id string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- Providername string `json:"providername,omitempty"`
- Scope string `json:"scope,omitempty"`
- Url string `json:"url,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type AddImageStoreS3Params struct {
- p map[string]interface{}
- }
- func (p *AddImageStoreS3Params) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["accesskey"]; found {
- u.Set("accesskey", v.(string))
- }
- if v, found := p.p["bucket"]; found {
- u.Set("bucket", v.(string))
- }
- if v, found := p.p["connectiontimeout"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("connectiontimeout", vv)
- }
- if v, found := p.p["connectionttl"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("connectionttl", vv)
- }
- if v, found := p.p["endpoint"]; found {
- u.Set("endpoint", v.(string))
- }
- if v, found := p.p["maxerrorretry"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("maxerrorretry", vv)
- }
- if v, found := p.p["s3signer"]; found {
- u.Set("s3signer", v.(string))
- }
- if v, found := p.p["secretkey"]; found {
- u.Set("secretkey", v.(string))
- }
- if v, found := p.p["sockettimeout"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("sockettimeout", vv)
- }
- if v, found := p.p["usehttps"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("usehttps", vv)
- }
- if v, found := p.p["usetcpkeepalive"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("usetcpkeepalive", vv)
- }
- return u
- }
- func (p *AddImageStoreS3Params) SetAccesskey(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["accesskey"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetBucket(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["bucket"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetConnectiontimeout(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["connectiontimeout"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetConnectionttl(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["connectionttl"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetEndpoint(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["endpoint"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetMaxerrorretry(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["maxerrorretry"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetS3signer(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["s3signer"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetSecretkey(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["secretkey"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetSockettimeout(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["sockettimeout"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetUsehttps(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["usehttps"] = v
- return
- }
- func (p *AddImageStoreS3Params) SetUsetcpkeepalive(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["usetcpkeepalive"] = v
- return
- }
- // You should always use this function to get a new AddImageStoreS3Params instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewAddImageStoreS3Params(accesskey string, bucket string, endpoint string, secretkey string) *AddImageStoreS3Params {
- p := &AddImageStoreS3Params{}
- p.p = make(map[string]interface{})
- p.p["accesskey"] = accesskey
- p.p["bucket"] = bucket
- p.p["endpoint"] = endpoint
- p.p["secretkey"] = secretkey
- return p
- }
- // Adds S3 Image Store
- func (s *ImageStoreService) AddImageStoreS3(p *AddImageStoreS3Params) (*AddImageStoreS3Response, error) {
- resp, err := s.cs.newRequest("addImageStoreS3", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r AddImageStoreS3Response
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type AddImageStoreS3Response struct {
- Details []string `json:"details,omitempty"`
- Id string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- Providername string `json:"providername,omitempty"`
- Scope string `json:"scope,omitempty"`
- Url string `json:"url,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type ListImageStoresParams struct {
- p map[string]interface{}
- }
- func (p *ListImageStoresParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- if v, found := p.p["keyword"]; found {
- u.Set("keyword", v.(string))
- }
- if v, found := p.p["name"]; found {
- u.Set("name", v.(string))
- }
- if v, found := p.p["page"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("page", vv)
- }
- if v, found := p.p["pagesize"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("pagesize", vv)
- }
- if v, found := p.p["protocol"]; found {
- u.Set("protocol", v.(string))
- }
- if v, found := p.p["provider"]; found {
- u.Set("provider", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *ListImageStoresParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *ListImageStoresParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListImageStoresParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *ListImageStoresParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListImageStoresParams) SetPagesize(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["pagesize"] = v
- return
- }
- func (p *ListImageStoresParams) SetProtocol(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["protocol"] = v
- return
- }
- func (p *ListImageStoresParams) SetProvider(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["provider"] = v
- return
- }
- func (p *ListImageStoresParams) SetZoneid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["zoneid"] = v
- return
- }
- // You should always use this function to get a new ListImageStoresParams instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewListImageStoresParams() *ListImageStoresParams {
- p := &ListImageStoresParams{}
- p.p = make(map[string]interface{})
- return p
- }
- // This is a courtesy helper function, which in some cases may not work as expected!
- func (s *ImageStoreService) GetImageStoreID(name string, opts ...OptionFunc) (string, int, error) {
- p := &ListImageStoresParams{}
- p.p = make(map[string]interface{})
- p.p["name"] = name
- for _, fn := range opts {
- if err := fn(s.cs, p); err != nil {
- return "", -1, err
- }
- }
- l, err := s.ListImageStores(p)
- if err != nil {
- return "", -1, err
- }
- if l.Count == 0 {
- return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
- }
- if l.Count == 1 {
- return l.ImageStores[0].Id, l.Count, nil
- }
- if l.Count > 1 {
- for _, v := range l.ImageStores {
- if v.Name == name {
- return v.Id, l.Count, nil
- }
- }
- }
- return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
- }
- // This is a courtesy helper function, which in some cases may not work as expected!
- func (s *ImageStoreService) GetImageStoreByName(name string, opts ...OptionFunc) (*ImageStore, int, error) {
- id, count, err := s.GetImageStoreID(name, opts...)
- if err != nil {
- return nil, count, err
- }
- r, count, err := s.GetImageStoreByID(id, opts...)
- if err != nil {
- return nil, count, err
- }
- return r, count, nil
- }
- // This is a courtesy helper function, which in some cases may not work as expected!
- func (s *ImageStoreService) GetImageStoreByID(id string, opts ...OptionFunc) (*ImageStore, int, error) {
- p := &ListImageStoresParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- for _, fn := range opts {
- if err := fn(s.cs, p); err != nil {
- return nil, -1, err
- }
- }
- l, err := s.ListImageStores(p)
- if err != nil {
- if strings.Contains(err.Error(), fmt.Sprintf(
- "Invalid parameter id value=%s due to incorrect long value format, "+
- "or entity does not exist", id)) {
- return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
- }
- return nil, -1, err
- }
- if l.Count == 0 {
- return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
- }
- if l.Count == 1 {
- return l.ImageStores[0], l.Count, nil
- }
- return nil, l.Count, fmt.Errorf("There is more then one result for ImageStore UUID: %s!", id)
- }
- // Lists image stores.
- func (s *ImageStoreService) ListImageStores(p *ListImageStoresParams) (*ListImageStoresResponse, error) {
- resp, err := s.cs.newRequest("listImageStores", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListImageStoresResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListImageStoresResponse struct {
- Count int `json:"count"`
- ImageStores []*ImageStore `json:"imagestore"`
- }
- type ImageStore struct {
- Details []string `json:"details,omitempty"`
- Id string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- Providername string `json:"providername,omitempty"`
- Scope string `json:"scope,omitempty"`
- Url string `json:"url,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type DeleteImageStoreParams struct {
- p map[string]interface{}
- }
- func (p *DeleteImageStoreParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- return u
- }
- func (p *DeleteImageStoreParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- // You should always use this function to get a new DeleteImageStoreParams instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewDeleteImageStoreParams(id string) *DeleteImageStoreParams {
- p := &DeleteImageStoreParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Deletes an image store or Secondary Storage.
- func (s *ImageStoreService) DeleteImageStore(p *DeleteImageStoreParams) (*DeleteImageStoreResponse, error) {
- resp, err := s.cs.newRequest("deleteImageStore", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r DeleteImageStoreResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type DeleteImageStoreResponse struct {
- Displaytext string `json:"displaytext,omitempty"`
- Success string `json:"success,omitempty"`
- }
- type CreateSecondaryStagingStoreParams struct {
- p map[string]interface{}
- }
- func (p *CreateSecondaryStagingStoreParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["details"]; found {
- i := 0
- for k, vv := range v.(map[string]string) {
- u.Set(fmt.Sprintf("details[%d].key", i), k)
- u.Set(fmt.Sprintf("details[%d].value", i), vv)
- i++
- }
- }
- if v, found := p.p["provider"]; found {
- u.Set("provider", v.(string))
- }
- if v, found := p.p["scope"]; found {
- u.Set("scope", v.(string))
- }
- if v, found := p.p["url"]; found {
- u.Set("url", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *CreateSecondaryStagingStoreParams) SetDetails(v map[string]string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["details"] = v
- return
- }
- func (p *CreateSecondaryStagingStoreParams) SetProvider(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["provider"] = v
- return
- }
- func (p *CreateSecondaryStagingStoreParams) SetScope(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["scope"] = v
- return
- }
- func (p *CreateSecondaryStagingStoreParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- func (p *CreateSecondaryStagingStoreParams) SetZoneid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["zoneid"] = v
- return
- }
- // You should always use this function to get a new CreateSecondaryStagingStoreParams instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewCreateSecondaryStagingStoreParams(url string) *CreateSecondaryStagingStoreParams {
- p := &CreateSecondaryStagingStoreParams{}
- p.p = make(map[string]interface{})
- p.p["url"] = url
- return p
- }
- // create secondary staging store.
- func (s *ImageStoreService) CreateSecondaryStagingStore(p *CreateSecondaryStagingStoreParams) (*CreateSecondaryStagingStoreResponse, error) {
- resp, err := s.cs.newRequest("createSecondaryStagingStore", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r CreateSecondaryStagingStoreResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type CreateSecondaryStagingStoreResponse struct {
- Details []string `json:"details,omitempty"`
- Id string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- Providername string `json:"providername,omitempty"`
- Scope string `json:"scope,omitempty"`
- Url string `json:"url,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type ListSecondaryStagingStoresParams struct {
- p map[string]interface{}
- }
- func (p *ListSecondaryStagingStoresParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- if v, found := p.p["keyword"]; found {
- u.Set("keyword", v.(string))
- }
- if v, found := p.p["name"]; found {
- u.Set("name", v.(string))
- }
- if v, found := p.p["page"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("page", vv)
- }
- if v, found := p.p["pagesize"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("pagesize", vv)
- }
- if v, found := p.p["protocol"]; found {
- u.Set("protocol", v.(string))
- }
- if v, found := p.p["provider"]; found {
- u.Set("provider", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *ListSecondaryStagingStoresParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *ListSecondaryStagingStoresParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListSecondaryStagingStoresParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *ListSecondaryStagingStoresParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListSecondaryStagingStoresParams) SetPagesize(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["pagesize"] = v
- return
- }
- func (p *ListSecondaryStagingStoresParams) SetProtocol(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["protocol"] = v
- return
- }
- func (p *ListSecondaryStagingStoresParams) SetProvider(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["provider"] = v
- return
- }
- func (p *ListSecondaryStagingStoresParams) SetZoneid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["zoneid"] = v
- return
- }
- // You should always use this function to get a new ListSecondaryStagingStoresParams instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewListSecondaryStagingStoresParams() *ListSecondaryStagingStoresParams {
- p := &ListSecondaryStagingStoresParams{}
- p.p = make(map[string]interface{})
- return p
- }
- // This is a courtesy helper function, which in some cases may not work as expected!
- func (s *ImageStoreService) GetSecondaryStagingStoreID(name string, opts ...OptionFunc) (string, int, error) {
- p := &ListSecondaryStagingStoresParams{}
- p.p = make(map[string]interface{})
- p.p["name"] = name
- for _, fn := range opts {
- if err := fn(s.cs, p); err != nil {
- return "", -1, err
- }
- }
- l, err := s.ListSecondaryStagingStores(p)
- if err != nil {
- return "", -1, err
- }
- if l.Count == 0 {
- return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
- }
- if l.Count == 1 {
- return l.SecondaryStagingStores[0].Id, l.Count, nil
- }
- if l.Count > 1 {
- for _, v := range l.SecondaryStagingStores {
- if v.Name == name {
- return v.Id, l.Count, nil
- }
- }
- }
- return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
- }
- // This is a courtesy helper function, which in some cases may not work as expected!
- func (s *ImageStoreService) GetSecondaryStagingStoreByName(name string, opts ...OptionFunc) (*SecondaryStagingStore, int, error) {
- id, count, err := s.GetSecondaryStagingStoreID(name, opts...)
- if err != nil {
- return nil, count, err
- }
- r, count, err := s.GetSecondaryStagingStoreByID(id, opts...)
- if err != nil {
- return nil, count, err
- }
- return r, count, nil
- }
- // This is a courtesy helper function, which in some cases may not work as expected!
- func (s *ImageStoreService) GetSecondaryStagingStoreByID(id string, opts ...OptionFunc) (*SecondaryStagingStore, int, error) {
- p := &ListSecondaryStagingStoresParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- for _, fn := range opts {
- if err := fn(s.cs, p); err != nil {
- return nil, -1, err
- }
- }
- l, err := s.ListSecondaryStagingStores(p)
- if err != nil {
- if strings.Contains(err.Error(), fmt.Sprintf(
- "Invalid parameter id value=%s due to incorrect long value format, "+
- "or entity does not exist", id)) {
- return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
- }
- return nil, -1, err
- }
- if l.Count == 0 {
- return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
- }
- if l.Count == 1 {
- return l.SecondaryStagingStores[0], l.Count, nil
- }
- return nil, l.Count, fmt.Errorf("There is more then one result for SecondaryStagingStore UUID: %s!", id)
- }
- // Lists secondary staging stores.
- func (s *ImageStoreService) ListSecondaryStagingStores(p *ListSecondaryStagingStoresParams) (*ListSecondaryStagingStoresResponse, error) {
- resp, err := s.cs.newRequest("listSecondaryStagingStores", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListSecondaryStagingStoresResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListSecondaryStagingStoresResponse struct {
- Count int `json:"count"`
- SecondaryStagingStores []*SecondaryStagingStore `json:"secondarystagingstore"`
- }
- type SecondaryStagingStore struct {
- Details []string `json:"details,omitempty"`
- Id string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- Providername string `json:"providername,omitempty"`
- Scope string `json:"scope,omitempty"`
- Url string `json:"url,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type DeleteSecondaryStagingStoreParams struct {
- p map[string]interface{}
- }
- func (p *DeleteSecondaryStagingStoreParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- return u
- }
- func (p *DeleteSecondaryStagingStoreParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- // You should always use this function to get a new DeleteSecondaryStagingStoreParams instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewDeleteSecondaryStagingStoreParams(id string) *DeleteSecondaryStagingStoreParams {
- p := &DeleteSecondaryStagingStoreParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Deletes a secondary staging store .
- func (s *ImageStoreService) DeleteSecondaryStagingStore(p *DeleteSecondaryStagingStoreParams) (*DeleteSecondaryStagingStoreResponse, error) {
- resp, err := s.cs.newRequest("deleteSecondaryStagingStore", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r DeleteSecondaryStagingStoreResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type DeleteSecondaryStagingStoreResponse struct {
- Displaytext string `json:"displaytext,omitempty"`
- Success string `json:"success,omitempty"`
- }
- type UpdateCloudToUseObjectStoreParams struct {
- p map[string]interface{}
- }
- func (p *UpdateCloudToUseObjectStoreParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["details"]; found {
- i := 0
- for k, vv := range v.(map[string]string) {
- u.Set(fmt.Sprintf("details[%d].key", i), k)
- u.Set(fmt.Sprintf("details[%d].value", i), vv)
- i++
- }
- }
- if v, found := p.p["name"]; found {
- u.Set("name", v.(string))
- }
- if v, found := p.p["provider"]; found {
- u.Set("provider", v.(string))
- }
- if v, found := p.p["url"]; found {
- u.Set("url", v.(string))
- }
- return u
- }
- func (p *UpdateCloudToUseObjectStoreParams) SetDetails(v map[string]string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["details"] = v
- return
- }
- func (p *UpdateCloudToUseObjectStoreParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *UpdateCloudToUseObjectStoreParams) SetProvider(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["provider"] = v
- return
- }
- func (p *UpdateCloudToUseObjectStoreParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- // You should always use this function to get a new UpdateCloudToUseObjectStoreParams instance,
- // as then you are sure you have configured all required params
- func (s *ImageStoreService) NewUpdateCloudToUseObjectStoreParams(provider string) *UpdateCloudToUseObjectStoreParams {
- p := &UpdateCloudToUseObjectStoreParams{}
- p.p = make(map[string]interface{})
- p.p["provider"] = provider
- return p
- }
- // Migrate current NFS secondary storages to use object store.
- func (s *ImageStoreService) UpdateCloudToUseObjectStore(p *UpdateCloudToUseObjectStoreParams) (*UpdateCloudToUseObjectStoreResponse, error) {
- resp, err := s.cs.newRequest("updateCloudToUseObjectStore", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r UpdateCloudToUseObjectStoreResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type UpdateCloudToUseObjectStoreResponse struct {
- Details []string `json:"details,omitempty"`
- Id string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- Protocol string `json:"protocol,omitempty"`
- Providername string `json:"providername,omitempty"`
- Scope string `json:"scope,omitempty"`
- Url string `json:"url,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
|