HostService.go 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297
  1. //
  2. // Copyright 2016, Sander van Harmelen
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. package cloudstack
  17. import (
  18. "encoding/json"
  19. "fmt"
  20. "net/url"
  21. "strconv"
  22. "strings"
  23. )
  24. type AddHostParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *AddHostParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["allocationstate"]; found {
  33. u.Set("allocationstate", v.(string))
  34. }
  35. if v, found := p.p["clusterid"]; found {
  36. u.Set("clusterid", v.(string))
  37. }
  38. if v, found := p.p["clustername"]; found {
  39. u.Set("clustername", v.(string))
  40. }
  41. if v, found := p.p["hosttags"]; found {
  42. vv := strings.Join(v.([]string), ",")
  43. u.Set("hosttags", vv)
  44. }
  45. if v, found := p.p["hypervisor"]; found {
  46. u.Set("hypervisor", v.(string))
  47. }
  48. if v, found := p.p["password"]; found {
  49. u.Set("password", v.(string))
  50. }
  51. if v, found := p.p["podid"]; found {
  52. u.Set("podid", v.(string))
  53. }
  54. if v, found := p.p["url"]; found {
  55. u.Set("url", v.(string))
  56. }
  57. if v, found := p.p["username"]; found {
  58. u.Set("username", v.(string))
  59. }
  60. if v, found := p.p["zoneid"]; found {
  61. u.Set("zoneid", v.(string))
  62. }
  63. return u
  64. }
  65. func (p *AddHostParams) SetAllocationstate(v string) {
  66. if p.p == nil {
  67. p.p = make(map[string]interface{})
  68. }
  69. p.p["allocationstate"] = v
  70. return
  71. }
  72. func (p *AddHostParams) SetClusterid(v string) {
  73. if p.p == nil {
  74. p.p = make(map[string]interface{})
  75. }
  76. p.p["clusterid"] = v
  77. return
  78. }
  79. func (p *AddHostParams) SetClustername(v string) {
  80. if p.p == nil {
  81. p.p = make(map[string]interface{})
  82. }
  83. p.p["clustername"] = v
  84. return
  85. }
  86. func (p *AddHostParams) SetHosttags(v []string) {
  87. if p.p == nil {
  88. p.p = make(map[string]interface{})
  89. }
  90. p.p["hosttags"] = v
  91. return
  92. }
  93. func (p *AddHostParams) SetHypervisor(v string) {
  94. if p.p == nil {
  95. p.p = make(map[string]interface{})
  96. }
  97. p.p["hypervisor"] = v
  98. return
  99. }
  100. func (p *AddHostParams) SetPassword(v string) {
  101. if p.p == nil {
  102. p.p = make(map[string]interface{})
  103. }
  104. p.p["password"] = v
  105. return
  106. }
  107. func (p *AddHostParams) SetPodid(v string) {
  108. if p.p == nil {
  109. p.p = make(map[string]interface{})
  110. }
  111. p.p["podid"] = v
  112. return
  113. }
  114. func (p *AddHostParams) SetUrl(v string) {
  115. if p.p == nil {
  116. p.p = make(map[string]interface{})
  117. }
  118. p.p["url"] = v
  119. return
  120. }
  121. func (p *AddHostParams) SetUsername(v string) {
  122. if p.p == nil {
  123. p.p = make(map[string]interface{})
  124. }
  125. p.p["username"] = v
  126. return
  127. }
  128. func (p *AddHostParams) SetZoneid(v string) {
  129. if p.p == nil {
  130. p.p = make(map[string]interface{})
  131. }
  132. p.p["zoneid"] = v
  133. return
  134. }
  135. // You should always use this function to get a new AddHostParams instance,
  136. // as then you are sure you have configured all required params
  137. func (s *HostService) NewAddHostParams(hypervisor string, password string, podid string, url string, username string, zoneid string) *AddHostParams {
  138. p := &AddHostParams{}
  139. p.p = make(map[string]interface{})
  140. p.p["hypervisor"] = hypervisor
  141. p.p["password"] = password
  142. p.p["podid"] = podid
  143. p.p["url"] = url
  144. p.p["username"] = username
  145. p.p["zoneid"] = zoneid
  146. return p
  147. }
  148. // Adds a new host.
  149. func (s *HostService) AddHost(p *AddHostParams) (*AddHostResponse, error) {
  150. resp, err := s.cs.newRequest("addHost", p.toURLValues())
  151. if err != nil {
  152. return nil, err
  153. }
  154. var r AddHostResponse
  155. if err := json.Unmarshal(resp, &r); err != nil {
  156. return nil, err
  157. }
  158. return &r, nil
  159. }
  160. type AddHostResponse struct {
  161. Averageload int64 `json:"averageload,omitempty"`
  162. Capabilities string `json:"capabilities,omitempty"`
  163. Clusterid string `json:"clusterid,omitempty"`
  164. Clustername string `json:"clustername,omitempty"`
  165. Clustertype string `json:"clustertype,omitempty"`
  166. Cpuallocated string `json:"cpuallocated,omitempty"`
  167. Cpunumber int `json:"cpunumber,omitempty"`
  168. Cpusockets int `json:"cpusockets,omitempty"`
  169. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  170. Cpuused string `json:"cpuused,omitempty"`
  171. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  172. Created string `json:"created,omitempty"`
  173. Details map[string]string `json:"details,omitempty"`
  174. Disconnected string `json:"disconnected,omitempty"`
  175. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  176. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  177. Events string `json:"events,omitempty"`
  178. Gpugroup []struct {
  179. Gpugroupname string `json:"gpugroupname,omitempty"`
  180. Vgpu []struct {
  181. Maxcapacity int64 `json:"maxcapacity,omitempty"`
  182. Maxheads int64 `json:"maxheads,omitempty"`
  183. Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
  184. Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
  185. Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
  186. Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
  187. Vgputype string `json:"vgputype,omitempty"`
  188. Videoram int64 `json:"videoram,omitempty"`
  189. } `json:"vgpu,omitempty"`
  190. } `json:"gpugroup,omitempty"`
  191. Hahost bool `json:"hahost,omitempty"`
  192. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  193. Hosttags string `json:"hosttags,omitempty"`
  194. Hypervisor string `json:"hypervisor,omitempty"`
  195. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  196. Id string `json:"id,omitempty"`
  197. Ipaddress string `json:"ipaddress,omitempty"`
  198. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  199. Lastpinged string `json:"lastpinged,omitempty"`
  200. Managementserverid int64 `json:"managementserverid,omitempty"`
  201. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  202. Memorytotal int64 `json:"memorytotal,omitempty"`
  203. Memoryused int64 `json:"memoryused,omitempty"`
  204. Name string `json:"name,omitempty"`
  205. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  206. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  207. Oscategoryid string `json:"oscategoryid,omitempty"`
  208. Oscategoryname string `json:"oscategoryname,omitempty"`
  209. Podid string `json:"podid,omitempty"`
  210. Podname string `json:"podname,omitempty"`
  211. Removed string `json:"removed,omitempty"`
  212. Resourcestate string `json:"resourcestate,omitempty"`
  213. State string `json:"state,omitempty"`
  214. Suitableformigration bool `json:"suitableformigration,omitempty"`
  215. Type string `json:"type,omitempty"`
  216. Version string `json:"version,omitempty"`
  217. Zoneid string `json:"zoneid,omitempty"`
  218. Zonename string `json:"zonename,omitempty"`
  219. }
  220. type ReconnectHostParams struct {
  221. p map[string]interface{}
  222. }
  223. func (p *ReconnectHostParams) toURLValues() url.Values {
  224. u := url.Values{}
  225. if p.p == nil {
  226. return u
  227. }
  228. if v, found := p.p["id"]; found {
  229. u.Set("id", v.(string))
  230. }
  231. return u
  232. }
  233. func (p *ReconnectHostParams) SetId(v string) {
  234. if p.p == nil {
  235. p.p = make(map[string]interface{})
  236. }
  237. p.p["id"] = v
  238. return
  239. }
  240. // You should always use this function to get a new ReconnectHostParams instance,
  241. // as then you are sure you have configured all required params
  242. func (s *HostService) NewReconnectHostParams(id string) *ReconnectHostParams {
  243. p := &ReconnectHostParams{}
  244. p.p = make(map[string]interface{})
  245. p.p["id"] = id
  246. return p
  247. }
  248. // Reconnects a host.
  249. func (s *HostService) ReconnectHost(p *ReconnectHostParams) (*ReconnectHostResponse, error) {
  250. resp, err := s.cs.newRequest("reconnectHost", p.toURLValues())
  251. if err != nil {
  252. return nil, err
  253. }
  254. var r ReconnectHostResponse
  255. if err := json.Unmarshal(resp, &r); err != nil {
  256. return nil, err
  257. }
  258. // If we have a async client, we need to wait for the async result
  259. if s.cs.async {
  260. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  261. if err != nil {
  262. if err == AsyncTimeoutErr {
  263. return &r, err
  264. }
  265. return nil, err
  266. }
  267. b, err = getRawValue(b)
  268. if err != nil {
  269. return nil, err
  270. }
  271. if err := json.Unmarshal(b, &r); err != nil {
  272. return nil, err
  273. }
  274. }
  275. return &r, nil
  276. }
  277. type ReconnectHostResponse struct {
  278. JobID string `json:"jobid,omitempty"`
  279. Averageload int64 `json:"averageload,omitempty"`
  280. Capabilities string `json:"capabilities,omitempty"`
  281. Clusterid string `json:"clusterid,omitempty"`
  282. Clustername string `json:"clustername,omitempty"`
  283. Clustertype string `json:"clustertype,omitempty"`
  284. Cpuallocated string `json:"cpuallocated,omitempty"`
  285. Cpunumber int `json:"cpunumber,omitempty"`
  286. Cpusockets int `json:"cpusockets,omitempty"`
  287. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  288. Cpuused string `json:"cpuused,omitempty"`
  289. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  290. Created string `json:"created,omitempty"`
  291. Details map[string]string `json:"details,omitempty"`
  292. Disconnected string `json:"disconnected,omitempty"`
  293. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  294. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  295. Events string `json:"events,omitempty"`
  296. Gpugroup []struct {
  297. Gpugroupname string `json:"gpugroupname,omitempty"`
  298. Vgpu []struct {
  299. Maxcapacity int64 `json:"maxcapacity,omitempty"`
  300. Maxheads int64 `json:"maxheads,omitempty"`
  301. Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
  302. Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
  303. Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
  304. Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
  305. Vgputype string `json:"vgputype,omitempty"`
  306. Videoram int64 `json:"videoram,omitempty"`
  307. } `json:"vgpu,omitempty"`
  308. } `json:"gpugroup,omitempty"`
  309. Hahost bool `json:"hahost,omitempty"`
  310. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  311. Hosttags string `json:"hosttags,omitempty"`
  312. Hypervisor string `json:"hypervisor,omitempty"`
  313. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  314. Id string `json:"id,omitempty"`
  315. Ipaddress string `json:"ipaddress,omitempty"`
  316. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  317. Lastpinged string `json:"lastpinged,omitempty"`
  318. Managementserverid int64 `json:"managementserverid,omitempty"`
  319. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  320. Memorytotal int64 `json:"memorytotal,omitempty"`
  321. Memoryused int64 `json:"memoryused,omitempty"`
  322. Name string `json:"name,omitempty"`
  323. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  324. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  325. Oscategoryid string `json:"oscategoryid,omitempty"`
  326. Oscategoryname string `json:"oscategoryname,omitempty"`
  327. Podid string `json:"podid,omitempty"`
  328. Podname string `json:"podname,omitempty"`
  329. Removed string `json:"removed,omitempty"`
  330. Resourcestate string `json:"resourcestate,omitempty"`
  331. State string `json:"state,omitempty"`
  332. Suitableformigration bool `json:"suitableformigration,omitempty"`
  333. Type string `json:"type,omitempty"`
  334. Version string `json:"version,omitempty"`
  335. Zoneid string `json:"zoneid,omitempty"`
  336. Zonename string `json:"zonename,omitempty"`
  337. }
  338. type UpdateHostParams struct {
  339. p map[string]interface{}
  340. }
  341. func (p *UpdateHostParams) toURLValues() url.Values {
  342. u := url.Values{}
  343. if p.p == nil {
  344. return u
  345. }
  346. if v, found := p.p["allocationstate"]; found {
  347. u.Set("allocationstate", v.(string))
  348. }
  349. if v, found := p.p["hosttags"]; found {
  350. vv := strings.Join(v.([]string), ",")
  351. u.Set("hosttags", vv)
  352. }
  353. if v, found := p.p["id"]; found {
  354. u.Set("id", v.(string))
  355. }
  356. if v, found := p.p["oscategoryid"]; found {
  357. u.Set("oscategoryid", v.(string))
  358. }
  359. if v, found := p.p["url"]; found {
  360. u.Set("url", v.(string))
  361. }
  362. return u
  363. }
  364. func (p *UpdateHostParams) SetAllocationstate(v string) {
  365. if p.p == nil {
  366. p.p = make(map[string]interface{})
  367. }
  368. p.p["allocationstate"] = v
  369. return
  370. }
  371. func (p *UpdateHostParams) SetHosttags(v []string) {
  372. if p.p == nil {
  373. p.p = make(map[string]interface{})
  374. }
  375. p.p["hosttags"] = v
  376. return
  377. }
  378. func (p *UpdateHostParams) SetId(v string) {
  379. if p.p == nil {
  380. p.p = make(map[string]interface{})
  381. }
  382. p.p["id"] = v
  383. return
  384. }
  385. func (p *UpdateHostParams) SetOscategoryid(v string) {
  386. if p.p == nil {
  387. p.p = make(map[string]interface{})
  388. }
  389. p.p["oscategoryid"] = v
  390. return
  391. }
  392. func (p *UpdateHostParams) SetUrl(v string) {
  393. if p.p == nil {
  394. p.p = make(map[string]interface{})
  395. }
  396. p.p["url"] = v
  397. return
  398. }
  399. // You should always use this function to get a new UpdateHostParams instance,
  400. // as then you are sure you have configured all required params
  401. func (s *HostService) NewUpdateHostParams(id string) *UpdateHostParams {
  402. p := &UpdateHostParams{}
  403. p.p = make(map[string]interface{})
  404. p.p["id"] = id
  405. return p
  406. }
  407. // Updates a host.
  408. func (s *HostService) UpdateHost(p *UpdateHostParams) (*UpdateHostResponse, error) {
  409. resp, err := s.cs.newRequest("updateHost", p.toURLValues())
  410. if err != nil {
  411. return nil, err
  412. }
  413. var r UpdateHostResponse
  414. if err := json.Unmarshal(resp, &r); err != nil {
  415. return nil, err
  416. }
  417. return &r, nil
  418. }
  419. type UpdateHostResponse struct {
  420. Averageload int64 `json:"averageload,omitempty"`
  421. Capabilities string `json:"capabilities,omitempty"`
  422. Clusterid string `json:"clusterid,omitempty"`
  423. Clustername string `json:"clustername,omitempty"`
  424. Clustertype string `json:"clustertype,omitempty"`
  425. Cpuallocated string `json:"cpuallocated,omitempty"`
  426. Cpunumber int `json:"cpunumber,omitempty"`
  427. Cpusockets int `json:"cpusockets,omitempty"`
  428. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  429. Cpuused string `json:"cpuused,omitempty"`
  430. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  431. Created string `json:"created,omitempty"`
  432. Details map[string]string `json:"details,omitempty"`
  433. Disconnected string `json:"disconnected,omitempty"`
  434. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  435. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  436. Events string `json:"events,omitempty"`
  437. Gpugroup []struct {
  438. Gpugroupname string `json:"gpugroupname,omitempty"`
  439. Vgpu []struct {
  440. Maxcapacity int64 `json:"maxcapacity,omitempty"`
  441. Maxheads int64 `json:"maxheads,omitempty"`
  442. Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
  443. Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
  444. Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
  445. Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
  446. Vgputype string `json:"vgputype,omitempty"`
  447. Videoram int64 `json:"videoram,omitempty"`
  448. } `json:"vgpu,omitempty"`
  449. } `json:"gpugroup,omitempty"`
  450. Hahost bool `json:"hahost,omitempty"`
  451. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  452. Hosttags string `json:"hosttags,omitempty"`
  453. Hypervisor string `json:"hypervisor,omitempty"`
  454. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  455. Id string `json:"id,omitempty"`
  456. Ipaddress string `json:"ipaddress,omitempty"`
  457. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  458. Lastpinged string `json:"lastpinged,omitempty"`
  459. Managementserverid int64 `json:"managementserverid,omitempty"`
  460. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  461. Memorytotal int64 `json:"memorytotal,omitempty"`
  462. Memoryused int64 `json:"memoryused,omitempty"`
  463. Name string `json:"name,omitempty"`
  464. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  465. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  466. Oscategoryid string `json:"oscategoryid,omitempty"`
  467. Oscategoryname string `json:"oscategoryname,omitempty"`
  468. Podid string `json:"podid,omitempty"`
  469. Podname string `json:"podname,omitempty"`
  470. Removed string `json:"removed,omitempty"`
  471. Resourcestate string `json:"resourcestate,omitempty"`
  472. State string `json:"state,omitempty"`
  473. Suitableformigration bool `json:"suitableformigration,omitempty"`
  474. Type string `json:"type,omitempty"`
  475. Version string `json:"version,omitempty"`
  476. Zoneid string `json:"zoneid,omitempty"`
  477. Zonename string `json:"zonename,omitempty"`
  478. }
  479. type DeleteHostParams struct {
  480. p map[string]interface{}
  481. }
  482. func (p *DeleteHostParams) toURLValues() url.Values {
  483. u := url.Values{}
  484. if p.p == nil {
  485. return u
  486. }
  487. if v, found := p.p["forced"]; found {
  488. vv := strconv.FormatBool(v.(bool))
  489. u.Set("forced", vv)
  490. }
  491. if v, found := p.p["forcedestroylocalstorage"]; found {
  492. vv := strconv.FormatBool(v.(bool))
  493. u.Set("forcedestroylocalstorage", vv)
  494. }
  495. if v, found := p.p["id"]; found {
  496. u.Set("id", v.(string))
  497. }
  498. return u
  499. }
  500. func (p *DeleteHostParams) SetForced(v bool) {
  501. if p.p == nil {
  502. p.p = make(map[string]interface{})
  503. }
  504. p.p["forced"] = v
  505. return
  506. }
  507. func (p *DeleteHostParams) SetForcedestroylocalstorage(v bool) {
  508. if p.p == nil {
  509. p.p = make(map[string]interface{})
  510. }
  511. p.p["forcedestroylocalstorage"] = v
  512. return
  513. }
  514. func (p *DeleteHostParams) SetId(v string) {
  515. if p.p == nil {
  516. p.p = make(map[string]interface{})
  517. }
  518. p.p["id"] = v
  519. return
  520. }
  521. // You should always use this function to get a new DeleteHostParams instance,
  522. // as then you are sure you have configured all required params
  523. func (s *HostService) NewDeleteHostParams(id string) *DeleteHostParams {
  524. p := &DeleteHostParams{}
  525. p.p = make(map[string]interface{})
  526. p.p["id"] = id
  527. return p
  528. }
  529. // Deletes a host.
  530. func (s *HostService) DeleteHost(p *DeleteHostParams) (*DeleteHostResponse, error) {
  531. resp, err := s.cs.newRequest("deleteHost", p.toURLValues())
  532. if err != nil {
  533. return nil, err
  534. }
  535. var r DeleteHostResponse
  536. if err := json.Unmarshal(resp, &r); err != nil {
  537. return nil, err
  538. }
  539. return &r, nil
  540. }
  541. type DeleteHostResponse struct {
  542. Displaytext string `json:"displaytext,omitempty"`
  543. Success string `json:"success,omitempty"`
  544. }
  545. type PrepareHostForMaintenanceParams struct {
  546. p map[string]interface{}
  547. }
  548. func (p *PrepareHostForMaintenanceParams) toURLValues() url.Values {
  549. u := url.Values{}
  550. if p.p == nil {
  551. return u
  552. }
  553. if v, found := p.p["id"]; found {
  554. u.Set("id", v.(string))
  555. }
  556. return u
  557. }
  558. func (p *PrepareHostForMaintenanceParams) SetId(v string) {
  559. if p.p == nil {
  560. p.p = make(map[string]interface{})
  561. }
  562. p.p["id"] = v
  563. return
  564. }
  565. // You should always use this function to get a new PrepareHostForMaintenanceParams instance,
  566. // as then you are sure you have configured all required params
  567. func (s *HostService) NewPrepareHostForMaintenanceParams(id string) *PrepareHostForMaintenanceParams {
  568. p := &PrepareHostForMaintenanceParams{}
  569. p.p = make(map[string]interface{})
  570. p.p["id"] = id
  571. return p
  572. }
  573. // Prepares a host for maintenance.
  574. func (s *HostService) PrepareHostForMaintenance(p *PrepareHostForMaintenanceParams) (*PrepareHostForMaintenanceResponse, error) {
  575. resp, err := s.cs.newRequest("prepareHostForMaintenance", p.toURLValues())
  576. if err != nil {
  577. return nil, err
  578. }
  579. var r PrepareHostForMaintenanceResponse
  580. if err := json.Unmarshal(resp, &r); err != nil {
  581. return nil, err
  582. }
  583. // If we have a async client, we need to wait for the async result
  584. if s.cs.async {
  585. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  586. if err != nil {
  587. if err == AsyncTimeoutErr {
  588. return &r, err
  589. }
  590. return nil, err
  591. }
  592. b, err = getRawValue(b)
  593. if err != nil {
  594. return nil, err
  595. }
  596. if err := json.Unmarshal(b, &r); err != nil {
  597. return nil, err
  598. }
  599. }
  600. return &r, nil
  601. }
  602. type PrepareHostForMaintenanceResponse struct {
  603. JobID string `json:"jobid,omitempty"`
  604. Averageload int64 `json:"averageload,omitempty"`
  605. Capabilities string `json:"capabilities,omitempty"`
  606. Clusterid string `json:"clusterid,omitempty"`
  607. Clustername string `json:"clustername,omitempty"`
  608. Clustertype string `json:"clustertype,omitempty"`
  609. Cpuallocated string `json:"cpuallocated,omitempty"`
  610. Cpunumber int `json:"cpunumber,omitempty"`
  611. Cpusockets int `json:"cpusockets,omitempty"`
  612. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  613. Cpuused string `json:"cpuused,omitempty"`
  614. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  615. Created string `json:"created,omitempty"`
  616. Details map[string]string `json:"details,omitempty"`
  617. Disconnected string `json:"disconnected,omitempty"`
  618. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  619. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  620. Events string `json:"events,omitempty"`
  621. Gpugroup []struct {
  622. Gpugroupname string `json:"gpugroupname,omitempty"`
  623. Vgpu []struct {
  624. Maxcapacity int64 `json:"maxcapacity,omitempty"`
  625. Maxheads int64 `json:"maxheads,omitempty"`
  626. Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
  627. Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
  628. Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
  629. Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
  630. Vgputype string `json:"vgputype,omitempty"`
  631. Videoram int64 `json:"videoram,omitempty"`
  632. } `json:"vgpu,omitempty"`
  633. } `json:"gpugroup,omitempty"`
  634. Hahost bool `json:"hahost,omitempty"`
  635. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  636. Hosttags string `json:"hosttags,omitempty"`
  637. Hypervisor string `json:"hypervisor,omitempty"`
  638. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  639. Id string `json:"id,omitempty"`
  640. Ipaddress string `json:"ipaddress,omitempty"`
  641. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  642. Lastpinged string `json:"lastpinged,omitempty"`
  643. Managementserverid int64 `json:"managementserverid,omitempty"`
  644. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  645. Memorytotal int64 `json:"memorytotal,omitempty"`
  646. Memoryused int64 `json:"memoryused,omitempty"`
  647. Name string `json:"name,omitempty"`
  648. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  649. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  650. Oscategoryid string `json:"oscategoryid,omitempty"`
  651. Oscategoryname string `json:"oscategoryname,omitempty"`
  652. Podid string `json:"podid,omitempty"`
  653. Podname string `json:"podname,omitempty"`
  654. Removed string `json:"removed,omitempty"`
  655. Resourcestate string `json:"resourcestate,omitempty"`
  656. State string `json:"state,omitempty"`
  657. Suitableformigration bool `json:"suitableformigration,omitempty"`
  658. Type string `json:"type,omitempty"`
  659. Version string `json:"version,omitempty"`
  660. Zoneid string `json:"zoneid,omitempty"`
  661. Zonename string `json:"zonename,omitempty"`
  662. }
  663. type CancelHostMaintenanceParams struct {
  664. p map[string]interface{}
  665. }
  666. func (p *CancelHostMaintenanceParams) toURLValues() url.Values {
  667. u := url.Values{}
  668. if p.p == nil {
  669. return u
  670. }
  671. if v, found := p.p["id"]; found {
  672. u.Set("id", v.(string))
  673. }
  674. return u
  675. }
  676. func (p *CancelHostMaintenanceParams) SetId(v string) {
  677. if p.p == nil {
  678. p.p = make(map[string]interface{})
  679. }
  680. p.p["id"] = v
  681. return
  682. }
  683. // You should always use this function to get a new CancelHostMaintenanceParams instance,
  684. // as then you are sure you have configured all required params
  685. func (s *HostService) NewCancelHostMaintenanceParams(id string) *CancelHostMaintenanceParams {
  686. p := &CancelHostMaintenanceParams{}
  687. p.p = make(map[string]interface{})
  688. p.p["id"] = id
  689. return p
  690. }
  691. // Cancels host maintenance.
  692. func (s *HostService) CancelHostMaintenance(p *CancelHostMaintenanceParams) (*CancelHostMaintenanceResponse, error) {
  693. resp, err := s.cs.newRequest("cancelHostMaintenance", p.toURLValues())
  694. if err != nil {
  695. return nil, err
  696. }
  697. var r CancelHostMaintenanceResponse
  698. if err := json.Unmarshal(resp, &r); err != nil {
  699. return nil, err
  700. }
  701. // If we have a async client, we need to wait for the async result
  702. if s.cs.async {
  703. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  704. if err != nil {
  705. if err == AsyncTimeoutErr {
  706. return &r, err
  707. }
  708. return nil, err
  709. }
  710. b, err = getRawValue(b)
  711. if err != nil {
  712. return nil, err
  713. }
  714. if err := json.Unmarshal(b, &r); err != nil {
  715. return nil, err
  716. }
  717. }
  718. return &r, nil
  719. }
  720. type CancelHostMaintenanceResponse struct {
  721. JobID string `json:"jobid,omitempty"`
  722. Averageload int64 `json:"averageload,omitempty"`
  723. Capabilities string `json:"capabilities,omitempty"`
  724. Clusterid string `json:"clusterid,omitempty"`
  725. Clustername string `json:"clustername,omitempty"`
  726. Clustertype string `json:"clustertype,omitempty"`
  727. Cpuallocated string `json:"cpuallocated,omitempty"`
  728. Cpunumber int `json:"cpunumber,omitempty"`
  729. Cpusockets int `json:"cpusockets,omitempty"`
  730. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  731. Cpuused string `json:"cpuused,omitempty"`
  732. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  733. Created string `json:"created,omitempty"`
  734. Details map[string]string `json:"details,omitempty"`
  735. Disconnected string `json:"disconnected,omitempty"`
  736. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  737. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  738. Events string `json:"events,omitempty"`
  739. Gpugroup []struct {
  740. Gpugroupname string `json:"gpugroupname,omitempty"`
  741. Vgpu []struct {
  742. Maxcapacity int64 `json:"maxcapacity,omitempty"`
  743. Maxheads int64 `json:"maxheads,omitempty"`
  744. Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
  745. Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
  746. Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
  747. Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
  748. Vgputype string `json:"vgputype,omitempty"`
  749. Videoram int64 `json:"videoram,omitempty"`
  750. } `json:"vgpu,omitempty"`
  751. } `json:"gpugroup,omitempty"`
  752. Hahost bool `json:"hahost,omitempty"`
  753. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  754. Hosttags string `json:"hosttags,omitempty"`
  755. Hypervisor string `json:"hypervisor,omitempty"`
  756. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  757. Id string `json:"id,omitempty"`
  758. Ipaddress string `json:"ipaddress,omitempty"`
  759. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  760. Lastpinged string `json:"lastpinged,omitempty"`
  761. Managementserverid int64 `json:"managementserverid,omitempty"`
  762. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  763. Memorytotal int64 `json:"memorytotal,omitempty"`
  764. Memoryused int64 `json:"memoryused,omitempty"`
  765. Name string `json:"name,omitempty"`
  766. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  767. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  768. Oscategoryid string `json:"oscategoryid,omitempty"`
  769. Oscategoryname string `json:"oscategoryname,omitempty"`
  770. Podid string `json:"podid,omitempty"`
  771. Podname string `json:"podname,omitempty"`
  772. Removed string `json:"removed,omitempty"`
  773. Resourcestate string `json:"resourcestate,omitempty"`
  774. State string `json:"state,omitempty"`
  775. Suitableformigration bool `json:"suitableformigration,omitempty"`
  776. Type string `json:"type,omitempty"`
  777. Version string `json:"version,omitempty"`
  778. Zoneid string `json:"zoneid,omitempty"`
  779. Zonename string `json:"zonename,omitempty"`
  780. }
  781. type ListHostsParams struct {
  782. p map[string]interface{}
  783. }
  784. func (p *ListHostsParams) toURLValues() url.Values {
  785. u := url.Values{}
  786. if p.p == nil {
  787. return u
  788. }
  789. if v, found := p.p["clusterid"]; found {
  790. u.Set("clusterid", v.(string))
  791. }
  792. if v, found := p.p["details"]; found {
  793. vv := strings.Join(v.([]string), ",")
  794. u.Set("details", vv)
  795. }
  796. if v, found := p.p["hahost"]; found {
  797. vv := strconv.FormatBool(v.(bool))
  798. u.Set("hahost", vv)
  799. }
  800. if v, found := p.p["hypervisor"]; found {
  801. u.Set("hypervisor", v.(string))
  802. }
  803. if v, found := p.p["id"]; found {
  804. u.Set("id", v.(string))
  805. }
  806. if v, found := p.p["keyword"]; found {
  807. u.Set("keyword", v.(string))
  808. }
  809. if v, found := p.p["name"]; found {
  810. u.Set("name", v.(string))
  811. }
  812. if v, found := p.p["page"]; found {
  813. vv := strconv.Itoa(v.(int))
  814. u.Set("page", vv)
  815. }
  816. if v, found := p.p["pagesize"]; found {
  817. vv := strconv.Itoa(v.(int))
  818. u.Set("pagesize", vv)
  819. }
  820. if v, found := p.p["podid"]; found {
  821. u.Set("podid", v.(string))
  822. }
  823. if v, found := p.p["resourcestate"]; found {
  824. u.Set("resourcestate", v.(string))
  825. }
  826. if v, found := p.p["state"]; found {
  827. u.Set("state", v.(string))
  828. }
  829. if v, found := p.p["type"]; found {
  830. u.Set("type", v.(string))
  831. }
  832. if v, found := p.p["virtualmachineid"]; found {
  833. u.Set("virtualmachineid", v.(string))
  834. }
  835. if v, found := p.p["zoneid"]; found {
  836. u.Set("zoneid", v.(string))
  837. }
  838. return u
  839. }
  840. func (p *ListHostsParams) SetClusterid(v string) {
  841. if p.p == nil {
  842. p.p = make(map[string]interface{})
  843. }
  844. p.p["clusterid"] = v
  845. return
  846. }
  847. func (p *ListHostsParams) SetDetails(v []string) {
  848. if p.p == nil {
  849. p.p = make(map[string]interface{})
  850. }
  851. p.p["details"] = v
  852. return
  853. }
  854. func (p *ListHostsParams) SetHahost(v bool) {
  855. if p.p == nil {
  856. p.p = make(map[string]interface{})
  857. }
  858. p.p["hahost"] = v
  859. return
  860. }
  861. func (p *ListHostsParams) SetHypervisor(v string) {
  862. if p.p == nil {
  863. p.p = make(map[string]interface{})
  864. }
  865. p.p["hypervisor"] = v
  866. return
  867. }
  868. func (p *ListHostsParams) SetId(v string) {
  869. if p.p == nil {
  870. p.p = make(map[string]interface{})
  871. }
  872. p.p["id"] = v
  873. return
  874. }
  875. func (p *ListHostsParams) SetKeyword(v string) {
  876. if p.p == nil {
  877. p.p = make(map[string]interface{})
  878. }
  879. p.p["keyword"] = v
  880. return
  881. }
  882. func (p *ListHostsParams) SetName(v string) {
  883. if p.p == nil {
  884. p.p = make(map[string]interface{})
  885. }
  886. p.p["name"] = v
  887. return
  888. }
  889. func (p *ListHostsParams) SetPage(v int) {
  890. if p.p == nil {
  891. p.p = make(map[string]interface{})
  892. }
  893. p.p["page"] = v
  894. return
  895. }
  896. func (p *ListHostsParams) SetPagesize(v int) {
  897. if p.p == nil {
  898. p.p = make(map[string]interface{})
  899. }
  900. p.p["pagesize"] = v
  901. return
  902. }
  903. func (p *ListHostsParams) SetPodid(v string) {
  904. if p.p == nil {
  905. p.p = make(map[string]interface{})
  906. }
  907. p.p["podid"] = v
  908. return
  909. }
  910. func (p *ListHostsParams) SetResourcestate(v string) {
  911. if p.p == nil {
  912. p.p = make(map[string]interface{})
  913. }
  914. p.p["resourcestate"] = v
  915. return
  916. }
  917. func (p *ListHostsParams) SetState(v string) {
  918. if p.p == nil {
  919. p.p = make(map[string]interface{})
  920. }
  921. p.p["state"] = v
  922. return
  923. }
  924. func (p *ListHostsParams) SetType(v string) {
  925. if p.p == nil {
  926. p.p = make(map[string]interface{})
  927. }
  928. p.p["hostType"] = v
  929. return
  930. }
  931. func (p *ListHostsParams) SetVirtualmachineid(v string) {
  932. if p.p == nil {
  933. p.p = make(map[string]interface{})
  934. }
  935. p.p["virtualmachineid"] = v
  936. return
  937. }
  938. func (p *ListHostsParams) SetZoneid(v string) {
  939. if p.p == nil {
  940. p.p = make(map[string]interface{})
  941. }
  942. p.p["zoneid"] = v
  943. return
  944. }
  945. // You should always use this function to get a new ListHostsParams instance,
  946. // as then you are sure you have configured all required params
  947. func (s *HostService) NewListHostsParams() *ListHostsParams {
  948. p := &ListHostsParams{}
  949. p.p = make(map[string]interface{})
  950. return p
  951. }
  952. // This is a courtesy helper function, which in some cases may not work as expected!
  953. func (s *HostService) GetHostID(name string, opts ...OptionFunc) (string, int, error) {
  954. p := &ListHostsParams{}
  955. p.p = make(map[string]interface{})
  956. p.p["name"] = name
  957. for _, fn := range opts {
  958. if err := fn(s.cs, p); err != nil {
  959. return "", -1, err
  960. }
  961. }
  962. l, err := s.ListHosts(p)
  963. if err != nil {
  964. return "", -1, err
  965. }
  966. if l.Count == 0 {
  967. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  968. }
  969. if l.Count == 1 {
  970. return l.Hosts[0].Id, l.Count, nil
  971. }
  972. if l.Count > 1 {
  973. for _, v := range l.Hosts {
  974. if v.Name == name {
  975. return v.Id, l.Count, nil
  976. }
  977. }
  978. }
  979. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  980. }
  981. // This is a courtesy helper function, which in some cases may not work as expected!
  982. func (s *HostService) GetHostByName(name string, opts ...OptionFunc) (*Host, int, error) {
  983. id, count, err := s.GetHostID(name, opts...)
  984. if err != nil {
  985. return nil, count, err
  986. }
  987. r, count, err := s.GetHostByID(id, opts...)
  988. if err != nil {
  989. return nil, count, err
  990. }
  991. return r, count, nil
  992. }
  993. // This is a courtesy helper function, which in some cases may not work as expected!
  994. func (s *HostService) GetHostByID(id string, opts ...OptionFunc) (*Host, int, error) {
  995. p := &ListHostsParams{}
  996. p.p = make(map[string]interface{})
  997. p.p["id"] = id
  998. for _, fn := range opts {
  999. if err := fn(s.cs, p); err != nil {
  1000. return nil, -1, err
  1001. }
  1002. }
  1003. l, err := s.ListHosts(p)
  1004. if err != nil {
  1005. if strings.Contains(err.Error(), fmt.Sprintf(
  1006. "Invalid parameter id value=%s due to incorrect long value format, "+
  1007. "or entity does not exist", id)) {
  1008. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1009. }
  1010. return nil, -1, err
  1011. }
  1012. if l.Count == 0 {
  1013. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1014. }
  1015. if l.Count == 1 {
  1016. return l.Hosts[0], l.Count, nil
  1017. }
  1018. return nil, l.Count, fmt.Errorf("There is more then one result for Host UUID: %s!", id)
  1019. }
  1020. // Lists hosts.
  1021. func (s *HostService) ListHosts(p *ListHostsParams) (*ListHostsResponse, error) {
  1022. resp, err := s.cs.newRequest("listHosts", p.toURLValues())
  1023. if err != nil {
  1024. return nil, err
  1025. }
  1026. var r ListHostsResponse
  1027. if err := json.Unmarshal(resp, &r); err != nil {
  1028. return nil, err
  1029. }
  1030. return &r, nil
  1031. }
  1032. type ListHostsResponse struct {
  1033. Count int `json:"count"`
  1034. Hosts []*Host `json:"host"`
  1035. }
  1036. type Host struct {
  1037. Averageload int64 `json:"averageload,omitempty"`
  1038. Capabilities string `json:"capabilities,omitempty"`
  1039. Clusterid string `json:"clusterid,omitempty"`
  1040. Clustername string `json:"clustername,omitempty"`
  1041. Clustertype string `json:"clustertype,omitempty"`
  1042. Cpuallocated string `json:"cpuallocated,omitempty"`
  1043. Cpunumber int `json:"cpunumber,omitempty"`
  1044. Cpusockets int `json:"cpusockets,omitempty"`
  1045. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  1046. Cpuused string `json:"cpuused,omitempty"`
  1047. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  1048. Created string `json:"created,omitempty"`
  1049. Details map[string]string `json:"details,omitempty"`
  1050. Disconnected string `json:"disconnected,omitempty"`
  1051. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  1052. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  1053. Events string `json:"events,omitempty"`
  1054. Gpugroup []struct {
  1055. Gpugroupname string `json:"gpugroupname,omitempty"`
  1056. Vgpu []struct {
  1057. Maxcapacity int64 `json:"maxcapacity,omitempty"`
  1058. Maxheads int64 `json:"maxheads,omitempty"`
  1059. Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
  1060. Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
  1061. Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
  1062. Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
  1063. Vgputype string `json:"vgputype,omitempty"`
  1064. Videoram int64 `json:"videoram,omitempty"`
  1065. } `json:"vgpu,omitempty"`
  1066. } `json:"gpugroup,omitempty"`
  1067. Hahost bool `json:"hahost,omitempty"`
  1068. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  1069. Hosttags string `json:"hosttags,omitempty"`
  1070. Hypervisor string `json:"hypervisor,omitempty"`
  1071. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  1072. Id string `json:"id,omitempty"`
  1073. Ipaddress string `json:"ipaddress,omitempty"`
  1074. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  1075. Lastpinged string `json:"lastpinged,omitempty"`
  1076. Managementserverid int64 `json:"managementserverid,omitempty"`
  1077. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  1078. Memorytotal int64 `json:"memorytotal,omitempty"`
  1079. Memoryused int64 `json:"memoryused,omitempty"`
  1080. Name string `json:"name,omitempty"`
  1081. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  1082. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  1083. Oscategoryid string `json:"oscategoryid,omitempty"`
  1084. Oscategoryname string `json:"oscategoryname,omitempty"`
  1085. Podid string `json:"podid,omitempty"`
  1086. Podname string `json:"podname,omitempty"`
  1087. Removed string `json:"removed,omitempty"`
  1088. Resourcestate string `json:"resourcestate,omitempty"`
  1089. State string `json:"state,omitempty"`
  1090. Suitableformigration bool `json:"suitableformigration,omitempty"`
  1091. Type string `json:"type,omitempty"`
  1092. Version string `json:"version,omitempty"`
  1093. Zoneid string `json:"zoneid,omitempty"`
  1094. Zonename string `json:"zonename,omitempty"`
  1095. }
  1096. type ListHostTagsParams struct {
  1097. p map[string]interface{}
  1098. }
  1099. func (p *ListHostTagsParams) toURLValues() url.Values {
  1100. u := url.Values{}
  1101. if p.p == nil {
  1102. return u
  1103. }
  1104. if v, found := p.p["keyword"]; found {
  1105. u.Set("keyword", v.(string))
  1106. }
  1107. if v, found := p.p["page"]; found {
  1108. vv := strconv.Itoa(v.(int))
  1109. u.Set("page", vv)
  1110. }
  1111. if v, found := p.p["pagesize"]; found {
  1112. vv := strconv.Itoa(v.(int))
  1113. u.Set("pagesize", vv)
  1114. }
  1115. return u
  1116. }
  1117. func (p *ListHostTagsParams) SetKeyword(v string) {
  1118. if p.p == nil {
  1119. p.p = make(map[string]interface{})
  1120. }
  1121. p.p["keyword"] = v
  1122. return
  1123. }
  1124. func (p *ListHostTagsParams) SetPage(v int) {
  1125. if p.p == nil {
  1126. p.p = make(map[string]interface{})
  1127. }
  1128. p.p["page"] = v
  1129. return
  1130. }
  1131. func (p *ListHostTagsParams) SetPagesize(v int) {
  1132. if p.p == nil {
  1133. p.p = make(map[string]interface{})
  1134. }
  1135. p.p["pagesize"] = v
  1136. return
  1137. }
  1138. // You should always use this function to get a new ListHostTagsParams instance,
  1139. // as then you are sure you have configured all required params
  1140. func (s *HostService) NewListHostTagsParams() *ListHostTagsParams {
  1141. p := &ListHostTagsParams{}
  1142. p.p = make(map[string]interface{})
  1143. return p
  1144. }
  1145. // This is a courtesy helper function, which in some cases may not work as expected!
  1146. func (s *HostService) GetHostTagID(keyword string, opts ...OptionFunc) (string, int, error) {
  1147. p := &ListHostTagsParams{}
  1148. p.p = make(map[string]interface{})
  1149. p.p["keyword"] = keyword
  1150. for _, fn := range opts {
  1151. if err := fn(s.cs, p); err != nil {
  1152. return "", -1, err
  1153. }
  1154. }
  1155. l, err := s.ListHostTags(p)
  1156. if err != nil {
  1157. return "", -1, err
  1158. }
  1159. if l.Count == 0 {
  1160. return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l)
  1161. }
  1162. if l.Count == 1 {
  1163. return l.HostTags[0].Id, l.Count, nil
  1164. }
  1165. if l.Count > 1 {
  1166. for _, v := range l.HostTags {
  1167. if v.Name == keyword {
  1168. return v.Id, l.Count, nil
  1169. }
  1170. }
  1171. }
  1172. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l)
  1173. }
  1174. // Lists host tags
  1175. func (s *HostService) ListHostTags(p *ListHostTagsParams) (*ListHostTagsResponse, error) {
  1176. resp, err := s.cs.newRequest("listHostTags", p.toURLValues())
  1177. if err != nil {
  1178. return nil, err
  1179. }
  1180. var r ListHostTagsResponse
  1181. if err := json.Unmarshal(resp, &r); err != nil {
  1182. return nil, err
  1183. }
  1184. return &r, nil
  1185. }
  1186. type ListHostTagsResponse struct {
  1187. Count int `json:"count"`
  1188. HostTags []*HostTag `json:"hosttag"`
  1189. }
  1190. type HostTag struct {
  1191. Hostid int64 `json:"hostid,omitempty"`
  1192. Id string `json:"id,omitempty"`
  1193. Name string `json:"name,omitempty"`
  1194. }
  1195. type FindHostsForMigrationParams struct {
  1196. p map[string]interface{}
  1197. }
  1198. func (p *FindHostsForMigrationParams) toURLValues() url.Values {
  1199. u := url.Values{}
  1200. if p.p == nil {
  1201. return u
  1202. }
  1203. if v, found := p.p["keyword"]; found {
  1204. u.Set("keyword", v.(string))
  1205. }
  1206. if v, found := p.p["page"]; found {
  1207. vv := strconv.Itoa(v.(int))
  1208. u.Set("page", vv)
  1209. }
  1210. if v, found := p.p["pagesize"]; found {
  1211. vv := strconv.Itoa(v.(int))
  1212. u.Set("pagesize", vv)
  1213. }
  1214. if v, found := p.p["virtualmachineid"]; found {
  1215. u.Set("virtualmachineid", v.(string))
  1216. }
  1217. return u
  1218. }
  1219. func (p *FindHostsForMigrationParams) SetKeyword(v string) {
  1220. if p.p == nil {
  1221. p.p = make(map[string]interface{})
  1222. }
  1223. p.p["keyword"] = v
  1224. return
  1225. }
  1226. func (p *FindHostsForMigrationParams) SetPage(v int) {
  1227. if p.p == nil {
  1228. p.p = make(map[string]interface{})
  1229. }
  1230. p.p["page"] = v
  1231. return
  1232. }
  1233. func (p *FindHostsForMigrationParams) SetPagesize(v int) {
  1234. if p.p == nil {
  1235. p.p = make(map[string]interface{})
  1236. }
  1237. p.p["pagesize"] = v
  1238. return
  1239. }
  1240. func (p *FindHostsForMigrationParams) SetVirtualmachineid(v string) {
  1241. if p.p == nil {
  1242. p.p = make(map[string]interface{})
  1243. }
  1244. p.p["virtualmachineid"] = v
  1245. return
  1246. }
  1247. // You should always use this function to get a new FindHostsForMigrationParams instance,
  1248. // as then you are sure you have configured all required params
  1249. func (s *HostService) NewFindHostsForMigrationParams(virtualmachineid string) *FindHostsForMigrationParams {
  1250. p := &FindHostsForMigrationParams{}
  1251. p.p = make(map[string]interface{})
  1252. p.p["virtualmachineid"] = virtualmachineid
  1253. return p
  1254. }
  1255. // Find hosts suitable for migrating a virtual machine.
  1256. func (s *HostService) FindHostsForMigration(p *FindHostsForMigrationParams) (*FindHostsForMigrationResponse, error) {
  1257. resp, err := s.cs.newRequest("findHostsForMigration", p.toURLValues())
  1258. if err != nil {
  1259. return nil, err
  1260. }
  1261. var r FindHostsForMigrationResponse
  1262. if err := json.Unmarshal(resp, &r); err != nil {
  1263. return nil, err
  1264. }
  1265. return &r, nil
  1266. }
  1267. type FindHostsForMigrationResponse struct {
  1268. Averageload int64 `json:"averageload,omitempty"`
  1269. Capabilities string `json:"capabilities,omitempty"`
  1270. Clusterid string `json:"clusterid,omitempty"`
  1271. Clustername string `json:"clustername,omitempty"`
  1272. Clustertype string `json:"clustertype,omitempty"`
  1273. Cpuallocated string `json:"cpuallocated,omitempty"`
  1274. Cpunumber int `json:"cpunumber,omitempty"`
  1275. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  1276. Cpuused string `json:"cpuused,omitempty"`
  1277. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  1278. Created string `json:"created,omitempty"`
  1279. Disconnected string `json:"disconnected,omitempty"`
  1280. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  1281. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  1282. Events string `json:"events,omitempty"`
  1283. Hahost bool `json:"hahost,omitempty"`
  1284. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  1285. Hosttags string `json:"hosttags,omitempty"`
  1286. Hypervisor string `json:"hypervisor,omitempty"`
  1287. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  1288. Id string `json:"id,omitempty"`
  1289. Ipaddress string `json:"ipaddress,omitempty"`
  1290. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  1291. Lastpinged string `json:"lastpinged,omitempty"`
  1292. Managementserverid int64 `json:"managementserverid,omitempty"`
  1293. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  1294. Memorytotal int64 `json:"memorytotal,omitempty"`
  1295. Memoryused int64 `json:"memoryused,omitempty"`
  1296. Name string `json:"name,omitempty"`
  1297. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  1298. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  1299. Oscategoryid string `json:"oscategoryid,omitempty"`
  1300. Oscategoryname string `json:"oscategoryname,omitempty"`
  1301. Podid string `json:"podid,omitempty"`
  1302. Podname string `json:"podname,omitempty"`
  1303. Removed string `json:"removed,omitempty"`
  1304. RequiresStorageMotion bool `json:"requiresStorageMotion,omitempty"`
  1305. Resourcestate string `json:"resourcestate,omitempty"`
  1306. State string `json:"state,omitempty"`
  1307. Suitableformigration bool `json:"suitableformigration,omitempty"`
  1308. Type string `json:"type,omitempty"`
  1309. Version string `json:"version,omitempty"`
  1310. Zoneid string `json:"zoneid,omitempty"`
  1311. Zonename string `json:"zonename,omitempty"`
  1312. }
  1313. type AddSecondaryStorageParams struct {
  1314. p map[string]interface{}
  1315. }
  1316. func (p *AddSecondaryStorageParams) toURLValues() url.Values {
  1317. u := url.Values{}
  1318. if p.p == nil {
  1319. return u
  1320. }
  1321. if v, found := p.p["url"]; found {
  1322. u.Set("url", v.(string))
  1323. }
  1324. if v, found := p.p["zoneid"]; found {
  1325. u.Set("zoneid", v.(string))
  1326. }
  1327. return u
  1328. }
  1329. func (p *AddSecondaryStorageParams) SetUrl(v string) {
  1330. if p.p == nil {
  1331. p.p = make(map[string]interface{})
  1332. }
  1333. p.p["url"] = v
  1334. return
  1335. }
  1336. func (p *AddSecondaryStorageParams) SetZoneid(v string) {
  1337. if p.p == nil {
  1338. p.p = make(map[string]interface{})
  1339. }
  1340. p.p["zoneid"] = v
  1341. return
  1342. }
  1343. // You should always use this function to get a new AddSecondaryStorageParams instance,
  1344. // as then you are sure you have configured all required params
  1345. func (s *HostService) NewAddSecondaryStorageParams(url string) *AddSecondaryStorageParams {
  1346. p := &AddSecondaryStorageParams{}
  1347. p.p = make(map[string]interface{})
  1348. p.p["url"] = url
  1349. return p
  1350. }
  1351. // Adds secondary storage.
  1352. func (s *HostService) AddSecondaryStorage(p *AddSecondaryStorageParams) (*AddSecondaryStorageResponse, error) {
  1353. resp, err := s.cs.newRequest("addSecondaryStorage", p.toURLValues())
  1354. if err != nil {
  1355. return nil, err
  1356. }
  1357. var r AddSecondaryStorageResponse
  1358. if err := json.Unmarshal(resp, &r); err != nil {
  1359. return nil, err
  1360. }
  1361. return &r, nil
  1362. }
  1363. type AddSecondaryStorageResponse struct {
  1364. Details []string `json:"details,omitempty"`
  1365. Id string `json:"id,omitempty"`
  1366. Name string `json:"name,omitempty"`
  1367. Protocol string `json:"protocol,omitempty"`
  1368. Providername string `json:"providername,omitempty"`
  1369. Scope string `json:"scope,omitempty"`
  1370. Url string `json:"url,omitempty"`
  1371. Zoneid string `json:"zoneid,omitempty"`
  1372. Zonename string `json:"zonename,omitempty"`
  1373. }
  1374. type UpdateHostPasswordParams struct {
  1375. p map[string]interface{}
  1376. }
  1377. func (p *UpdateHostPasswordParams) toURLValues() url.Values {
  1378. u := url.Values{}
  1379. if p.p == nil {
  1380. return u
  1381. }
  1382. if v, found := p.p["clusterid"]; found {
  1383. u.Set("clusterid", v.(string))
  1384. }
  1385. if v, found := p.p["hostid"]; found {
  1386. u.Set("hostid", v.(string))
  1387. }
  1388. if v, found := p.p["password"]; found {
  1389. u.Set("password", v.(string))
  1390. }
  1391. if v, found := p.p["update_passwd_on_host"]; found {
  1392. vv := strconv.FormatBool(v.(bool))
  1393. u.Set("update_passwd_on_host", vv)
  1394. }
  1395. if v, found := p.p["username"]; found {
  1396. u.Set("username", v.(string))
  1397. }
  1398. return u
  1399. }
  1400. func (p *UpdateHostPasswordParams) SetClusterid(v string) {
  1401. if p.p == nil {
  1402. p.p = make(map[string]interface{})
  1403. }
  1404. p.p["clusterid"] = v
  1405. return
  1406. }
  1407. func (p *UpdateHostPasswordParams) SetHostid(v string) {
  1408. if p.p == nil {
  1409. p.p = make(map[string]interface{})
  1410. }
  1411. p.p["hostid"] = v
  1412. return
  1413. }
  1414. func (p *UpdateHostPasswordParams) SetPassword(v string) {
  1415. if p.p == nil {
  1416. p.p = make(map[string]interface{})
  1417. }
  1418. p.p["password"] = v
  1419. return
  1420. }
  1421. func (p *UpdateHostPasswordParams) SetUpdate_passwd_on_host(v bool) {
  1422. if p.p == nil {
  1423. p.p = make(map[string]interface{})
  1424. }
  1425. p.p["update_passwd_on_host"] = v
  1426. return
  1427. }
  1428. func (p *UpdateHostPasswordParams) SetUsername(v string) {
  1429. if p.p == nil {
  1430. p.p = make(map[string]interface{})
  1431. }
  1432. p.p["username"] = v
  1433. return
  1434. }
  1435. // You should always use this function to get a new UpdateHostPasswordParams instance,
  1436. // as then you are sure you have configured all required params
  1437. func (s *HostService) NewUpdateHostPasswordParams(password string, username string) *UpdateHostPasswordParams {
  1438. p := &UpdateHostPasswordParams{}
  1439. p.p = make(map[string]interface{})
  1440. p.p["password"] = password
  1441. p.p["username"] = username
  1442. return p
  1443. }
  1444. // Update password of a host/pool on management server.
  1445. func (s *HostService) UpdateHostPassword(p *UpdateHostPasswordParams) (*UpdateHostPasswordResponse, error) {
  1446. resp, err := s.cs.newRequest("updateHostPassword", p.toURLValues())
  1447. if err != nil {
  1448. return nil, err
  1449. }
  1450. var r UpdateHostPasswordResponse
  1451. if err := json.Unmarshal(resp, &r); err != nil {
  1452. return nil, err
  1453. }
  1454. return &r, nil
  1455. }
  1456. type UpdateHostPasswordResponse struct {
  1457. Displaytext string `json:"displaytext,omitempty"`
  1458. Success string `json:"success,omitempty"`
  1459. }
  1460. type ReleaseHostReservationParams struct {
  1461. p map[string]interface{}
  1462. }
  1463. func (p *ReleaseHostReservationParams) toURLValues() url.Values {
  1464. u := url.Values{}
  1465. if p.p == nil {
  1466. return u
  1467. }
  1468. if v, found := p.p["id"]; found {
  1469. u.Set("id", v.(string))
  1470. }
  1471. return u
  1472. }
  1473. func (p *ReleaseHostReservationParams) SetId(v string) {
  1474. if p.p == nil {
  1475. p.p = make(map[string]interface{})
  1476. }
  1477. p.p["id"] = v
  1478. return
  1479. }
  1480. // You should always use this function to get a new ReleaseHostReservationParams instance,
  1481. // as then you are sure you have configured all required params
  1482. func (s *HostService) NewReleaseHostReservationParams(id string) *ReleaseHostReservationParams {
  1483. p := &ReleaseHostReservationParams{}
  1484. p.p = make(map[string]interface{})
  1485. p.p["id"] = id
  1486. return p
  1487. }
  1488. // Releases host reservation.
  1489. func (s *HostService) ReleaseHostReservation(p *ReleaseHostReservationParams) (*ReleaseHostReservationResponse, error) {
  1490. resp, err := s.cs.newRequest("releaseHostReservation", p.toURLValues())
  1491. if err != nil {
  1492. return nil, err
  1493. }
  1494. var r ReleaseHostReservationResponse
  1495. if err := json.Unmarshal(resp, &r); err != nil {
  1496. return nil, err
  1497. }
  1498. // If we have a async client, we need to wait for the async result
  1499. if s.cs.async {
  1500. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1501. if err != nil {
  1502. if err == AsyncTimeoutErr {
  1503. return &r, err
  1504. }
  1505. return nil, err
  1506. }
  1507. if err := json.Unmarshal(b, &r); err != nil {
  1508. return nil, err
  1509. }
  1510. }
  1511. return &r, nil
  1512. }
  1513. type ReleaseHostReservationResponse struct {
  1514. JobID string `json:"jobid,omitempty"`
  1515. Displaytext string `json:"displaytext,omitempty"`
  1516. Success bool `json:"success,omitempty"`
  1517. }
  1518. type AddBaremetalHostParams struct {
  1519. p map[string]interface{}
  1520. }
  1521. func (p *AddBaremetalHostParams) toURLValues() url.Values {
  1522. u := url.Values{}
  1523. if p.p == nil {
  1524. return u
  1525. }
  1526. if v, found := p.p["allocationstate"]; found {
  1527. u.Set("allocationstate", v.(string))
  1528. }
  1529. if v, found := p.p["clusterid"]; found {
  1530. u.Set("clusterid", v.(string))
  1531. }
  1532. if v, found := p.p["clustername"]; found {
  1533. u.Set("clustername", v.(string))
  1534. }
  1535. if v, found := p.p["hosttags"]; found {
  1536. vv := strings.Join(v.([]string), ",")
  1537. u.Set("hosttags", vv)
  1538. }
  1539. if v, found := p.p["hypervisor"]; found {
  1540. u.Set("hypervisor", v.(string))
  1541. }
  1542. if v, found := p.p["ipaddress"]; found {
  1543. u.Set("ipaddress", v.(string))
  1544. }
  1545. if v, found := p.p["password"]; found {
  1546. u.Set("password", v.(string))
  1547. }
  1548. if v, found := p.p["podid"]; found {
  1549. u.Set("podid", v.(string))
  1550. }
  1551. if v, found := p.p["url"]; found {
  1552. u.Set("url", v.(string))
  1553. }
  1554. if v, found := p.p["username"]; found {
  1555. u.Set("username", v.(string))
  1556. }
  1557. if v, found := p.p["zoneid"]; found {
  1558. u.Set("zoneid", v.(string))
  1559. }
  1560. return u
  1561. }
  1562. func (p *AddBaremetalHostParams) SetAllocationstate(v string) {
  1563. if p.p == nil {
  1564. p.p = make(map[string]interface{})
  1565. }
  1566. p.p["allocationstate"] = v
  1567. return
  1568. }
  1569. func (p *AddBaremetalHostParams) SetClusterid(v string) {
  1570. if p.p == nil {
  1571. p.p = make(map[string]interface{})
  1572. }
  1573. p.p["clusterid"] = v
  1574. return
  1575. }
  1576. func (p *AddBaremetalHostParams) SetClustername(v string) {
  1577. if p.p == nil {
  1578. p.p = make(map[string]interface{})
  1579. }
  1580. p.p["clustername"] = v
  1581. return
  1582. }
  1583. func (p *AddBaremetalHostParams) SetHosttags(v []string) {
  1584. if p.p == nil {
  1585. p.p = make(map[string]interface{})
  1586. }
  1587. p.p["hosttags"] = v
  1588. return
  1589. }
  1590. func (p *AddBaremetalHostParams) SetHypervisor(v string) {
  1591. if p.p == nil {
  1592. p.p = make(map[string]interface{})
  1593. }
  1594. p.p["hypervisor"] = v
  1595. return
  1596. }
  1597. func (p *AddBaremetalHostParams) SetIpaddress(v string) {
  1598. if p.p == nil {
  1599. p.p = make(map[string]interface{})
  1600. }
  1601. p.p["ipaddress"] = v
  1602. return
  1603. }
  1604. func (p *AddBaremetalHostParams) SetPassword(v string) {
  1605. if p.p == nil {
  1606. p.p = make(map[string]interface{})
  1607. }
  1608. p.p["password"] = v
  1609. return
  1610. }
  1611. func (p *AddBaremetalHostParams) SetPodid(v string) {
  1612. if p.p == nil {
  1613. p.p = make(map[string]interface{})
  1614. }
  1615. p.p["podid"] = v
  1616. return
  1617. }
  1618. func (p *AddBaremetalHostParams) SetUrl(v string) {
  1619. if p.p == nil {
  1620. p.p = make(map[string]interface{})
  1621. }
  1622. p.p["url"] = v
  1623. return
  1624. }
  1625. func (p *AddBaremetalHostParams) SetUsername(v string) {
  1626. if p.p == nil {
  1627. p.p = make(map[string]interface{})
  1628. }
  1629. p.p["username"] = v
  1630. return
  1631. }
  1632. func (p *AddBaremetalHostParams) SetZoneid(v string) {
  1633. if p.p == nil {
  1634. p.p = make(map[string]interface{})
  1635. }
  1636. p.p["zoneid"] = v
  1637. return
  1638. }
  1639. // You should always use this function to get a new AddBaremetalHostParams instance,
  1640. // as then you are sure you have configured all required params
  1641. func (s *HostService) NewAddBaremetalHostParams(hypervisor string, password string, podid string, url string, username string, zoneid string) *AddBaremetalHostParams {
  1642. p := &AddBaremetalHostParams{}
  1643. p.p = make(map[string]interface{})
  1644. p.p["hypervisor"] = hypervisor
  1645. p.p["password"] = password
  1646. p.p["podid"] = podid
  1647. p.p["url"] = url
  1648. p.p["username"] = username
  1649. p.p["zoneid"] = zoneid
  1650. return p
  1651. }
  1652. // add a baremetal host
  1653. func (s *HostService) AddBaremetalHost(p *AddBaremetalHostParams) (*AddBaremetalHostResponse, error) {
  1654. resp, err := s.cs.newRequest("addBaremetalHost", p.toURLValues())
  1655. if err != nil {
  1656. return nil, err
  1657. }
  1658. var r AddBaremetalHostResponse
  1659. if err := json.Unmarshal(resp, &r); err != nil {
  1660. return nil, err
  1661. }
  1662. return &r, nil
  1663. }
  1664. type AddBaremetalHostResponse struct {
  1665. Averageload int64 `json:"averageload,omitempty"`
  1666. Capabilities string `json:"capabilities,omitempty"`
  1667. Clusterid string `json:"clusterid,omitempty"`
  1668. Clustername string `json:"clustername,omitempty"`
  1669. Clustertype string `json:"clustertype,omitempty"`
  1670. Cpuallocated string `json:"cpuallocated,omitempty"`
  1671. Cpunumber int `json:"cpunumber,omitempty"`
  1672. Cpusockets int `json:"cpusockets,omitempty"`
  1673. Cpuspeed int64 `json:"cpuspeed,omitempty"`
  1674. Cpuused string `json:"cpuused,omitempty"`
  1675. Cpuwithoverprovisioning string `json:"cpuwithoverprovisioning,omitempty"`
  1676. Created string `json:"created,omitempty"`
  1677. Details map[string]string `json:"details,omitempty"`
  1678. Disconnected string `json:"disconnected,omitempty"`
  1679. Disksizeallocated int64 `json:"disksizeallocated,omitempty"`
  1680. Disksizetotal int64 `json:"disksizetotal,omitempty"`
  1681. Events string `json:"events,omitempty"`
  1682. Gpugroup []struct {
  1683. Gpugroupname string `json:"gpugroupname,omitempty"`
  1684. Vgpu []struct {
  1685. Maxcapacity int64 `json:"maxcapacity,omitempty"`
  1686. Maxheads int64 `json:"maxheads,omitempty"`
  1687. Maxresolutionx int64 `json:"maxresolutionx,omitempty"`
  1688. Maxresolutiony int64 `json:"maxresolutiony,omitempty"`
  1689. Maxvgpuperpgpu int64 `json:"maxvgpuperpgpu,omitempty"`
  1690. Remainingcapacity int64 `json:"remainingcapacity,omitempty"`
  1691. Vgputype string `json:"vgputype,omitempty"`
  1692. Videoram int64 `json:"videoram,omitempty"`
  1693. } `json:"vgpu,omitempty"`
  1694. } `json:"gpugroup,omitempty"`
  1695. Hahost bool `json:"hahost,omitempty"`
  1696. Hasenoughcapacity bool `json:"hasenoughcapacity,omitempty"`
  1697. Hosttags string `json:"hosttags,omitempty"`
  1698. Hypervisor string `json:"hypervisor,omitempty"`
  1699. Hypervisorversion string `json:"hypervisorversion,omitempty"`
  1700. Id string `json:"id,omitempty"`
  1701. Ipaddress string `json:"ipaddress,omitempty"`
  1702. Islocalstorageactive bool `json:"islocalstorageactive,omitempty"`
  1703. Lastpinged string `json:"lastpinged,omitempty"`
  1704. Managementserverid int64 `json:"managementserverid,omitempty"`
  1705. Memoryallocated int64 `json:"memoryallocated,omitempty"`
  1706. Memorytotal int64 `json:"memorytotal,omitempty"`
  1707. Memoryused int64 `json:"memoryused,omitempty"`
  1708. Name string `json:"name,omitempty"`
  1709. Networkkbsread int64 `json:"networkkbsread,omitempty"`
  1710. Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
  1711. Oscategoryid string `json:"oscategoryid,omitempty"`
  1712. Oscategoryname string `json:"oscategoryname,omitempty"`
  1713. Podid string `json:"podid,omitempty"`
  1714. Podname string `json:"podname,omitempty"`
  1715. Removed string `json:"removed,omitempty"`
  1716. Resourcestate string `json:"resourcestate,omitempty"`
  1717. State string `json:"state,omitempty"`
  1718. Suitableformigration bool `json:"suitableformigration,omitempty"`
  1719. Type string `json:"type,omitempty"`
  1720. Version string `json:"version,omitempty"`
  1721. Zoneid string `json:"zoneid,omitempty"`
  1722. Zonename string `json:"zonename,omitempty"`
  1723. }
  1724. type DedicateHostParams struct {
  1725. p map[string]interface{}
  1726. }
  1727. func (p *DedicateHostParams) toURLValues() url.Values {
  1728. u := url.Values{}
  1729. if p.p == nil {
  1730. return u
  1731. }
  1732. if v, found := p.p["account"]; found {
  1733. u.Set("account", v.(string))
  1734. }
  1735. if v, found := p.p["domainid"]; found {
  1736. u.Set("domainid", v.(string))
  1737. }
  1738. if v, found := p.p["hostid"]; found {
  1739. u.Set("hostid", v.(string))
  1740. }
  1741. return u
  1742. }
  1743. func (p *DedicateHostParams) SetAccount(v string) {
  1744. if p.p == nil {
  1745. p.p = make(map[string]interface{})
  1746. }
  1747. p.p["account"] = v
  1748. return
  1749. }
  1750. func (p *DedicateHostParams) SetDomainid(v string) {
  1751. if p.p == nil {
  1752. p.p = make(map[string]interface{})
  1753. }
  1754. p.p["domainid"] = v
  1755. return
  1756. }
  1757. func (p *DedicateHostParams) SetHostid(v string) {
  1758. if p.p == nil {
  1759. p.p = make(map[string]interface{})
  1760. }
  1761. p.p["hostid"] = v
  1762. return
  1763. }
  1764. // You should always use this function to get a new DedicateHostParams instance,
  1765. // as then you are sure you have configured all required params
  1766. func (s *HostService) NewDedicateHostParams(domainid string, hostid string) *DedicateHostParams {
  1767. p := &DedicateHostParams{}
  1768. p.p = make(map[string]interface{})
  1769. p.p["domainid"] = domainid
  1770. p.p["hostid"] = hostid
  1771. return p
  1772. }
  1773. // Dedicates a host.
  1774. func (s *HostService) DedicateHost(p *DedicateHostParams) (*DedicateHostResponse, error) {
  1775. resp, err := s.cs.newRequest("dedicateHost", p.toURLValues())
  1776. if err != nil {
  1777. return nil, err
  1778. }
  1779. var r DedicateHostResponse
  1780. if err := json.Unmarshal(resp, &r); err != nil {
  1781. return nil, err
  1782. }
  1783. // If we have a async client, we need to wait for the async result
  1784. if s.cs.async {
  1785. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1786. if err != nil {
  1787. if err == AsyncTimeoutErr {
  1788. return &r, err
  1789. }
  1790. return nil, err
  1791. }
  1792. b, err = getRawValue(b)
  1793. if err != nil {
  1794. return nil, err
  1795. }
  1796. if err := json.Unmarshal(b, &r); err != nil {
  1797. return nil, err
  1798. }
  1799. }
  1800. return &r, nil
  1801. }
  1802. type DedicateHostResponse struct {
  1803. JobID string `json:"jobid,omitempty"`
  1804. Accountid string `json:"accountid,omitempty"`
  1805. Affinitygroupid string `json:"affinitygroupid,omitempty"`
  1806. Domainid string `json:"domainid,omitempty"`
  1807. Hostid string `json:"hostid,omitempty"`
  1808. Hostname string `json:"hostname,omitempty"`
  1809. Id string `json:"id,omitempty"`
  1810. }
  1811. type ReleaseDedicatedHostParams struct {
  1812. p map[string]interface{}
  1813. }
  1814. func (p *ReleaseDedicatedHostParams) toURLValues() url.Values {
  1815. u := url.Values{}
  1816. if p.p == nil {
  1817. return u
  1818. }
  1819. if v, found := p.p["hostid"]; found {
  1820. u.Set("hostid", v.(string))
  1821. }
  1822. return u
  1823. }
  1824. func (p *ReleaseDedicatedHostParams) SetHostid(v string) {
  1825. if p.p == nil {
  1826. p.p = make(map[string]interface{})
  1827. }
  1828. p.p["hostid"] = v
  1829. return
  1830. }
  1831. // You should always use this function to get a new ReleaseDedicatedHostParams instance,
  1832. // as then you are sure you have configured all required params
  1833. func (s *HostService) NewReleaseDedicatedHostParams(hostid string) *ReleaseDedicatedHostParams {
  1834. p := &ReleaseDedicatedHostParams{}
  1835. p.p = make(map[string]interface{})
  1836. p.p["hostid"] = hostid
  1837. return p
  1838. }
  1839. // Release the dedication for host
  1840. func (s *HostService) ReleaseDedicatedHost(p *ReleaseDedicatedHostParams) (*ReleaseDedicatedHostResponse, error) {
  1841. resp, err := s.cs.newRequest("releaseDedicatedHost", p.toURLValues())
  1842. if err != nil {
  1843. return nil, err
  1844. }
  1845. var r ReleaseDedicatedHostResponse
  1846. if err := json.Unmarshal(resp, &r); err != nil {
  1847. return nil, err
  1848. }
  1849. // If we have a async client, we need to wait for the async result
  1850. if s.cs.async {
  1851. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1852. if err != nil {
  1853. if err == AsyncTimeoutErr {
  1854. return &r, err
  1855. }
  1856. return nil, err
  1857. }
  1858. if err := json.Unmarshal(b, &r); err != nil {
  1859. return nil, err
  1860. }
  1861. }
  1862. return &r, nil
  1863. }
  1864. type ReleaseDedicatedHostResponse struct {
  1865. JobID string `json:"jobid,omitempty"`
  1866. Displaytext string `json:"displaytext,omitempty"`
  1867. Success bool `json:"success,omitempty"`
  1868. }
  1869. type ListDedicatedHostsParams struct {
  1870. p map[string]interface{}
  1871. }
  1872. func (p *ListDedicatedHostsParams) toURLValues() url.Values {
  1873. u := url.Values{}
  1874. if p.p == nil {
  1875. return u
  1876. }
  1877. if v, found := p.p["account"]; found {
  1878. u.Set("account", v.(string))
  1879. }
  1880. if v, found := p.p["affinitygroupid"]; found {
  1881. u.Set("affinitygroupid", v.(string))
  1882. }
  1883. if v, found := p.p["domainid"]; found {
  1884. u.Set("domainid", v.(string))
  1885. }
  1886. if v, found := p.p["hostid"]; found {
  1887. u.Set("hostid", v.(string))
  1888. }
  1889. if v, found := p.p["keyword"]; found {
  1890. u.Set("keyword", v.(string))
  1891. }
  1892. if v, found := p.p["page"]; found {
  1893. vv := strconv.Itoa(v.(int))
  1894. u.Set("page", vv)
  1895. }
  1896. if v, found := p.p["pagesize"]; found {
  1897. vv := strconv.Itoa(v.(int))
  1898. u.Set("pagesize", vv)
  1899. }
  1900. return u
  1901. }
  1902. func (p *ListDedicatedHostsParams) SetAccount(v string) {
  1903. if p.p == nil {
  1904. p.p = make(map[string]interface{})
  1905. }
  1906. p.p["account"] = v
  1907. return
  1908. }
  1909. func (p *ListDedicatedHostsParams) SetAffinitygroupid(v string) {
  1910. if p.p == nil {
  1911. p.p = make(map[string]interface{})
  1912. }
  1913. p.p["affinitygroupid"] = v
  1914. return
  1915. }
  1916. func (p *ListDedicatedHostsParams) SetDomainid(v string) {
  1917. if p.p == nil {
  1918. p.p = make(map[string]interface{})
  1919. }
  1920. p.p["domainid"] = v
  1921. return
  1922. }
  1923. func (p *ListDedicatedHostsParams) SetHostid(v string) {
  1924. if p.p == nil {
  1925. p.p = make(map[string]interface{})
  1926. }
  1927. p.p["hostid"] = v
  1928. return
  1929. }
  1930. func (p *ListDedicatedHostsParams) SetKeyword(v string) {
  1931. if p.p == nil {
  1932. p.p = make(map[string]interface{})
  1933. }
  1934. p.p["keyword"] = v
  1935. return
  1936. }
  1937. func (p *ListDedicatedHostsParams) SetPage(v int) {
  1938. if p.p == nil {
  1939. p.p = make(map[string]interface{})
  1940. }
  1941. p.p["page"] = v
  1942. return
  1943. }
  1944. func (p *ListDedicatedHostsParams) SetPagesize(v int) {
  1945. if p.p == nil {
  1946. p.p = make(map[string]interface{})
  1947. }
  1948. p.p["pagesize"] = v
  1949. return
  1950. }
  1951. // You should always use this function to get a new ListDedicatedHostsParams instance,
  1952. // as then you are sure you have configured all required params
  1953. func (s *HostService) NewListDedicatedHostsParams() *ListDedicatedHostsParams {
  1954. p := &ListDedicatedHostsParams{}
  1955. p.p = make(map[string]interface{})
  1956. return p
  1957. }
  1958. // Lists dedicated hosts.
  1959. func (s *HostService) ListDedicatedHosts(p *ListDedicatedHostsParams) (*ListDedicatedHostsResponse, error) {
  1960. resp, err := s.cs.newRequest("listDedicatedHosts", p.toURLValues())
  1961. if err != nil {
  1962. return nil, err
  1963. }
  1964. var r ListDedicatedHostsResponse
  1965. if err := json.Unmarshal(resp, &r); err != nil {
  1966. return nil, err
  1967. }
  1968. return &r, nil
  1969. }
  1970. type ListDedicatedHostsResponse struct {
  1971. Count int `json:"count"`
  1972. DedicatedHosts []*DedicatedHost `json:"dedicatedhost"`
  1973. }
  1974. type DedicatedHost struct {
  1975. Accountid string `json:"accountid,omitempty"`
  1976. Affinitygroupid string `json:"affinitygroupid,omitempty"`
  1977. Domainid string `json:"domainid,omitempty"`
  1978. Hostid string `json:"hostid,omitempty"`
  1979. Hostname string `json:"hostname,omitempty"`
  1980. Id string `json:"id,omitempty"`
  1981. }
  1982. type AddGloboDnsHostParams struct {
  1983. p map[string]interface{}
  1984. }
  1985. func (p *AddGloboDnsHostParams) toURLValues() url.Values {
  1986. u := url.Values{}
  1987. if p.p == nil {
  1988. return u
  1989. }
  1990. if v, found := p.p["password"]; found {
  1991. u.Set("password", v.(string))
  1992. }
  1993. if v, found := p.p["physicalnetworkid"]; found {
  1994. u.Set("physicalnetworkid", v.(string))
  1995. }
  1996. if v, found := p.p["url"]; found {
  1997. u.Set("url", v.(string))
  1998. }
  1999. if v, found := p.p["username"]; found {
  2000. u.Set("username", v.(string))
  2001. }
  2002. return u
  2003. }
  2004. func (p *AddGloboDnsHostParams) SetPassword(v string) {
  2005. if p.p == nil {
  2006. p.p = make(map[string]interface{})
  2007. }
  2008. p.p["password"] = v
  2009. return
  2010. }
  2011. func (p *AddGloboDnsHostParams) SetPhysicalnetworkid(v string) {
  2012. if p.p == nil {
  2013. p.p = make(map[string]interface{})
  2014. }
  2015. p.p["physicalnetworkid"] = v
  2016. return
  2017. }
  2018. func (p *AddGloboDnsHostParams) SetUrl(v string) {
  2019. if p.p == nil {
  2020. p.p = make(map[string]interface{})
  2021. }
  2022. p.p["url"] = v
  2023. return
  2024. }
  2025. func (p *AddGloboDnsHostParams) SetUsername(v string) {
  2026. if p.p == nil {
  2027. p.p = make(map[string]interface{})
  2028. }
  2029. p.p["username"] = v
  2030. return
  2031. }
  2032. // You should always use this function to get a new AddGloboDnsHostParams instance,
  2033. // as then you are sure you have configured all required params
  2034. func (s *HostService) NewAddGloboDnsHostParams(password string, physicalnetworkid string, url string, username string) *AddGloboDnsHostParams {
  2035. p := &AddGloboDnsHostParams{}
  2036. p.p = make(map[string]interface{})
  2037. p.p["password"] = password
  2038. p.p["physicalnetworkid"] = physicalnetworkid
  2039. p.p["url"] = url
  2040. p.p["username"] = username
  2041. return p
  2042. }
  2043. // Adds the GloboDNS external host
  2044. func (s *HostService) AddGloboDnsHost(p *AddGloboDnsHostParams) (*AddGloboDnsHostResponse, error) {
  2045. resp, err := s.cs.newRequest("addGloboDnsHost", p.toURLValues())
  2046. if err != nil {
  2047. return nil, err
  2048. }
  2049. var r AddGloboDnsHostResponse
  2050. if err := json.Unmarshal(resp, &r); err != nil {
  2051. return nil, err
  2052. }
  2053. // If we have a async client, we need to wait for the async result
  2054. if s.cs.async {
  2055. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  2056. if err != nil {
  2057. if err == AsyncTimeoutErr {
  2058. return &r, err
  2059. }
  2060. return nil, err
  2061. }
  2062. if err := json.Unmarshal(b, &r); err != nil {
  2063. return nil, err
  2064. }
  2065. }
  2066. return &r, nil
  2067. }
  2068. type AddGloboDnsHostResponse struct {
  2069. JobID string `json:"jobid,omitempty"`
  2070. Displaytext string `json:"displaytext,omitempty"`
  2071. Success bool `json:"success,omitempty"`
  2072. }