1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060 |
- //
- // 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 AddClusterParams struct {
- p map[string]interface{}
- }
- func (p *AddClusterParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["allocationstate"]; found {
- u.Set("allocationstate", v.(string))
- }
- if v, found := p.p["clustername"]; found {
- u.Set("clustername", v.(string))
- }
- if v, found := p.p["clustertype"]; found {
- u.Set("clustertype", v.(string))
- }
- if v, found := p.p["guestvswitchname"]; found {
- u.Set("guestvswitchname", v.(string))
- }
- if v, found := p.p["guestvswitchtype"]; found {
- u.Set("guestvswitchtype", v.(string))
- }
- if v, found := p.p["hypervisor"]; found {
- u.Set("hypervisor", v.(string))
- }
- if v, found := p.p["ovm3cluster"]; found {
- u.Set("ovm3cluster", v.(string))
- }
- if v, found := p.p["ovm3pool"]; found {
- u.Set("ovm3pool", v.(string))
- }
- if v, found := p.p["ovm3vip"]; found {
- u.Set("ovm3vip", v.(string))
- }
- if v, found := p.p["password"]; found {
- u.Set("password", v.(string))
- }
- if v, found := p.p["podid"]; found {
- u.Set("podid", v.(string))
- }
- if v, found := p.p["publicvswitchname"]; found {
- u.Set("publicvswitchname", v.(string))
- }
- if v, found := p.p["publicvswitchtype"]; found {
- u.Set("publicvswitchtype", v.(string))
- }
- if v, found := p.p["url"]; found {
- u.Set("url", v.(string))
- }
- if v, found := p.p["username"]; found {
- u.Set("username", v.(string))
- }
- if v, found := p.p["vsmipaddress"]; found {
- u.Set("vsmipaddress", v.(string))
- }
- if v, found := p.p["vsmpassword"]; found {
- u.Set("vsmpassword", v.(string))
- }
- if v, found := p.p["vsmusername"]; found {
- u.Set("vsmusername", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *AddClusterParams) SetAllocationstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["allocationstate"] = v
- return
- }
- func (p *AddClusterParams) SetClustername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clustername"] = v
- return
- }
- func (p *AddClusterParams) SetClustertype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clustertype"] = v
- return
- }
- func (p *AddClusterParams) SetGuestvswitchname(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["guestvswitchname"] = v
- return
- }
- func (p *AddClusterParams) SetGuestvswitchtype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["guestvswitchtype"] = v
- return
- }
- func (p *AddClusterParams) SetHypervisor(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hypervisor"] = v
- return
- }
- func (p *AddClusterParams) SetOvm3cluster(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["ovm3cluster"] = v
- return
- }
- func (p *AddClusterParams) SetOvm3pool(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["ovm3pool"] = v
- return
- }
- func (p *AddClusterParams) SetOvm3vip(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["ovm3vip"] = v
- return
- }
- func (p *AddClusterParams) SetPassword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["password"] = v
- return
- }
- func (p *AddClusterParams) SetPodid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["podid"] = v
- return
- }
- func (p *AddClusterParams) SetPublicvswitchname(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["publicvswitchname"] = v
- return
- }
- func (p *AddClusterParams) SetPublicvswitchtype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["publicvswitchtype"] = v
- return
- }
- func (p *AddClusterParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- func (p *AddClusterParams) SetUsername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["username"] = v
- return
- }
- func (p *AddClusterParams) SetVsmipaddress(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["vsmipaddress"] = v
- return
- }
- func (p *AddClusterParams) SetVsmpassword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["vsmpassword"] = v
- return
- }
- func (p *AddClusterParams) SetVsmusername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["vsmusername"] = v
- return
- }
- func (p *AddClusterParams) 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 AddClusterParams instance,
- // as then you are sure you have configured all required params
- func (s *ClusterService) NewAddClusterParams(clustername string, clustertype string, hypervisor string, podid string, zoneid string) *AddClusterParams {
- p := &AddClusterParams{}
- p.p = make(map[string]interface{})
- p.p["clustername"] = clustername
- p.p["clustertype"] = clustertype
- p.p["hypervisor"] = hypervisor
- p.p["podid"] = podid
- p.p["zoneid"] = zoneid
- return p
- }
- // Adds a new cluster
- func (s *ClusterService) AddCluster(p *AddClusterParams) (*AddClusterResponse, error) {
- resp, err := s.cs.newRequest("addCluster", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r AddClusterResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type AddClusterResponse struct {
- Allocationstate string `json:"allocationstate,omitempty"`
- Capacity []struct {
- Capacitytotal int64 `json:"capacitytotal,omitempty"`
- Capacityused int64 `json:"capacityused,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Percentused string `json:"percentused,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Type int `json:"type,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- } `json:"capacity,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuovercommitratio string `json:"cpuovercommitratio,omitempty"`
- Hypervisortype string `json:"hypervisortype,omitempty"`
- Id string `json:"id,omitempty"`
- Managedstate string `json:"managedstate,omitempty"`
- Memoryovercommitratio string `json:"memoryovercommitratio,omitempty"`
- Name string `json:"name,omitempty"`
- Ovm3vip string `json:"ovm3vip,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type DeleteClusterParams struct {
- p map[string]interface{}
- }
- func (p *DeleteClusterParams) 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 *DeleteClusterParams) 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 DeleteClusterParams instance,
- // as then you are sure you have configured all required params
- func (s *ClusterService) NewDeleteClusterParams(id string) *DeleteClusterParams {
- p := &DeleteClusterParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Deletes a cluster.
- func (s *ClusterService) DeleteCluster(p *DeleteClusterParams) (*DeleteClusterResponse, error) {
- resp, err := s.cs.newRequest("deleteCluster", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r DeleteClusterResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type DeleteClusterResponse struct {
- Displaytext string `json:"displaytext,omitempty"`
- Success string `json:"success,omitempty"`
- }
- type UpdateClusterParams struct {
- p map[string]interface{}
- }
- func (p *UpdateClusterParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["allocationstate"]; found {
- u.Set("allocationstate", v.(string))
- }
- if v, found := p.p["clustername"]; found {
- u.Set("clustername", v.(string))
- }
- if v, found := p.p["clustertype"]; found {
- u.Set("clustertype", v.(string))
- }
- if v, found := p.p["hypervisor"]; found {
- u.Set("hypervisor", v.(string))
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- if v, found := p.p["managedstate"]; found {
- u.Set("managedstate", v.(string))
- }
- return u
- }
- func (p *UpdateClusterParams) SetAllocationstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["allocationstate"] = v
- return
- }
- func (p *UpdateClusterParams) SetClustername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clustername"] = v
- return
- }
- func (p *UpdateClusterParams) SetClustertype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clustertype"] = v
- return
- }
- func (p *UpdateClusterParams) SetHypervisor(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hypervisor"] = v
- return
- }
- func (p *UpdateClusterParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *UpdateClusterParams) SetManagedstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["managedstate"] = v
- return
- }
- // You should always use this function to get a new UpdateClusterParams instance,
- // as then you are sure you have configured all required params
- func (s *ClusterService) NewUpdateClusterParams(id string) *UpdateClusterParams {
- p := &UpdateClusterParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Updates an existing cluster
- func (s *ClusterService) UpdateCluster(p *UpdateClusterParams) (*UpdateClusterResponse, error) {
- resp, err := s.cs.newRequest("updateCluster", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r UpdateClusterResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type UpdateClusterResponse struct {
- Allocationstate string `json:"allocationstate,omitempty"`
- Capacity []struct {
- Capacitytotal int64 `json:"capacitytotal,omitempty"`
- Capacityused int64 `json:"capacityused,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Percentused string `json:"percentused,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Type int `json:"type,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- } `json:"capacity,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuovercommitratio string `json:"cpuovercommitratio,omitempty"`
- Hypervisortype string `json:"hypervisortype,omitempty"`
- Id string `json:"id,omitempty"`
- Managedstate string `json:"managedstate,omitempty"`
- Memoryovercommitratio string `json:"memoryovercommitratio,omitempty"`
- Name string `json:"name,omitempty"`
- Ovm3vip string `json:"ovm3vip,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type ListClustersParams struct {
- p map[string]interface{}
- }
- func (p *ListClustersParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["allocationstate"]; found {
- u.Set("allocationstate", v.(string))
- }
- if v, found := p.p["clustertype"]; found {
- u.Set("clustertype", v.(string))
- }
- if v, found := p.p["hypervisor"]; found {
- u.Set("hypervisor", v.(string))
- }
- 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["managedstate"]; found {
- u.Set("managedstate", 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["podid"]; found {
- u.Set("podid", v.(string))
- }
- if v, found := p.p["showcapacities"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("showcapacities", vv)
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *ListClustersParams) SetAllocationstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["allocationstate"] = v
- return
- }
- func (p *ListClustersParams) SetClustertype(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clustertype"] = v
- return
- }
- func (p *ListClustersParams) SetHypervisor(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hypervisor"] = v
- return
- }
- func (p *ListClustersParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *ListClustersParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListClustersParams) SetManagedstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["managedstate"] = v
- return
- }
- func (p *ListClustersParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *ListClustersParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListClustersParams) SetPagesize(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["pagesize"] = v
- return
- }
- func (p *ListClustersParams) SetPodid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["podid"] = v
- return
- }
- func (p *ListClustersParams) SetShowcapacities(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["showcapacities"] = v
- return
- }
- func (p *ListClustersParams) 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 ListClustersParams instance,
- // as then you are sure you have configured all required params
- func (s *ClusterService) NewListClustersParams() *ListClustersParams {
- p := &ListClustersParams{}
- 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 *ClusterService) GetClusterID(name string, opts ...OptionFunc) (string, int, error) {
- p := &ListClustersParams{}
- 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.ListClusters(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.Clusters[0].Id, l.Count, nil
- }
- if l.Count > 1 {
- for _, v := range l.Clusters {
- 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 *ClusterService) GetClusterByName(name string, opts ...OptionFunc) (*Cluster, int, error) {
- id, count, err := s.GetClusterID(name, opts...)
- if err != nil {
- return nil, count, err
- }
- r, count, err := s.GetClusterByID(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 *ClusterService) GetClusterByID(id string, opts ...OptionFunc) (*Cluster, int, error) {
- p := &ListClustersParams{}
- 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.ListClusters(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.Clusters[0], l.Count, nil
- }
- return nil, l.Count, fmt.Errorf("There is more then one result for Cluster UUID: %s!", id)
- }
- // Lists clusters.
- func (s *ClusterService) ListClusters(p *ListClustersParams) (*ListClustersResponse, error) {
- resp, err := s.cs.newRequest("listClusters", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListClustersResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListClustersResponse struct {
- Count int `json:"count"`
- Clusters []*Cluster `json:"cluster"`
- }
- type Cluster struct {
- Allocationstate string `json:"allocationstate,omitempty"`
- Capacity []struct {
- Capacitytotal int64 `json:"capacitytotal,omitempty"`
- Capacityused int64 `json:"capacityused,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Percentused string `json:"percentused,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Type int `json:"type,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- } `json:"capacity,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuovercommitratio string `json:"cpuovercommitratio,omitempty"`
- Hypervisortype string `json:"hypervisortype,omitempty"`
- Id string `json:"id,omitempty"`
- Managedstate string `json:"managedstate,omitempty"`
- Memoryovercommitratio string `json:"memoryovercommitratio,omitempty"`
- Name string `json:"name,omitempty"`
- Ovm3vip string `json:"ovm3vip,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type DedicateClusterParams struct {
- p map[string]interface{}
- }
- func (p *DedicateClusterParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["account"]; found {
- u.Set("account", v.(string))
- }
- if v, found := p.p["clusterid"]; found {
- u.Set("clusterid", v.(string))
- }
- if v, found := p.p["domainid"]; found {
- u.Set("domainid", v.(string))
- }
- return u
- }
- func (p *DedicateClusterParams) SetAccount(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["account"] = v
- return
- }
- func (p *DedicateClusterParams) SetClusterid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clusterid"] = v
- return
- }
- func (p *DedicateClusterParams) SetDomainid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["domainid"] = v
- return
- }
- // You should always use this function to get a new DedicateClusterParams instance,
- // as then you are sure you have configured all required params
- func (s *ClusterService) NewDedicateClusterParams(clusterid string, domainid string) *DedicateClusterParams {
- p := &DedicateClusterParams{}
- p.p = make(map[string]interface{})
- p.p["clusterid"] = clusterid
- p.p["domainid"] = domainid
- return p
- }
- // Dedicate an existing cluster
- func (s *ClusterService) DedicateCluster(p *DedicateClusterParams) (*DedicateClusterResponse, error) {
- resp, err := s.cs.newRequest("dedicateCluster", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r DedicateClusterResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- // If we have a async client, we need to wait for the async result
- if s.cs.async {
- b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
- if err != nil {
- if err == AsyncTimeoutErr {
- return &r, err
- }
- return nil, err
- }
- b, err = getRawValue(b)
- if err != nil {
- return nil, err
- }
- if err := json.Unmarshal(b, &r); err != nil {
- return nil, err
- }
- }
- return &r, nil
- }
- type DedicateClusterResponse struct {
- JobID string `json:"jobid,omitempty"`
- Accountid string `json:"accountid,omitempty"`
- Affinitygroupid string `json:"affinitygroupid,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Domainid string `json:"domainid,omitempty"`
- Id string `json:"id,omitempty"`
- }
- type ReleaseDedicatedClusterParams struct {
- p map[string]interface{}
- }
- func (p *ReleaseDedicatedClusterParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["clusterid"]; found {
- u.Set("clusterid", v.(string))
- }
- return u
- }
- func (p *ReleaseDedicatedClusterParams) SetClusterid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clusterid"] = v
- return
- }
- // You should always use this function to get a new ReleaseDedicatedClusterParams instance,
- // as then you are sure you have configured all required params
- func (s *ClusterService) NewReleaseDedicatedClusterParams(clusterid string) *ReleaseDedicatedClusterParams {
- p := &ReleaseDedicatedClusterParams{}
- p.p = make(map[string]interface{})
- p.p["clusterid"] = clusterid
- return p
- }
- // Release the dedication for cluster
- func (s *ClusterService) ReleaseDedicatedCluster(p *ReleaseDedicatedClusterParams) (*ReleaseDedicatedClusterResponse, error) {
- resp, err := s.cs.newRequest("releaseDedicatedCluster", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ReleaseDedicatedClusterResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- // If we have a async client, we need to wait for the async result
- if s.cs.async {
- b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
- if err != nil {
- if err == AsyncTimeoutErr {
- return &r, err
- }
- return nil, err
- }
- if err := json.Unmarshal(b, &r); err != nil {
- return nil, err
- }
- }
- return &r, nil
- }
- type ReleaseDedicatedClusterResponse struct {
- JobID string `json:"jobid,omitempty"`
- Displaytext string `json:"displaytext,omitempty"`
- Success bool `json:"success,omitempty"`
- }
- type ListDedicatedClustersParams struct {
- p map[string]interface{}
- }
- func (p *ListDedicatedClustersParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["account"]; found {
- u.Set("account", v.(string))
- }
- if v, found := p.p["affinitygroupid"]; found {
- u.Set("affinitygroupid", v.(string))
- }
- if v, found := p.p["clusterid"]; found {
- u.Set("clusterid", v.(string))
- }
- if v, found := p.p["domainid"]; found {
- u.Set("domainid", v.(string))
- }
- if v, found := p.p["keyword"]; found {
- u.Set("keyword", 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)
- }
- return u
- }
- func (p *ListDedicatedClustersParams) SetAccount(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["account"] = v
- return
- }
- func (p *ListDedicatedClustersParams) SetAffinitygroupid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["affinitygroupid"] = v
- return
- }
- func (p *ListDedicatedClustersParams) SetClusterid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clusterid"] = v
- return
- }
- func (p *ListDedicatedClustersParams) SetDomainid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["domainid"] = v
- return
- }
- func (p *ListDedicatedClustersParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListDedicatedClustersParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListDedicatedClustersParams) SetPagesize(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["pagesize"] = v
- return
- }
- // You should always use this function to get a new ListDedicatedClustersParams instance,
- // as then you are sure you have configured all required params
- func (s *ClusterService) NewListDedicatedClustersParams() *ListDedicatedClustersParams {
- p := &ListDedicatedClustersParams{}
- p.p = make(map[string]interface{})
- return p
- }
- // Lists dedicated clusters.
- func (s *ClusterService) ListDedicatedClusters(p *ListDedicatedClustersParams) (*ListDedicatedClustersResponse, error) {
- resp, err := s.cs.newRequest("listDedicatedClusters", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListDedicatedClustersResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListDedicatedClustersResponse struct {
- Count int `json:"count"`
- DedicatedClusters []*DedicatedCluster `json:"dedicatedcluster"`
- }
- type DedicatedCluster struct {
- Accountid string `json:"accountid,omitempty"`
- Affinitygroupid string `json:"affinitygroupid,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Domainid string `json:"domainid,omitempty"`
- Id string `json:"id,omitempty"`
- }
|