123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854 |
- //
- // 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 CreateServiceOfferingParams struct {
- p map[string]interface{}
- }
- func (p *CreateServiceOfferingParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["bytesreadrate"]; found {
- vv := strconv.FormatInt(v.(int64), 10)
- u.Set("bytesreadrate", vv)
- }
- if v, found := p.p["byteswriterate"]; found {
- vv := strconv.FormatInt(v.(int64), 10)
- u.Set("byteswriterate", vv)
- }
- if v, found := p.p["cpunumber"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("cpunumber", vv)
- }
- if v, found := p.p["cpuspeed"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("cpuspeed", vv)
- }
- if v, found := p.p["customizediops"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("customizediops", vv)
- }
- if v, found := p.p["deploymentplanner"]; found {
- u.Set("deploymentplanner", v.(string))
- }
- if v, found := p.p["displaytext"]; found {
- u.Set("displaytext", v.(string))
- }
- if v, found := p.p["domainid"]; found {
- u.Set("domainid", v.(string))
- }
- if v, found := p.p["hosttags"]; found {
- u.Set("hosttags", v.(string))
- }
- if v, found := p.p["hypervisorsnapshotreserve"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("hypervisorsnapshotreserve", vv)
- }
- if v, found := p.p["iopsreadrate"]; found {
- vv := strconv.FormatInt(v.(int64), 10)
- u.Set("iopsreadrate", vv)
- }
- if v, found := p.p["iopswriterate"]; found {
- vv := strconv.FormatInt(v.(int64), 10)
- u.Set("iopswriterate", vv)
- }
- if v, found := p.p["issystem"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("issystem", vv)
- }
- if v, found := p.p["isvolatile"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("isvolatile", vv)
- }
- if v, found := p.p["limitcpuuse"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("limitcpuuse", vv)
- }
- if v, found := p.p["maxiops"]; found {
- vv := strconv.FormatInt(v.(int64), 10)
- u.Set("maxiops", vv)
- }
- if v, found := p.p["memory"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("memory", vv)
- }
- if v, found := p.p["miniops"]; found {
- vv := strconv.FormatInt(v.(int64), 10)
- u.Set("miniops", vv)
- }
- if v, found := p.p["name"]; found {
- u.Set("name", v.(string))
- }
- if v, found := p.p["networkrate"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("networkrate", vv)
- }
- if v, found := p.p["offerha"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("offerha", vv)
- }
- if v, found := p.p["provisioningtype"]; found {
- u.Set("provisioningtype", v.(string))
- }
- if v, found := p.p["serviceofferingdetails"]; found {
- i := 0
- for k, vv := range v.(map[string]string) {
- u.Set(fmt.Sprintf("serviceofferingdetails[%d].key", i), k)
- u.Set(fmt.Sprintf("serviceofferingdetails[%d].value", i), vv)
- i++
- }
- }
- if v, found := p.p["storagetype"]; found {
- u.Set("storagetype", v.(string))
- }
- if v, found := p.p["systemvmtype"]; found {
- u.Set("systemvmtype", v.(string))
- }
- if v, found := p.p["tags"]; found {
- u.Set("tags", v.(string))
- }
- return u
- }
- func (p *CreateServiceOfferingParams) SetBytesreadrate(v int64) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["bytesreadrate"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetByteswriterate(v int64) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["byteswriterate"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetCpunumber(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["cpunumber"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetCpuspeed(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["cpuspeed"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetCustomizediops(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["customizediops"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetDeploymentplanner(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["deploymentplanner"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetDisplaytext(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["displaytext"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetDomainid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["domainid"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetHosttags(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hosttags"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetHypervisorsnapshotreserve(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hypervisorsnapshotreserve"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetIopsreadrate(v int64) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["iopsreadrate"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetIopswriterate(v int64) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["iopswriterate"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetIssystem(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["issystem"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetIsvolatile(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["isvolatile"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetLimitcpuuse(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["limitcpuuse"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetMaxiops(v int64) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["maxiops"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetMemory(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["memory"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetMiniops(v int64) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["miniops"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetNetworkrate(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["networkrate"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetOfferha(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["offerha"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetProvisioningtype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["provisioningtype"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetServiceofferingdetails(v map[string]string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["serviceofferingdetails"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetStoragetype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["storagetype"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetSystemvmtype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["systemvmtype"] = v
- return
- }
- func (p *CreateServiceOfferingParams) SetTags(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["tags"] = v
- return
- }
- // You should always use this function to get a new CreateServiceOfferingParams instance,
- // as then you are sure you have configured all required params
- func (s *ServiceOfferingService) NewCreateServiceOfferingParams(displaytext string, name string) *CreateServiceOfferingParams {
- p := &CreateServiceOfferingParams{}
- p.p = make(map[string]interface{})
- p.p["displaytext"] = displaytext
- p.p["name"] = name
- return p
- }
- // Creates a service offering.
- func (s *ServiceOfferingService) CreateServiceOffering(p *CreateServiceOfferingParams) (*CreateServiceOfferingResponse, error) {
- resp, err := s.cs.newRequest("createServiceOffering", p.toURLValues())
- if err != nil {
- return nil, err
- }
- if resp, err = getRawValue(resp); err != nil {
- return nil, err
- }
- var r CreateServiceOfferingResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type CreateServiceOfferingResponse struct {
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpuspeed int `json:"cpuspeed,omitempty"`
- Created string `json:"created,omitempty"`
- Defaultuse bool `json:"defaultuse,omitempty"`
- Deploymentplanner string `json:"deploymentplanner,omitempty"`
- DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
- DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
- DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
- DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
- Displaytext string `json:"displaytext,omitempty"`
- Domain string `json:"domain,omitempty"`
- Domainid string `json:"domainid,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
- Id string `json:"id,omitempty"`
- Iscustomized bool `json:"iscustomized,omitempty"`
- Iscustomizediops bool `json:"iscustomizediops,omitempty"`
- Issystem bool `json:"issystem,omitempty"`
- Isvolatile bool `json:"isvolatile,omitempty"`
- Limitcpuuse bool `json:"limitcpuuse,omitempty"`
- Maxiops int64 `json:"maxiops,omitempty"`
- Memory int `json:"memory,omitempty"`
- Miniops int64 `json:"miniops,omitempty"`
- Name string `json:"name,omitempty"`
- Networkrate int `json:"networkrate,omitempty"`
- Offerha bool `json:"offerha,omitempty"`
- Provisioningtype string `json:"provisioningtype,omitempty"`
- Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
- Storagetype string `json:"storagetype,omitempty"`
- Systemvmtype string `json:"systemvmtype,omitempty"`
- Tags string `json:"tags,omitempty"`
- }
- type DeleteServiceOfferingParams struct {
- p map[string]interface{}
- }
- func (p *DeleteServiceOfferingParams) 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 *DeleteServiceOfferingParams) 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 DeleteServiceOfferingParams instance,
- // as then you are sure you have configured all required params
- func (s *ServiceOfferingService) NewDeleteServiceOfferingParams(id string) *DeleteServiceOfferingParams {
- p := &DeleteServiceOfferingParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Deletes a service offering.
- func (s *ServiceOfferingService) DeleteServiceOffering(p *DeleteServiceOfferingParams) (*DeleteServiceOfferingResponse, error) {
- resp, err := s.cs.newRequest("deleteServiceOffering", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r DeleteServiceOfferingResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type DeleteServiceOfferingResponse struct {
- Displaytext string `json:"displaytext,omitempty"`
- Success string `json:"success,omitempty"`
- }
- type UpdateServiceOfferingParams struct {
- p map[string]interface{}
- }
- func (p *UpdateServiceOfferingParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["displaytext"]; found {
- u.Set("displaytext", v.(string))
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- if v, found := p.p["name"]; found {
- u.Set("name", v.(string))
- }
- if v, found := p.p["sortkey"]; found {
- vv := strconv.Itoa(v.(int))
- u.Set("sortkey", vv)
- }
- return u
- }
- func (p *UpdateServiceOfferingParams) SetDisplaytext(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["displaytext"] = v
- return
- }
- func (p *UpdateServiceOfferingParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *UpdateServiceOfferingParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *UpdateServiceOfferingParams) SetSortkey(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["sortkey"] = v
- return
- }
- // You should always use this function to get a new UpdateServiceOfferingParams instance,
- // as then you are sure you have configured all required params
- func (s *ServiceOfferingService) NewUpdateServiceOfferingParams(id string) *UpdateServiceOfferingParams {
- p := &UpdateServiceOfferingParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Updates a service offering.
- func (s *ServiceOfferingService) UpdateServiceOffering(p *UpdateServiceOfferingParams) (*UpdateServiceOfferingResponse, error) {
- resp, err := s.cs.newRequest("updateServiceOffering", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r UpdateServiceOfferingResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type UpdateServiceOfferingResponse struct {
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpuspeed int `json:"cpuspeed,omitempty"`
- Created string `json:"created,omitempty"`
- Defaultuse bool `json:"defaultuse,omitempty"`
- Deploymentplanner string `json:"deploymentplanner,omitempty"`
- DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
- DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
- DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
- DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
- Displaytext string `json:"displaytext,omitempty"`
- Domain string `json:"domain,omitempty"`
- Domainid string `json:"domainid,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
- Id string `json:"id,omitempty"`
- Iscustomized bool `json:"iscustomized,omitempty"`
- Iscustomizediops bool `json:"iscustomizediops,omitempty"`
- Issystem bool `json:"issystem,omitempty"`
- Isvolatile bool `json:"isvolatile,omitempty"`
- Limitcpuuse bool `json:"limitcpuuse,omitempty"`
- Maxiops int64 `json:"maxiops,omitempty"`
- Memory int `json:"memory,omitempty"`
- Miniops int64 `json:"miniops,omitempty"`
- Name string `json:"name,omitempty"`
- Networkrate int `json:"networkrate,omitempty"`
- Offerha bool `json:"offerha,omitempty"`
- Provisioningtype string `json:"provisioningtype,omitempty"`
- Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
- Storagetype string `json:"storagetype,omitempty"`
- Systemvmtype string `json:"systemvmtype,omitempty"`
- Tags string `json:"tags,omitempty"`
- }
- type ListServiceOfferingsParams struct {
- p map[string]interface{}
- }
- func (p *ListServiceOfferingsParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["domainid"]; found {
- u.Set("domainid", v.(string))
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- if v, found := p.p["isrecursive"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("isrecursive", vv)
- }
- if v, found := p.p["issystem"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("issystem", vv)
- }
- if v, found := p.p["keyword"]; found {
- u.Set("keyword", v.(string))
- }
- if v, found := p.p["listall"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("listall", vv)
- }
- 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["systemvmtype"]; found {
- u.Set("systemvmtype", v.(string))
- }
- if v, found := p.p["virtualmachineid"]; found {
- u.Set("virtualmachineid", v.(string))
- }
- return u
- }
- func (p *ListServiceOfferingsParams) SetDomainid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["domainid"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetIsrecursive(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["isrecursive"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetIssystem(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["issystem"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetListall(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["listall"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetPagesize(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["pagesize"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetSystemvmtype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["systemvmtype"] = v
- return
- }
- func (p *ListServiceOfferingsParams) SetVirtualmachineid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["virtualmachineid"] = v
- return
- }
- // You should always use this function to get a new ListServiceOfferingsParams instance,
- // as then you are sure you have configured all required params
- func (s *ServiceOfferingService) NewListServiceOfferingsParams() *ListServiceOfferingsParams {
- p := &ListServiceOfferingsParams{}
- 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 *ServiceOfferingService) GetServiceOfferingID(name string, opts ...OptionFunc) (string, int, error) {
- p := &ListServiceOfferingsParams{}
- 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.ListServiceOfferings(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.ServiceOfferings[0].Id, l.Count, nil
- }
- if l.Count > 1 {
- for _, v := range l.ServiceOfferings {
- 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 *ServiceOfferingService) GetServiceOfferingByName(name string, opts ...OptionFunc) (*ServiceOffering, int, error) {
- id, count, err := s.GetServiceOfferingID(name, opts...)
- if err != nil {
- return nil, count, err
- }
- r, count, err := s.GetServiceOfferingByID(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 *ServiceOfferingService) GetServiceOfferingByID(id string, opts ...OptionFunc) (*ServiceOffering, int, error) {
- p := &ListServiceOfferingsParams{}
- 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.ListServiceOfferings(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.ServiceOfferings[0], l.Count, nil
- }
- return nil, l.Count, fmt.Errorf("There is more then one result for ServiceOffering UUID: %s!", id)
- }
- // Lists all available service offerings.
- func (s *ServiceOfferingService) ListServiceOfferings(p *ListServiceOfferingsParams) (*ListServiceOfferingsResponse, error) {
- resp, err := s.cs.newRequest("listServiceOfferings", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListServiceOfferingsResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListServiceOfferingsResponse struct {
- Count int `json:"count"`
- ServiceOfferings []*ServiceOffering `json:"serviceoffering"`
- }
- type ServiceOffering struct {
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpuspeed int `json:"cpuspeed,omitempty"`
- Created string `json:"created,omitempty"`
- Defaultuse bool `json:"defaultuse,omitempty"`
- Deploymentplanner string `json:"deploymentplanner,omitempty"`
- DiskBytesReadRate int64 `json:"diskBytesReadRate,omitempty"`
- DiskBytesWriteRate int64 `json:"diskBytesWriteRate,omitempty"`
- DiskIopsReadRate int64 `json:"diskIopsReadRate,omitempty"`
- DiskIopsWriteRate int64 `json:"diskIopsWriteRate,omitempty"`
- Displaytext string `json:"displaytext,omitempty"`
- Domain string `json:"domain,omitempty"`
- Domainid string `json:"domainid,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisorsnapshotreserve int `json:"hypervisorsnapshotreserve,omitempty"`
- Id string `json:"id,omitempty"`
- Iscustomized bool `json:"iscustomized,omitempty"`
- Iscustomizediops bool `json:"iscustomizediops,omitempty"`
- Issystem bool `json:"issystem,omitempty"`
- Isvolatile bool `json:"isvolatile,omitempty"`
- Limitcpuuse bool `json:"limitcpuuse,omitempty"`
- Maxiops int64 `json:"maxiops,omitempty"`
- Memory int `json:"memory,omitempty"`
- Miniops int64 `json:"miniops,omitempty"`
- Name string `json:"name,omitempty"`
- Networkrate int `json:"networkrate,omitempty"`
- Offerha bool `json:"offerha,omitempty"`
- Provisioningtype string `json:"provisioningtype,omitempty"`
- Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
- Storagetype string `json:"storagetype,omitempty"`
- Systemvmtype string `json:"systemvmtype,omitempty"`
- Tags string `json:"tags,omitempty"`
- }
|