12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297 |
- //
- // 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 AddHostParams struct {
- p map[string]interface{}
- }
- func (p *AddHostParams) 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["clusterid"]; found {
- u.Set("clusterid", v.(string))
- }
- if v, found := p.p["clustername"]; found {
- u.Set("clustername", v.(string))
- }
- if v, found := p.p["hosttags"]; found {
- vv := strings.Join(v.([]string), ",")
- u.Set("hosttags", vv)
- }
- if v, found := p.p["hypervisor"]; found {
- u.Set("hypervisor", 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["url"]; found {
- u.Set("url", v.(string))
- }
- if v, found := p.p["username"]; found {
- u.Set("username", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *AddHostParams) SetAllocationstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["allocationstate"] = v
- return
- }
- func (p *AddHostParams) SetClusterid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clusterid"] = v
- return
- }
- func (p *AddHostParams) SetClustername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clustername"] = v
- return
- }
- func (p *AddHostParams) SetHosttags(v []string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hosttags"] = v
- return
- }
- func (p *AddHostParams) SetHypervisor(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hypervisor"] = v
- return
- }
- func (p *AddHostParams) SetPassword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["password"] = v
- return
- }
- func (p *AddHostParams) SetPodid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["podid"] = v
- return
- }
- func (p *AddHostParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- func (p *AddHostParams) SetUsername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["username"] = v
- return
- }
- func (p *AddHostParams) 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 AddHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewAddHostParams(hypervisor string, password string, podid string, url string, username string, zoneid string) *AddHostParams {
- p := &AddHostParams{}
- p.p = make(map[string]interface{})
- p.p["hypervisor"] = hypervisor
- p.p["password"] = password
- p.p["podid"] = podid
- p.p["url"] = url
- p.p["username"] = username
- p.p["zoneid"] = zoneid
- return p
- }
- // Adds a new host.
- func (s *HostService) AddHost(p *AddHostParams) (*AddHostResponse, error) {
- resp, err := s.cs.newRequest("addHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r AddHostResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type AddHostResponse struct {
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpusockets int `json:"cpusockets,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Details map[string]string `json:"details,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Gpugroup []struct {
- Gpugroupname string `json:"gpugroupname,omitempty"`
- Vgpu []struct {
- Maxcapacity int64 `json:"maxcapacity,omitempty"`
- Maxheads int64 `json:"maxheads,omitempty"`
- Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
- Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
- Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
- Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
- Vgputype string `json:"vgputype,omitempty"`
- Videoram int64 `json:"videoram,omitempty"`
- } `json:"vgpu,omitempty"`
- } `json:"gpugroup,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type ReconnectHostParams struct {
- p map[string]interface{}
- }
- func (p *ReconnectHostParams) 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 *ReconnectHostParams) 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 ReconnectHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewReconnectHostParams(id string) *ReconnectHostParams {
- p := &ReconnectHostParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Reconnects a host.
- func (s *HostService) ReconnectHost(p *ReconnectHostParams) (*ReconnectHostResponse, error) {
- resp, err := s.cs.newRequest("reconnectHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ReconnectHostResponse
- 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 ReconnectHostResponse struct {
- JobID string `json:"jobid,omitempty"`
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpusockets int `json:"cpusockets,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Details map[string]string `json:"details,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Gpugroup []struct {
- Gpugroupname string `json:"gpugroupname,omitempty"`
- Vgpu []struct {
- Maxcapacity int64 `json:"maxcapacity,omitempty"`
- Maxheads int64 `json:"maxheads,omitempty"`
- Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
- Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
- Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
- Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
- Vgputype string `json:"vgputype,omitempty"`
- Videoram int64 `json:"videoram,omitempty"`
- } `json:"vgpu,omitempty"`
- } `json:"gpugroup,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type UpdateHostParams struct {
- p map[string]interface{}
- }
- func (p *UpdateHostParams) 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["hosttags"]; found {
- vv := strings.Join(v.([]string), ",")
- u.Set("hosttags", vv)
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- if v, found := p.p["oscategoryid"]; found {
- u.Set("oscategoryid", v.(string))
- }
- if v, found := p.p["url"]; found {
- u.Set("url", v.(string))
- }
- return u
- }
- func (p *UpdateHostParams) SetAllocationstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["allocationstate"] = v
- return
- }
- func (p *UpdateHostParams) SetHosttags(v []string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hosttags"] = v
- return
- }
- func (p *UpdateHostParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *UpdateHostParams) SetOscategoryid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["oscategoryid"] = v
- return
- }
- func (p *UpdateHostParams) 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 UpdateHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewUpdateHostParams(id string) *UpdateHostParams {
- p := &UpdateHostParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Updates a host.
- func (s *HostService) UpdateHost(p *UpdateHostParams) (*UpdateHostResponse, error) {
- resp, err := s.cs.newRequest("updateHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r UpdateHostResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type UpdateHostResponse struct {
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpusockets int `json:"cpusockets,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Details map[string]string `json:"details,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Gpugroup []struct {
- Gpugroupname string `json:"gpugroupname,omitempty"`
- Vgpu []struct {
- Maxcapacity int64 `json:"maxcapacity,omitempty"`
- Maxheads int64 `json:"maxheads,omitempty"`
- Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
- Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
- Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
- Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
- Vgputype string `json:"vgputype,omitempty"`
- Videoram int64 `json:"videoram,omitempty"`
- } `json:"vgpu,omitempty"`
- } `json:"gpugroup,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type DeleteHostParams struct {
- p map[string]interface{}
- }
- func (p *DeleteHostParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["forced"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("forced", vv)
- }
- if v, found := p.p["forcedestroylocalstorage"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("forcedestroylocalstorage", vv)
- }
- if v, found := p.p["id"]; found {
- u.Set("id", v.(string))
- }
- return u
- }
- func (p *DeleteHostParams) SetForced(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["forced"] = v
- return
- }
- func (p *DeleteHostParams) SetForcedestroylocalstorage(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["forcedestroylocalstorage"] = v
- return
- }
- func (p *DeleteHostParams) 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 DeleteHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewDeleteHostParams(id string) *DeleteHostParams {
- p := &DeleteHostParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Deletes a host.
- func (s *HostService) DeleteHost(p *DeleteHostParams) (*DeleteHostResponse, error) {
- resp, err := s.cs.newRequest("deleteHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r DeleteHostResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type DeleteHostResponse struct {
- Displaytext string `json:"displaytext,omitempty"`
- Success string `json:"success,omitempty"`
- }
- type PrepareHostForMaintenanceParams struct {
- p map[string]interface{}
- }
- func (p *PrepareHostForMaintenanceParams) 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 *PrepareHostForMaintenanceParams) 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 PrepareHostForMaintenanceParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewPrepareHostForMaintenanceParams(id string) *PrepareHostForMaintenanceParams {
- p := &PrepareHostForMaintenanceParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Prepares a host for maintenance.
- func (s *HostService) PrepareHostForMaintenance(p *PrepareHostForMaintenanceParams) (*PrepareHostForMaintenanceResponse, error) {
- resp, err := s.cs.newRequest("prepareHostForMaintenance", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r PrepareHostForMaintenanceResponse
- 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 PrepareHostForMaintenanceResponse struct {
- JobID string `json:"jobid,omitempty"`
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpusockets int `json:"cpusockets,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Details map[string]string `json:"details,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Gpugroup []struct {
- Gpugroupname string `json:"gpugroupname,omitempty"`
- Vgpu []struct {
- Maxcapacity int64 `json:"maxcapacity,omitempty"`
- Maxheads int64 `json:"maxheads,omitempty"`
- Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
- Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
- Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
- Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
- Vgputype string `json:"vgputype,omitempty"`
- Videoram int64 `json:"videoram,omitempty"`
- } `json:"vgpu,omitempty"`
- } `json:"gpugroup,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type CancelHostMaintenanceParams struct {
- p map[string]interface{}
- }
- func (p *CancelHostMaintenanceParams) 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 *CancelHostMaintenanceParams) 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 CancelHostMaintenanceParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewCancelHostMaintenanceParams(id string) *CancelHostMaintenanceParams {
- p := &CancelHostMaintenanceParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Cancels host maintenance.
- func (s *HostService) CancelHostMaintenance(p *CancelHostMaintenanceParams) (*CancelHostMaintenanceResponse, error) {
- resp, err := s.cs.newRequest("cancelHostMaintenance", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r CancelHostMaintenanceResponse
- 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 CancelHostMaintenanceResponse struct {
- JobID string `json:"jobid,omitempty"`
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpusockets int `json:"cpusockets,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Details map[string]string `json:"details,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Gpugroup []struct {
- Gpugroupname string `json:"gpugroupname,omitempty"`
- Vgpu []struct {
- Maxcapacity int64 `json:"maxcapacity,omitempty"`
- Maxheads int64 `json:"maxheads,omitempty"`
- Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
- Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
- Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
- Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
- Vgputype string `json:"vgputype,omitempty"`
- Videoram int64 `json:"videoram,omitempty"`
- } `json:"vgpu,omitempty"`
- } `json:"gpugroup,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type ListHostsParams struct {
- p map[string]interface{}
- }
- func (p *ListHostsParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["clusterid"]; found {
- u.Set("clusterid", v.(string))
- }
- if v, found := p.p["details"]; found {
- vv := strings.Join(v.([]string), ",")
- u.Set("details", vv)
- }
- if v, found := p.p["hahost"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("hahost", vv)
- }
- 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["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["resourcestate"]; found {
- u.Set("resourcestate", v.(string))
- }
- if v, found := p.p["state"]; found {
- u.Set("state", v.(string))
- }
- if v, found := p.p["type"]; found {
- u.Set("type", v.(string))
- }
- if v, found := p.p["virtualmachineid"]; found {
- u.Set("virtualmachineid", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *ListHostsParams) SetClusterid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clusterid"] = v
- return
- }
- func (p *ListHostsParams) SetDetails(v []string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["details"] = v
- return
- }
- func (p *ListHostsParams) SetHahost(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hahost"] = v
- return
- }
- func (p *ListHostsParams) SetHypervisor(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hypervisor"] = v
- return
- }
- func (p *ListHostsParams) SetId(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["id"] = v
- return
- }
- func (p *ListHostsParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListHostsParams) SetName(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["name"] = v
- return
- }
- func (p *ListHostsParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListHostsParams) SetPagesize(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["pagesize"] = v
- return
- }
- func (p *ListHostsParams) SetPodid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["podid"] = v
- return
- }
- func (p *ListHostsParams) SetResourcestate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["resourcestate"] = v
- return
- }
- func (p *ListHostsParams) SetState(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["state"] = v
- return
- }
- func (p *ListHostsParams) SetType(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hostType"] = v
- return
- }
- func (p *ListHostsParams) SetVirtualmachineid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["virtualmachineid"] = v
- return
- }
- func (p *ListHostsParams) 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 ListHostsParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewListHostsParams() *ListHostsParams {
- p := &ListHostsParams{}
- 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 *HostService) GetHostID(name string, opts ...OptionFunc) (string, int, error) {
- p := &ListHostsParams{}
- 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.ListHosts(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.Hosts[0].Id, l.Count, nil
- }
- if l.Count > 1 {
- for _, v := range l.Hosts {
- 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 *HostService) GetHostByName(name string, opts ...OptionFunc) (*Host, int, error) {
- id, count, err := s.GetHostID(name, opts...)
- if err != nil {
- return nil, count, err
- }
- r, count, err := s.GetHostByID(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 *HostService) GetHostByID(id string, opts ...OptionFunc) (*Host, int, error) {
- p := &ListHostsParams{}
- 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.ListHosts(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.Hosts[0], l.Count, nil
- }
- return nil, l.Count, fmt.Errorf("There is more then one result for Host UUID: %s!", id)
- }
- // Lists hosts.
- func (s *HostService) ListHosts(p *ListHostsParams) (*ListHostsResponse, error) {
- resp, err := s.cs.newRequest("listHosts", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListHostsResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListHostsResponse struct {
- Count int `json:"count"`
- Hosts []*Host `json:"host"`
- }
- type Host struct {
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpusockets int `json:"cpusockets,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Details map[string]string `json:"details,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Gpugroup []struct {
- Gpugroupname string `json:"gpugroupname,omitempty"`
- Vgpu []struct {
- Maxcapacity int64 `json:"maxcapacity,omitempty"`
- Maxheads int64 `json:"maxheads,omitempty"`
- Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
- Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
- Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
- Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
- Vgputype string `json:"vgputype,omitempty"`
- Videoram int64 `json:"videoram,omitempty"`
- } `json:"vgpu,omitempty"`
- } `json:"gpugroup,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type ListHostTagsParams struct {
- p map[string]interface{}
- }
- func (p *ListHostTagsParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- 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 *ListHostTagsParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListHostTagsParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListHostTagsParams) 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 ListHostTagsParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewListHostTagsParams() *ListHostTagsParams {
- p := &ListHostTagsParams{}
- 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 *HostService) GetHostTagID(keyword string, opts ...OptionFunc) (string, int, error) {
- p := &ListHostTagsParams{}
- p.p = make(map[string]interface{})
- p.p["keyword"] = keyword
- for _, fn := range opts {
- if err := fn(s.cs, p); err != nil {
- return "", -1, err
- }
- }
- l, err := s.ListHostTags(p)
- if err != nil {
- return "", -1, err
- }
- if l.Count == 0 {
- return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l)
- }
- if l.Count == 1 {
- return l.HostTags[0].Id, l.Count, nil
- }
- if l.Count > 1 {
- for _, v := range l.HostTags {
- if v.Name == keyword {
- return v.Id, l.Count, nil
- }
- }
- }
- return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l)
- }
- // Lists host tags
- func (s *HostService) ListHostTags(p *ListHostTagsParams) (*ListHostTagsResponse, error) {
- resp, err := s.cs.newRequest("listHostTags", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListHostTagsResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListHostTagsResponse struct {
- Count int `json:"count"`
- HostTags []*HostTag `json:"hosttag"`
- }
- type HostTag struct {
- Hostid int64 `json:"hostid,omitempty"`
- Id string `json:"id,omitempty"`
- Name string `json:"name,omitempty"`
- }
- type FindHostsForMigrationParams struct {
- p map[string]interface{}
- }
- func (p *FindHostsForMigrationParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- 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)
- }
- if v, found := p.p["virtualmachineid"]; found {
- u.Set("virtualmachineid", v.(string))
- }
- return u
- }
- func (p *FindHostsForMigrationParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *FindHostsForMigrationParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *FindHostsForMigrationParams) SetPagesize(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["pagesize"] = v
- return
- }
- func (p *FindHostsForMigrationParams) 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 FindHostsForMigrationParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewFindHostsForMigrationParams(virtualmachineid string) *FindHostsForMigrationParams {
- p := &FindHostsForMigrationParams{}
- p.p = make(map[string]interface{})
- p.p["virtualmachineid"] = virtualmachineid
- return p
- }
- // Find hosts suitable for migrating a virtual machine.
- func (s *HostService) FindHostsForMigration(p *FindHostsForMigrationParams) (*FindHostsForMigrationResponse, error) {
- resp, err := s.cs.newRequest("findHostsForMigration", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r FindHostsForMigrationResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type FindHostsForMigrationResponse struct {
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- RequiresStorageMotion bool `json:"requiresStorageMotion,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type AddSecondaryStorageParams struct {
- p map[string]interface{}
- }
- func (p *AddSecondaryStorageParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- 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 *AddSecondaryStorageParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- func (p *AddSecondaryStorageParams) 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 AddSecondaryStorageParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewAddSecondaryStorageParams(url string) *AddSecondaryStorageParams {
- p := &AddSecondaryStorageParams{}
- p.p = make(map[string]interface{})
- p.p["url"] = url
- return p
- }
- // Adds secondary storage.
- func (s *HostService) AddSecondaryStorage(p *AddSecondaryStorageParams) (*AddSecondaryStorageResponse, error) {
- resp, err := s.cs.newRequest("addSecondaryStorage", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r AddSecondaryStorageResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type AddSecondaryStorageResponse 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 UpdateHostPasswordParams struct {
- p map[string]interface{}
- }
- func (p *UpdateHostPasswordParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["clusterid"]; found {
- u.Set("clusterid", v.(string))
- }
- if v, found := p.p["hostid"]; found {
- u.Set("hostid", v.(string))
- }
- if v, found := p.p["password"]; found {
- u.Set("password", v.(string))
- }
- if v, found := p.p["update_passwd_on_host"]; found {
- vv := strconv.FormatBool(v.(bool))
- u.Set("update_passwd_on_host", vv)
- }
- if v, found := p.p["username"]; found {
- u.Set("username", v.(string))
- }
- return u
- }
- func (p *UpdateHostPasswordParams) SetClusterid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clusterid"] = v
- return
- }
- func (p *UpdateHostPasswordParams) SetHostid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hostid"] = v
- return
- }
- func (p *UpdateHostPasswordParams) SetPassword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["password"] = v
- return
- }
- func (p *UpdateHostPasswordParams) SetUpdate_passwd_on_host(v bool) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["update_passwd_on_host"] = v
- return
- }
- func (p *UpdateHostPasswordParams) SetUsername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["username"] = v
- return
- }
- // You should always use this function to get a new UpdateHostPasswordParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewUpdateHostPasswordParams(password string, username string) *UpdateHostPasswordParams {
- p := &UpdateHostPasswordParams{}
- p.p = make(map[string]interface{})
- p.p["password"] = password
- p.p["username"] = username
- return p
- }
- // Update password of a host/pool on management server.
- func (s *HostService) UpdateHostPassword(p *UpdateHostPasswordParams) (*UpdateHostPasswordResponse, error) {
- resp, err := s.cs.newRequest("updateHostPassword", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r UpdateHostPasswordResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type UpdateHostPasswordResponse struct {
- Displaytext string `json:"displaytext,omitempty"`
- Success string `json:"success,omitempty"`
- }
- type ReleaseHostReservationParams struct {
- p map[string]interface{}
- }
- func (p *ReleaseHostReservationParams) 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 *ReleaseHostReservationParams) 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 ReleaseHostReservationParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewReleaseHostReservationParams(id string) *ReleaseHostReservationParams {
- p := &ReleaseHostReservationParams{}
- p.p = make(map[string]interface{})
- p.p["id"] = id
- return p
- }
- // Releases host reservation.
- func (s *HostService) ReleaseHostReservation(p *ReleaseHostReservationParams) (*ReleaseHostReservationResponse, error) {
- resp, err := s.cs.newRequest("releaseHostReservation", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ReleaseHostReservationResponse
- 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 ReleaseHostReservationResponse struct {
- JobID string `json:"jobid,omitempty"`
- Displaytext string `json:"displaytext,omitempty"`
- Success bool `json:"success,omitempty"`
- }
- type AddBaremetalHostParams struct {
- p map[string]interface{}
- }
- func (p *AddBaremetalHostParams) 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["clusterid"]; found {
- u.Set("clusterid", v.(string))
- }
- if v, found := p.p["clustername"]; found {
- u.Set("clustername", v.(string))
- }
- if v, found := p.p["hosttags"]; found {
- vv := strings.Join(v.([]string), ",")
- u.Set("hosttags", vv)
- }
- if v, found := p.p["hypervisor"]; found {
- u.Set("hypervisor", v.(string))
- }
- if v, found := p.p["ipaddress"]; found {
- u.Set("ipaddress", 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["url"]; found {
- u.Set("url", v.(string))
- }
- if v, found := p.p["username"]; found {
- u.Set("username", v.(string))
- }
- if v, found := p.p["zoneid"]; found {
- u.Set("zoneid", v.(string))
- }
- return u
- }
- func (p *AddBaremetalHostParams) SetAllocationstate(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["allocationstate"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetClusterid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clusterid"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetClustername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["clustername"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetHosttags(v []string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hosttags"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetHypervisor(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hypervisor"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetIpaddress(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["ipaddress"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetPassword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["password"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetPodid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["podid"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- func (p *AddBaremetalHostParams) SetUsername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["username"] = v
- return
- }
- func (p *AddBaremetalHostParams) 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 AddBaremetalHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewAddBaremetalHostParams(hypervisor string, password string, podid string, url string, username string, zoneid string) *AddBaremetalHostParams {
- p := &AddBaremetalHostParams{}
- p.p = make(map[string]interface{})
- p.p["hypervisor"] = hypervisor
- p.p["password"] = password
- p.p["podid"] = podid
- p.p["url"] = url
- p.p["username"] = username
- p.p["zoneid"] = zoneid
- return p
- }
- // add a baremetal host
- func (s *HostService) AddBaremetalHost(p *AddBaremetalHostParams) (*AddBaremetalHostResponse, error) {
- resp, err := s.cs.newRequest("addBaremetalHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r AddBaremetalHostResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type AddBaremetalHostResponse struct {
- Averageload int64 `json:"averageload,omitempty"`
- Capabilities string `json:"capabilities,omitempty"`
- Clusterid string `json:"clusterid,omitempty"`
- Clustername string `json:"clustername,omitempty"`
- Clustertype string `json:"clustertype,omitempty"`
- Cpuallocated string `json:"cpuallocated,omitempty"`
- Cpunumber int `json:"cpunumber,omitempty"`
- Cpusockets int `json:"cpusockets,omitempty"`
- Cpuspeed int64 `json:"cpuspeed,omitempty"`
- Cpuused string `json:"cpuused,omitempty"`
- Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
- Created string `json:"created,omitempty"`
- Details map[string]string `json:"details,omitempty"`
- Disconnected string `json:"disconnected,omitempty"`
- Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
- Disksizetotal int64 `json:"disksizetotal,omitempty"`
- Events string `json:"events,omitempty"`
- Gpugroup []struct {
- Gpugroupname string `json:"gpugroupname,omitempty"`
- Vgpu []struct {
- Maxcapacity int64 `json:"maxcapacity,omitempty"`
- Maxheads int64 `json:"maxheads,omitempty"`
- Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
- Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
- Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
- Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
- Vgputype string `json:"vgputype,omitempty"`
- Videoram int64 `json:"videoram,omitempty"`
- } `json:"vgpu,omitempty"`
- } `json:"gpugroup,omitempty"`
- Hahost bool `json:"hahost,omitempty"`
- Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
- Hosttags string `json:"hosttags,omitempty"`
- Hypervisor string `json:"hypervisor,omitempty"`
- Hypervisorversion string `json:"hypervisorversion,omitempty"`
- Id string `json:"id,omitempty"`
- Ipaddress string `json:"ipaddress,omitempty"`
- Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
- Lastpinged string `json:"lastpinged,omitempty"`
- Managementserverid int64 `json:"managementserverid,omitempty"`
- Memoryallocated int64 `json:"memoryallocated,omitempty"`
- Memorytotal int64 `json:"memorytotal,omitempty"`
- Memoryused int64 `json:"memoryused,omitempty"`
- Name string `json:"name,omitempty"`
- Networkkbsread int64 `json:"networkkbsread,omitempty"`
- Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
- Oscategoryid string `json:"oscategoryid,omitempty"`
- Oscategoryname string `json:"oscategoryname,omitempty"`
- Podid string `json:"podid,omitempty"`
- Podname string `json:"podname,omitempty"`
- Removed string `json:"removed,omitempty"`
- Resourcestate string `json:"resourcestate,omitempty"`
- State string `json:"state,omitempty"`
- Suitableformigration bool `json:"suitableformigration,omitempty"`
- Type string `json:"type,omitempty"`
- Version string `json:"version,omitempty"`
- Zoneid string `json:"zoneid,omitempty"`
- Zonename string `json:"zonename,omitempty"`
- }
- type DedicateHostParams struct {
- p map[string]interface{}
- }
- func (p *DedicateHostParams) 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["domainid"]; found {
- u.Set("domainid", v.(string))
- }
- if v, found := p.p["hostid"]; found {
- u.Set("hostid", v.(string))
- }
- return u
- }
- func (p *DedicateHostParams) SetAccount(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["account"] = v
- return
- }
- func (p *DedicateHostParams) SetDomainid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["domainid"] = v
- return
- }
- func (p *DedicateHostParams) SetHostid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hostid"] = v
- return
- }
- // You should always use this function to get a new DedicateHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewDedicateHostParams(domainid string, hostid string) *DedicateHostParams {
- p := &DedicateHostParams{}
- p.p = make(map[string]interface{})
- p.p["domainid"] = domainid
- p.p["hostid"] = hostid
- return p
- }
- // Dedicates a host.
- func (s *HostService) DedicateHost(p *DedicateHostParams) (*DedicateHostResponse, error) {
- resp, err := s.cs.newRequest("dedicateHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r DedicateHostResponse
- 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 DedicateHostResponse struct {
- JobID string `json:"jobid,omitempty"`
- Accountid string `json:"accountid,omitempty"`
- Affinitygroupid string `json:"affinitygroupid,omitempty"`
- Domainid string `json:"domainid,omitempty"`
- Hostid string `json:"hostid,omitempty"`
- Hostname string `json:"hostname,omitempty"`
- Id string `json:"id,omitempty"`
- }
- type ReleaseDedicatedHostParams struct {
- p map[string]interface{}
- }
- func (p *ReleaseDedicatedHostParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["hostid"]; found {
- u.Set("hostid", v.(string))
- }
- return u
- }
- func (p *ReleaseDedicatedHostParams) SetHostid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hostid"] = v
- return
- }
- // You should always use this function to get a new ReleaseDedicatedHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewReleaseDedicatedHostParams(hostid string) *ReleaseDedicatedHostParams {
- p := &ReleaseDedicatedHostParams{}
- p.p = make(map[string]interface{})
- p.p["hostid"] = hostid
- return p
- }
- // Release the dedication for host
- func (s *HostService) ReleaseDedicatedHost(p *ReleaseDedicatedHostParams) (*ReleaseDedicatedHostResponse, error) {
- resp, err := s.cs.newRequest("releaseDedicatedHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ReleaseDedicatedHostResponse
- 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 ReleaseDedicatedHostResponse struct {
- JobID string `json:"jobid,omitempty"`
- Displaytext string `json:"displaytext,omitempty"`
- Success bool `json:"success,omitempty"`
- }
- type ListDedicatedHostsParams struct {
- p map[string]interface{}
- }
- func (p *ListDedicatedHostsParams) 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["domainid"]; found {
- u.Set("domainid", v.(string))
- }
- if v, found := p.p["hostid"]; found {
- u.Set("hostid", 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 *ListDedicatedHostsParams) SetAccount(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["account"] = v
- return
- }
- func (p *ListDedicatedHostsParams) SetAffinitygroupid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["affinitygroupid"] = v
- return
- }
- func (p *ListDedicatedHostsParams) SetDomainid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["domainid"] = v
- return
- }
- func (p *ListDedicatedHostsParams) SetHostid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["hostid"] = v
- return
- }
- func (p *ListDedicatedHostsParams) SetKeyword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["keyword"] = v
- return
- }
- func (p *ListDedicatedHostsParams) SetPage(v int) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["page"] = v
- return
- }
- func (p *ListDedicatedHostsParams) 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 ListDedicatedHostsParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewListDedicatedHostsParams() *ListDedicatedHostsParams {
- p := &ListDedicatedHostsParams{}
- p.p = make(map[string]interface{})
- return p
- }
- // Lists dedicated hosts.
- func (s *HostService) ListDedicatedHosts(p *ListDedicatedHostsParams) (*ListDedicatedHostsResponse, error) {
- resp, err := s.cs.newRequest("listDedicatedHosts", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r ListDedicatedHostsResponse
- if err := json.Unmarshal(resp, &r); err != nil {
- return nil, err
- }
- return &r, nil
- }
- type ListDedicatedHostsResponse struct {
- Count int `json:"count"`
- DedicatedHosts []*DedicatedHost `json:"dedicatedhost"`
- }
- type DedicatedHost struct {
- Accountid string `json:"accountid,omitempty"`
- Affinitygroupid string `json:"affinitygroupid,omitempty"`
- Domainid string `json:"domainid,omitempty"`
- Hostid string `json:"hostid,omitempty"`
- Hostname string `json:"hostname,omitempty"`
- Id string `json:"id,omitempty"`
- }
- type AddGloboDnsHostParams struct {
- p map[string]interface{}
- }
- func (p *AddGloboDnsHostParams) toURLValues() url.Values {
- u := url.Values{}
- if p.p == nil {
- return u
- }
- if v, found := p.p["password"]; found {
- u.Set("password", v.(string))
- }
- if v, found := p.p["physicalnetworkid"]; found {
- u.Set("physicalnetworkid", 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))
- }
- return u
- }
- func (p *AddGloboDnsHostParams) SetPassword(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["password"] = v
- return
- }
- func (p *AddGloboDnsHostParams) SetPhysicalnetworkid(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["physicalnetworkid"] = v
- return
- }
- func (p *AddGloboDnsHostParams) SetUrl(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["url"] = v
- return
- }
- func (p *AddGloboDnsHostParams) SetUsername(v string) {
- if p.p == nil {
- p.p = make(map[string]interface{})
- }
- p.p["username"] = v
- return
- }
- // You should always use this function to get a new AddGloboDnsHostParams instance,
- // as then you are sure you have configured all required params
- func (s *HostService) NewAddGloboDnsHostParams(password string, physicalnetworkid string, url string, username string) *AddGloboDnsHostParams {
- p := &AddGloboDnsHostParams{}
- p.p = make(map[string]interface{})
- p.p["password"] = password
- p.p["physicalnetworkid"] = physicalnetworkid
- p.p["url"] = url
- p.p["username"] = username
- return p
- }
- // Adds the GloboDNS external host
- func (s *HostService) AddGloboDnsHost(p *AddGloboDnsHostParams) (*AddGloboDnsHostResponse, error) {
- resp, err := s.cs.newRequest("addGloboDnsHost", p.toURLValues())
- if err != nil {
- return nil, err
- }
- var r AddGloboDnsHostResponse
- 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 AddGloboDnsHostResponse struct {
- JobID string `json:"jobid,omitempty"`
- Displaytext string `json:"displaytext,omitempty"`
- Success bool `json:"success,omitempty"`
- }
|