AutoScaleService.go 69 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760
  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 CreateCounterParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *CreateCounterParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["name"]; found {
  33. u.Set("name", v.(string))
  34. }
  35. if v, found := p.p["source"]; found {
  36. u.Set("source", v.(string))
  37. }
  38. if v, found := p.p["value"]; found {
  39. u.Set("value", v.(string))
  40. }
  41. return u
  42. }
  43. func (p *CreateCounterParams) SetName(v string) {
  44. if p.p == nil {
  45. p.p = make(map[string]interface{})
  46. }
  47. p.p["name"] = v
  48. return
  49. }
  50. func (p *CreateCounterParams) SetSource(v string) {
  51. if p.p == nil {
  52. p.p = make(map[string]interface{})
  53. }
  54. p.p["source"] = v
  55. return
  56. }
  57. func (p *CreateCounterParams) SetValue(v string) {
  58. if p.p == nil {
  59. p.p = make(map[string]interface{})
  60. }
  61. p.p["value"] = v
  62. return
  63. }
  64. // You should always use this function to get a new CreateCounterParams instance,
  65. // as then you are sure you have configured all required params
  66. func (s *AutoScaleService) NewCreateCounterParams(name string, source string, value string) *CreateCounterParams {
  67. p := &CreateCounterParams{}
  68. p.p = make(map[string]interface{})
  69. p.p["name"] = name
  70. p.p["source"] = source
  71. p.p["value"] = value
  72. return p
  73. }
  74. // Adds metric counter
  75. func (s *AutoScaleService) CreateCounter(p *CreateCounterParams) (*CreateCounterResponse, error) {
  76. resp, err := s.cs.newRequest("createCounter", p.toURLValues())
  77. if err != nil {
  78. return nil, err
  79. }
  80. var r CreateCounterResponse
  81. if err := json.Unmarshal(resp, &r); err != nil {
  82. return nil, err
  83. }
  84. // If we have a async client, we need to wait for the async result
  85. if s.cs.async {
  86. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  87. if err != nil {
  88. if err == AsyncTimeoutErr {
  89. return &r, err
  90. }
  91. return nil, err
  92. }
  93. b, err = getRawValue(b)
  94. if err != nil {
  95. return nil, err
  96. }
  97. if err := json.Unmarshal(b, &r); err != nil {
  98. return nil, err
  99. }
  100. }
  101. return &r, nil
  102. }
  103. type CreateCounterResponse struct {
  104. JobID string `json:"jobid,omitempty"`
  105. Id string `json:"id,omitempty"`
  106. Name string `json:"name,omitempty"`
  107. Source string `json:"source,omitempty"`
  108. Value string `json:"value,omitempty"`
  109. Zoneid string `json:"zoneid,omitempty"`
  110. }
  111. type CreateConditionParams struct {
  112. p map[string]interface{}
  113. }
  114. func (p *CreateConditionParams) toURLValues() url.Values {
  115. u := url.Values{}
  116. if p.p == nil {
  117. return u
  118. }
  119. if v, found := p.p["account"]; found {
  120. u.Set("account", v.(string))
  121. }
  122. if v, found := p.p["counterid"]; found {
  123. u.Set("counterid", v.(string))
  124. }
  125. if v, found := p.p["domainid"]; found {
  126. u.Set("domainid", v.(string))
  127. }
  128. if v, found := p.p["relationaloperator"]; found {
  129. u.Set("relationaloperator", v.(string))
  130. }
  131. if v, found := p.p["threshold"]; found {
  132. vv := strconv.FormatInt(v.(int64), 10)
  133. u.Set("threshold", vv)
  134. }
  135. return u
  136. }
  137. func (p *CreateConditionParams) SetAccount(v string) {
  138. if p.p == nil {
  139. p.p = make(map[string]interface{})
  140. }
  141. p.p["account"] = v
  142. return
  143. }
  144. func (p *CreateConditionParams) SetCounterid(v string) {
  145. if p.p == nil {
  146. p.p = make(map[string]interface{})
  147. }
  148. p.p["counterid"] = v
  149. return
  150. }
  151. func (p *CreateConditionParams) SetDomainid(v string) {
  152. if p.p == nil {
  153. p.p = make(map[string]interface{})
  154. }
  155. p.p["domainid"] = v
  156. return
  157. }
  158. func (p *CreateConditionParams) SetRelationaloperator(v string) {
  159. if p.p == nil {
  160. p.p = make(map[string]interface{})
  161. }
  162. p.p["relationaloperator"] = v
  163. return
  164. }
  165. func (p *CreateConditionParams) SetThreshold(v int64) {
  166. if p.p == nil {
  167. p.p = make(map[string]interface{})
  168. }
  169. p.p["threshold"] = v
  170. return
  171. }
  172. // You should always use this function to get a new CreateConditionParams instance,
  173. // as then you are sure you have configured all required params
  174. func (s *AutoScaleService) NewCreateConditionParams(counterid string, relationaloperator string, threshold int64) *CreateConditionParams {
  175. p := &CreateConditionParams{}
  176. p.p = make(map[string]interface{})
  177. p.p["counterid"] = counterid
  178. p.p["relationaloperator"] = relationaloperator
  179. p.p["threshold"] = threshold
  180. return p
  181. }
  182. // Creates a condition
  183. func (s *AutoScaleService) CreateCondition(p *CreateConditionParams) (*CreateConditionResponse, error) {
  184. resp, err := s.cs.newRequest("createCondition", p.toURLValues())
  185. if err != nil {
  186. return nil, err
  187. }
  188. var r CreateConditionResponse
  189. if err := json.Unmarshal(resp, &r); err != nil {
  190. return nil, err
  191. }
  192. // If we have a async client, we need to wait for the async result
  193. if s.cs.async {
  194. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  195. if err != nil {
  196. if err == AsyncTimeoutErr {
  197. return &r, err
  198. }
  199. return nil, err
  200. }
  201. b, err = getRawValue(b)
  202. if err != nil {
  203. return nil, err
  204. }
  205. if err := json.Unmarshal(b, &r); err != nil {
  206. return nil, err
  207. }
  208. }
  209. return &r, nil
  210. }
  211. type CreateConditionResponse struct {
  212. JobID string `json:"jobid,omitempty"`
  213. Account string `json:"account,omitempty"`
  214. Counter []string `json:"counter,omitempty"`
  215. Domain string `json:"domain,omitempty"`
  216. Domainid string `json:"domainid,omitempty"`
  217. Id string `json:"id,omitempty"`
  218. Project string `json:"project,omitempty"`
  219. Projectid string `json:"projectid,omitempty"`
  220. Relationaloperator string `json:"relationaloperator,omitempty"`
  221. Threshold int64 `json:"threshold,omitempty"`
  222. Zoneid string `json:"zoneid,omitempty"`
  223. }
  224. type CreateAutoScalePolicyParams struct {
  225. p map[string]interface{}
  226. }
  227. func (p *CreateAutoScalePolicyParams) toURLValues() url.Values {
  228. u := url.Values{}
  229. if p.p == nil {
  230. return u
  231. }
  232. if v, found := p.p["action"]; found {
  233. u.Set("action", v.(string))
  234. }
  235. if v, found := p.p["conditionids"]; found {
  236. vv := strings.Join(v.([]string), ",")
  237. u.Set("conditionids", vv)
  238. }
  239. if v, found := p.p["duration"]; found {
  240. vv := strconv.Itoa(v.(int))
  241. u.Set("duration", vv)
  242. }
  243. if v, found := p.p["quiettime"]; found {
  244. vv := strconv.Itoa(v.(int))
  245. u.Set("quiettime", vv)
  246. }
  247. return u
  248. }
  249. func (p *CreateAutoScalePolicyParams) SetAction(v string) {
  250. if p.p == nil {
  251. p.p = make(map[string]interface{})
  252. }
  253. p.p["action"] = v
  254. return
  255. }
  256. func (p *CreateAutoScalePolicyParams) SetConditionids(v []string) {
  257. if p.p == nil {
  258. p.p = make(map[string]interface{})
  259. }
  260. p.p["conditionids"] = v
  261. return
  262. }
  263. func (p *CreateAutoScalePolicyParams) SetDuration(v int) {
  264. if p.p == nil {
  265. p.p = make(map[string]interface{})
  266. }
  267. p.p["duration"] = v
  268. return
  269. }
  270. func (p *CreateAutoScalePolicyParams) SetQuiettime(v int) {
  271. if p.p == nil {
  272. p.p = make(map[string]interface{})
  273. }
  274. p.p["quiettime"] = v
  275. return
  276. }
  277. // You should always use this function to get a new CreateAutoScalePolicyParams instance,
  278. // as then you are sure you have configured all required params
  279. func (s *AutoScaleService) NewCreateAutoScalePolicyParams(action string, conditionids []string, duration int) *CreateAutoScalePolicyParams {
  280. p := &CreateAutoScalePolicyParams{}
  281. p.p = make(map[string]interface{})
  282. p.p["action"] = action
  283. p.p["conditionids"] = conditionids
  284. p.p["duration"] = duration
  285. return p
  286. }
  287. // Creates an autoscale policy for a provision or deprovision action, the action is taken when the all the conditions evaluates to true for the specified duration. The policy is in effect once it is attached to a autscale vm group.
  288. func (s *AutoScaleService) CreateAutoScalePolicy(p *CreateAutoScalePolicyParams) (*CreateAutoScalePolicyResponse, error) {
  289. resp, err := s.cs.newRequest("createAutoScalePolicy", p.toURLValues())
  290. if err != nil {
  291. return nil, err
  292. }
  293. var r CreateAutoScalePolicyResponse
  294. if err := json.Unmarshal(resp, &r); err != nil {
  295. return nil, err
  296. }
  297. // If we have a async client, we need to wait for the async result
  298. if s.cs.async {
  299. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  300. if err != nil {
  301. if err == AsyncTimeoutErr {
  302. return &r, err
  303. }
  304. return nil, err
  305. }
  306. b, err = getRawValue(b)
  307. if err != nil {
  308. return nil, err
  309. }
  310. if err := json.Unmarshal(b, &r); err != nil {
  311. return nil, err
  312. }
  313. }
  314. return &r, nil
  315. }
  316. type CreateAutoScalePolicyResponse struct {
  317. JobID string `json:"jobid,omitempty"`
  318. Account string `json:"account,omitempty"`
  319. Action string `json:"action,omitempty"`
  320. Conditions []string `json:"conditions,omitempty"`
  321. Domain string `json:"domain,omitempty"`
  322. Domainid string `json:"domainid,omitempty"`
  323. Duration int `json:"duration,omitempty"`
  324. Id string `json:"id,omitempty"`
  325. Project string `json:"project,omitempty"`
  326. Projectid string `json:"projectid,omitempty"`
  327. Quiettime int `json:"quiettime,omitempty"`
  328. }
  329. type CreateAutoScaleVmProfileParams struct {
  330. p map[string]interface{}
  331. }
  332. func (p *CreateAutoScaleVmProfileParams) toURLValues() url.Values {
  333. u := url.Values{}
  334. if p.p == nil {
  335. return u
  336. }
  337. if v, found := p.p["autoscaleuserid"]; found {
  338. u.Set("autoscaleuserid", v.(string))
  339. }
  340. if v, found := p.p["counterparam"]; found {
  341. i := 0
  342. for k, vv := range v.(map[string]string) {
  343. u.Set(fmt.Sprintf("counterparam[%d].key", i), k)
  344. u.Set(fmt.Sprintf("counterparam[%d].value", i), vv)
  345. i++
  346. }
  347. }
  348. if v, found := p.p["destroyvmgraceperiod"]; found {
  349. vv := strconv.Itoa(v.(int))
  350. u.Set("destroyvmgraceperiod", vv)
  351. }
  352. if v, found := p.p["fordisplay"]; found {
  353. vv := strconv.FormatBool(v.(bool))
  354. u.Set("fordisplay", vv)
  355. }
  356. if v, found := p.p["otherdeployparams"]; found {
  357. u.Set("otherdeployparams", v.(string))
  358. }
  359. if v, found := p.p["serviceofferingid"]; found {
  360. u.Set("serviceofferingid", v.(string))
  361. }
  362. if v, found := p.p["templateid"]; found {
  363. u.Set("templateid", v.(string))
  364. }
  365. if v, found := p.p["zoneid"]; found {
  366. u.Set("zoneid", v.(string))
  367. }
  368. return u
  369. }
  370. func (p *CreateAutoScaleVmProfileParams) SetAutoscaleuserid(v string) {
  371. if p.p == nil {
  372. p.p = make(map[string]interface{})
  373. }
  374. p.p["autoscaleuserid"] = v
  375. return
  376. }
  377. func (p *CreateAutoScaleVmProfileParams) SetCounterparam(v map[string]string) {
  378. if p.p == nil {
  379. p.p = make(map[string]interface{})
  380. }
  381. p.p["counterparam"] = v
  382. return
  383. }
  384. func (p *CreateAutoScaleVmProfileParams) SetDestroyvmgraceperiod(v int) {
  385. if p.p == nil {
  386. p.p = make(map[string]interface{})
  387. }
  388. p.p["destroyvmgraceperiod"] = v
  389. return
  390. }
  391. func (p *CreateAutoScaleVmProfileParams) SetFordisplay(v bool) {
  392. if p.p == nil {
  393. p.p = make(map[string]interface{})
  394. }
  395. p.p["fordisplay"] = v
  396. return
  397. }
  398. func (p *CreateAutoScaleVmProfileParams) SetOtherdeployparams(v string) {
  399. if p.p == nil {
  400. p.p = make(map[string]interface{})
  401. }
  402. p.p["otherdeployparams"] = v
  403. return
  404. }
  405. func (p *CreateAutoScaleVmProfileParams) SetServiceofferingid(v string) {
  406. if p.p == nil {
  407. p.p = make(map[string]interface{})
  408. }
  409. p.p["serviceofferingid"] = v
  410. return
  411. }
  412. func (p *CreateAutoScaleVmProfileParams) SetTemplateid(v string) {
  413. if p.p == nil {
  414. p.p = make(map[string]interface{})
  415. }
  416. p.p["templateid"] = v
  417. return
  418. }
  419. func (p *CreateAutoScaleVmProfileParams) SetZoneid(v string) {
  420. if p.p == nil {
  421. p.p = make(map[string]interface{})
  422. }
  423. p.p["zoneid"] = v
  424. return
  425. }
  426. // You should always use this function to get a new CreateAutoScaleVmProfileParams instance,
  427. // as then you are sure you have configured all required params
  428. func (s *AutoScaleService) NewCreateAutoScaleVmProfileParams(serviceofferingid string, templateid string, zoneid string) *CreateAutoScaleVmProfileParams {
  429. p := &CreateAutoScaleVmProfileParams{}
  430. p.p = make(map[string]interface{})
  431. p.p["serviceofferingid"] = serviceofferingid
  432. p.p["templateid"] = templateid
  433. p.p["zoneid"] = zoneid
  434. return p
  435. }
  436. // Creates a profile that contains information about the virtual machine which will be provisioned automatically by autoscale feature.
  437. func (s *AutoScaleService) CreateAutoScaleVmProfile(p *CreateAutoScaleVmProfileParams) (*CreateAutoScaleVmProfileResponse, error) {
  438. resp, err := s.cs.newRequest("createAutoScaleVmProfile", p.toURLValues())
  439. if err != nil {
  440. return nil, err
  441. }
  442. var r CreateAutoScaleVmProfileResponse
  443. if err := json.Unmarshal(resp, &r); err != nil {
  444. return nil, err
  445. }
  446. // If we have a async client, we need to wait for the async result
  447. if s.cs.async {
  448. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  449. if err != nil {
  450. if err == AsyncTimeoutErr {
  451. return &r, err
  452. }
  453. return nil, err
  454. }
  455. b, err = getRawValue(b)
  456. if err != nil {
  457. return nil, err
  458. }
  459. if err := json.Unmarshal(b, &r); err != nil {
  460. return nil, err
  461. }
  462. }
  463. return &r, nil
  464. }
  465. type CreateAutoScaleVmProfileResponse struct {
  466. JobID string `json:"jobid,omitempty"`
  467. Account string `json:"account,omitempty"`
  468. Autoscaleuserid string `json:"autoscaleuserid,omitempty"`
  469. Destroyvmgraceperiod int `json:"destroyvmgraceperiod,omitempty"`
  470. Domain string `json:"domain,omitempty"`
  471. Domainid string `json:"domainid,omitempty"`
  472. Fordisplay bool `json:"fordisplay,omitempty"`
  473. Id string `json:"id,omitempty"`
  474. Otherdeployparams string `json:"otherdeployparams,omitempty"`
  475. Project string `json:"project,omitempty"`
  476. Projectid string `json:"projectid,omitempty"`
  477. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  478. Templateid string `json:"templateid,omitempty"`
  479. Zoneid string `json:"zoneid,omitempty"`
  480. }
  481. type CreateAutoScaleVmGroupParams struct {
  482. p map[string]interface{}
  483. }
  484. func (p *CreateAutoScaleVmGroupParams) toURLValues() url.Values {
  485. u := url.Values{}
  486. if p.p == nil {
  487. return u
  488. }
  489. if v, found := p.p["fordisplay"]; found {
  490. vv := strconv.FormatBool(v.(bool))
  491. u.Set("fordisplay", vv)
  492. }
  493. if v, found := p.p["interval"]; found {
  494. vv := strconv.Itoa(v.(int))
  495. u.Set("interval", vv)
  496. }
  497. if v, found := p.p["lbruleid"]; found {
  498. u.Set("lbruleid", v.(string))
  499. }
  500. if v, found := p.p["maxmembers"]; found {
  501. vv := strconv.Itoa(v.(int))
  502. u.Set("maxmembers", vv)
  503. }
  504. if v, found := p.p["minmembers"]; found {
  505. vv := strconv.Itoa(v.(int))
  506. u.Set("minmembers", vv)
  507. }
  508. if v, found := p.p["scaledownpolicyids"]; found {
  509. vv := strings.Join(v.([]string), ",")
  510. u.Set("scaledownpolicyids", vv)
  511. }
  512. if v, found := p.p["scaleuppolicyids"]; found {
  513. vv := strings.Join(v.([]string), ",")
  514. u.Set("scaleuppolicyids", vv)
  515. }
  516. if v, found := p.p["vmprofileid"]; found {
  517. u.Set("vmprofileid", v.(string))
  518. }
  519. return u
  520. }
  521. func (p *CreateAutoScaleVmGroupParams) SetFordisplay(v bool) {
  522. if p.p == nil {
  523. p.p = make(map[string]interface{})
  524. }
  525. p.p["fordisplay"] = v
  526. return
  527. }
  528. func (p *CreateAutoScaleVmGroupParams) SetInterval(v int) {
  529. if p.p == nil {
  530. p.p = make(map[string]interface{})
  531. }
  532. p.p["interval"] = v
  533. return
  534. }
  535. func (p *CreateAutoScaleVmGroupParams) SetLbruleid(v string) {
  536. if p.p == nil {
  537. p.p = make(map[string]interface{})
  538. }
  539. p.p["lbruleid"] = v
  540. return
  541. }
  542. func (p *CreateAutoScaleVmGroupParams) SetMaxmembers(v int) {
  543. if p.p == nil {
  544. p.p = make(map[string]interface{})
  545. }
  546. p.p["maxmembers"] = v
  547. return
  548. }
  549. func (p *CreateAutoScaleVmGroupParams) SetMinmembers(v int) {
  550. if p.p == nil {
  551. p.p = make(map[string]interface{})
  552. }
  553. p.p["minmembers"] = v
  554. return
  555. }
  556. func (p *CreateAutoScaleVmGroupParams) SetScaledownpolicyids(v []string) {
  557. if p.p == nil {
  558. p.p = make(map[string]interface{})
  559. }
  560. p.p["scaledownpolicyids"] = v
  561. return
  562. }
  563. func (p *CreateAutoScaleVmGroupParams) SetScaleuppolicyids(v []string) {
  564. if p.p == nil {
  565. p.p = make(map[string]interface{})
  566. }
  567. p.p["scaleuppolicyids"] = v
  568. return
  569. }
  570. func (p *CreateAutoScaleVmGroupParams) SetVmprofileid(v string) {
  571. if p.p == nil {
  572. p.p = make(map[string]interface{})
  573. }
  574. p.p["vmprofileid"] = v
  575. return
  576. }
  577. // You should always use this function to get a new CreateAutoScaleVmGroupParams instance,
  578. // as then you are sure you have configured all required params
  579. func (s *AutoScaleService) NewCreateAutoScaleVmGroupParams(lbruleid string, maxmembers int, minmembers int, scaledownpolicyids []string, scaleuppolicyids []string, vmprofileid string) *CreateAutoScaleVmGroupParams {
  580. p := &CreateAutoScaleVmGroupParams{}
  581. p.p = make(map[string]interface{})
  582. p.p["lbruleid"] = lbruleid
  583. p.p["maxmembers"] = maxmembers
  584. p.p["minmembers"] = minmembers
  585. p.p["scaledownpolicyids"] = scaledownpolicyids
  586. p.p["scaleuppolicyids"] = scaleuppolicyids
  587. p.p["vmprofileid"] = vmprofileid
  588. return p
  589. }
  590. // Creates and automatically starts a virtual machine based on a service offering, disk offering, and template.
  591. func (s *AutoScaleService) CreateAutoScaleVmGroup(p *CreateAutoScaleVmGroupParams) (*CreateAutoScaleVmGroupResponse, error) {
  592. resp, err := s.cs.newRequest("createAutoScaleVmGroup", p.toURLValues())
  593. if err != nil {
  594. return nil, err
  595. }
  596. var r CreateAutoScaleVmGroupResponse
  597. if err := json.Unmarshal(resp, &r); err != nil {
  598. return nil, err
  599. }
  600. // If we have a async client, we need to wait for the async result
  601. if s.cs.async {
  602. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  603. if err != nil {
  604. if err == AsyncTimeoutErr {
  605. return &r, err
  606. }
  607. return nil, err
  608. }
  609. b, err = getRawValue(b)
  610. if err != nil {
  611. return nil, err
  612. }
  613. if err := json.Unmarshal(b, &r); err != nil {
  614. return nil, err
  615. }
  616. }
  617. return &r, nil
  618. }
  619. type CreateAutoScaleVmGroupResponse struct {
  620. JobID string `json:"jobid,omitempty"`
  621. Account string `json:"account,omitempty"`
  622. Domain string `json:"domain,omitempty"`
  623. Domainid string `json:"domainid,omitempty"`
  624. Fordisplay bool `json:"fordisplay,omitempty"`
  625. Id string `json:"id,omitempty"`
  626. Interval int `json:"interval,omitempty"`
  627. Lbruleid string `json:"lbruleid,omitempty"`
  628. Maxmembers int `json:"maxmembers,omitempty"`
  629. Minmembers int `json:"minmembers,omitempty"`
  630. Project string `json:"project,omitempty"`
  631. Projectid string `json:"projectid,omitempty"`
  632. Scaledownpolicies []string `json:"scaledownpolicies,omitempty"`
  633. Scaleuppolicies []string `json:"scaleuppolicies,omitempty"`
  634. State string `json:"state,omitempty"`
  635. Vmprofileid string `json:"vmprofileid,omitempty"`
  636. }
  637. type DeleteCounterParams struct {
  638. p map[string]interface{}
  639. }
  640. func (p *DeleteCounterParams) toURLValues() url.Values {
  641. u := url.Values{}
  642. if p.p == nil {
  643. return u
  644. }
  645. if v, found := p.p["id"]; found {
  646. u.Set("id", v.(string))
  647. }
  648. return u
  649. }
  650. func (p *DeleteCounterParams) SetId(v string) {
  651. if p.p == nil {
  652. p.p = make(map[string]interface{})
  653. }
  654. p.p["id"] = v
  655. return
  656. }
  657. // You should always use this function to get a new DeleteCounterParams instance,
  658. // as then you are sure you have configured all required params
  659. func (s *AutoScaleService) NewDeleteCounterParams(id string) *DeleteCounterParams {
  660. p := &DeleteCounterParams{}
  661. p.p = make(map[string]interface{})
  662. p.p["id"] = id
  663. return p
  664. }
  665. // Deletes a counter
  666. func (s *AutoScaleService) DeleteCounter(p *DeleteCounterParams) (*DeleteCounterResponse, error) {
  667. resp, err := s.cs.newRequest("deleteCounter", p.toURLValues())
  668. if err != nil {
  669. return nil, err
  670. }
  671. var r DeleteCounterResponse
  672. if err := json.Unmarshal(resp, &r); err != nil {
  673. return nil, err
  674. }
  675. // If we have a async client, we need to wait for the async result
  676. if s.cs.async {
  677. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  678. if err != nil {
  679. if err == AsyncTimeoutErr {
  680. return &r, err
  681. }
  682. return nil, err
  683. }
  684. if err := json.Unmarshal(b, &r); err != nil {
  685. return nil, err
  686. }
  687. }
  688. return &r, nil
  689. }
  690. type DeleteCounterResponse struct {
  691. JobID string `json:"jobid,omitempty"`
  692. Displaytext string `json:"displaytext,omitempty"`
  693. Success bool `json:"success,omitempty"`
  694. }
  695. type DeleteConditionParams struct {
  696. p map[string]interface{}
  697. }
  698. func (p *DeleteConditionParams) toURLValues() url.Values {
  699. u := url.Values{}
  700. if p.p == nil {
  701. return u
  702. }
  703. if v, found := p.p["id"]; found {
  704. u.Set("id", v.(string))
  705. }
  706. return u
  707. }
  708. func (p *DeleteConditionParams) SetId(v string) {
  709. if p.p == nil {
  710. p.p = make(map[string]interface{})
  711. }
  712. p.p["id"] = v
  713. return
  714. }
  715. // You should always use this function to get a new DeleteConditionParams instance,
  716. // as then you are sure you have configured all required params
  717. func (s *AutoScaleService) NewDeleteConditionParams(id string) *DeleteConditionParams {
  718. p := &DeleteConditionParams{}
  719. p.p = make(map[string]interface{})
  720. p.p["id"] = id
  721. return p
  722. }
  723. // Removes a condition
  724. func (s *AutoScaleService) DeleteCondition(p *DeleteConditionParams) (*DeleteConditionResponse, error) {
  725. resp, err := s.cs.newRequest("deleteCondition", p.toURLValues())
  726. if err != nil {
  727. return nil, err
  728. }
  729. var r DeleteConditionResponse
  730. if err := json.Unmarshal(resp, &r); err != nil {
  731. return nil, err
  732. }
  733. // If we have a async client, we need to wait for the async result
  734. if s.cs.async {
  735. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  736. if err != nil {
  737. if err == AsyncTimeoutErr {
  738. return &r, err
  739. }
  740. return nil, err
  741. }
  742. if err := json.Unmarshal(b, &r); err != nil {
  743. return nil, err
  744. }
  745. }
  746. return &r, nil
  747. }
  748. type DeleteConditionResponse struct {
  749. JobID string `json:"jobid,omitempty"`
  750. Displaytext string `json:"displaytext,omitempty"`
  751. Success bool `json:"success,omitempty"`
  752. }
  753. type DeleteAutoScalePolicyParams struct {
  754. p map[string]interface{}
  755. }
  756. func (p *DeleteAutoScalePolicyParams) toURLValues() url.Values {
  757. u := url.Values{}
  758. if p.p == nil {
  759. return u
  760. }
  761. if v, found := p.p["id"]; found {
  762. u.Set("id", v.(string))
  763. }
  764. return u
  765. }
  766. func (p *DeleteAutoScalePolicyParams) SetId(v string) {
  767. if p.p == nil {
  768. p.p = make(map[string]interface{})
  769. }
  770. p.p["id"] = v
  771. return
  772. }
  773. // You should always use this function to get a new DeleteAutoScalePolicyParams instance,
  774. // as then you are sure you have configured all required params
  775. func (s *AutoScaleService) NewDeleteAutoScalePolicyParams(id string) *DeleteAutoScalePolicyParams {
  776. p := &DeleteAutoScalePolicyParams{}
  777. p.p = make(map[string]interface{})
  778. p.p["id"] = id
  779. return p
  780. }
  781. // Deletes a autoscale policy.
  782. func (s *AutoScaleService) DeleteAutoScalePolicy(p *DeleteAutoScalePolicyParams) (*DeleteAutoScalePolicyResponse, error) {
  783. resp, err := s.cs.newRequest("deleteAutoScalePolicy", p.toURLValues())
  784. if err != nil {
  785. return nil, err
  786. }
  787. var r DeleteAutoScalePolicyResponse
  788. if err := json.Unmarshal(resp, &r); err != nil {
  789. return nil, err
  790. }
  791. // If we have a async client, we need to wait for the async result
  792. if s.cs.async {
  793. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  794. if err != nil {
  795. if err == AsyncTimeoutErr {
  796. return &r, err
  797. }
  798. return nil, err
  799. }
  800. if err := json.Unmarshal(b, &r); err != nil {
  801. return nil, err
  802. }
  803. }
  804. return &r, nil
  805. }
  806. type DeleteAutoScalePolicyResponse struct {
  807. JobID string `json:"jobid,omitempty"`
  808. Displaytext string `json:"displaytext,omitempty"`
  809. Success bool `json:"success,omitempty"`
  810. }
  811. type DeleteAutoScaleVmProfileParams struct {
  812. p map[string]interface{}
  813. }
  814. func (p *DeleteAutoScaleVmProfileParams) toURLValues() url.Values {
  815. u := url.Values{}
  816. if p.p == nil {
  817. return u
  818. }
  819. if v, found := p.p["id"]; found {
  820. u.Set("id", v.(string))
  821. }
  822. return u
  823. }
  824. func (p *DeleteAutoScaleVmProfileParams) SetId(v string) {
  825. if p.p == nil {
  826. p.p = make(map[string]interface{})
  827. }
  828. p.p["id"] = v
  829. return
  830. }
  831. // You should always use this function to get a new DeleteAutoScaleVmProfileParams instance,
  832. // as then you are sure you have configured all required params
  833. func (s *AutoScaleService) NewDeleteAutoScaleVmProfileParams(id string) *DeleteAutoScaleVmProfileParams {
  834. p := &DeleteAutoScaleVmProfileParams{}
  835. p.p = make(map[string]interface{})
  836. p.p["id"] = id
  837. return p
  838. }
  839. // Deletes a autoscale vm profile.
  840. func (s *AutoScaleService) DeleteAutoScaleVmProfile(p *DeleteAutoScaleVmProfileParams) (*DeleteAutoScaleVmProfileResponse, error) {
  841. resp, err := s.cs.newRequest("deleteAutoScaleVmProfile", p.toURLValues())
  842. if err != nil {
  843. return nil, err
  844. }
  845. var r DeleteAutoScaleVmProfileResponse
  846. if err := json.Unmarshal(resp, &r); err != nil {
  847. return nil, err
  848. }
  849. // If we have a async client, we need to wait for the async result
  850. if s.cs.async {
  851. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  852. if err != nil {
  853. if err == AsyncTimeoutErr {
  854. return &r, err
  855. }
  856. return nil, err
  857. }
  858. if err := json.Unmarshal(b, &r); err != nil {
  859. return nil, err
  860. }
  861. }
  862. return &r, nil
  863. }
  864. type DeleteAutoScaleVmProfileResponse struct {
  865. JobID string `json:"jobid,omitempty"`
  866. Displaytext string `json:"displaytext,omitempty"`
  867. Success bool `json:"success,omitempty"`
  868. }
  869. type DeleteAutoScaleVmGroupParams struct {
  870. p map[string]interface{}
  871. }
  872. func (p *DeleteAutoScaleVmGroupParams) toURLValues() url.Values {
  873. u := url.Values{}
  874. if p.p == nil {
  875. return u
  876. }
  877. if v, found := p.p["id"]; found {
  878. u.Set("id", v.(string))
  879. }
  880. return u
  881. }
  882. func (p *DeleteAutoScaleVmGroupParams) SetId(v string) {
  883. if p.p == nil {
  884. p.p = make(map[string]interface{})
  885. }
  886. p.p["id"] = v
  887. return
  888. }
  889. // You should always use this function to get a new DeleteAutoScaleVmGroupParams instance,
  890. // as then you are sure you have configured all required params
  891. func (s *AutoScaleService) NewDeleteAutoScaleVmGroupParams(id string) *DeleteAutoScaleVmGroupParams {
  892. p := &DeleteAutoScaleVmGroupParams{}
  893. p.p = make(map[string]interface{})
  894. p.p["id"] = id
  895. return p
  896. }
  897. // Deletes a autoscale vm group.
  898. func (s *AutoScaleService) DeleteAutoScaleVmGroup(p *DeleteAutoScaleVmGroupParams) (*DeleteAutoScaleVmGroupResponse, error) {
  899. resp, err := s.cs.newRequest("deleteAutoScaleVmGroup", p.toURLValues())
  900. if err != nil {
  901. return nil, err
  902. }
  903. var r DeleteAutoScaleVmGroupResponse
  904. if err := json.Unmarshal(resp, &r); err != nil {
  905. return nil, err
  906. }
  907. // If we have a async client, we need to wait for the async result
  908. if s.cs.async {
  909. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  910. if err != nil {
  911. if err == AsyncTimeoutErr {
  912. return &r, err
  913. }
  914. return nil, err
  915. }
  916. if err := json.Unmarshal(b, &r); err != nil {
  917. return nil, err
  918. }
  919. }
  920. return &r, nil
  921. }
  922. type DeleteAutoScaleVmGroupResponse struct {
  923. JobID string `json:"jobid,omitempty"`
  924. Displaytext string `json:"displaytext,omitempty"`
  925. Success bool `json:"success,omitempty"`
  926. }
  927. type ListCountersParams struct {
  928. p map[string]interface{}
  929. }
  930. func (p *ListCountersParams) toURLValues() url.Values {
  931. u := url.Values{}
  932. if p.p == nil {
  933. return u
  934. }
  935. if v, found := p.p["id"]; found {
  936. u.Set("id", v.(string))
  937. }
  938. if v, found := p.p["keyword"]; found {
  939. u.Set("keyword", v.(string))
  940. }
  941. if v, found := p.p["name"]; found {
  942. u.Set("name", v.(string))
  943. }
  944. if v, found := p.p["page"]; found {
  945. vv := strconv.Itoa(v.(int))
  946. u.Set("page", vv)
  947. }
  948. if v, found := p.p["pagesize"]; found {
  949. vv := strconv.Itoa(v.(int))
  950. u.Set("pagesize", vv)
  951. }
  952. if v, found := p.p["source"]; found {
  953. u.Set("source", v.(string))
  954. }
  955. return u
  956. }
  957. func (p *ListCountersParams) SetId(v string) {
  958. if p.p == nil {
  959. p.p = make(map[string]interface{})
  960. }
  961. p.p["id"] = v
  962. return
  963. }
  964. func (p *ListCountersParams) SetKeyword(v string) {
  965. if p.p == nil {
  966. p.p = make(map[string]interface{})
  967. }
  968. p.p["keyword"] = v
  969. return
  970. }
  971. func (p *ListCountersParams) SetName(v string) {
  972. if p.p == nil {
  973. p.p = make(map[string]interface{})
  974. }
  975. p.p["name"] = v
  976. return
  977. }
  978. func (p *ListCountersParams) SetPage(v int) {
  979. if p.p == nil {
  980. p.p = make(map[string]interface{})
  981. }
  982. p.p["page"] = v
  983. return
  984. }
  985. func (p *ListCountersParams) SetPagesize(v int) {
  986. if p.p == nil {
  987. p.p = make(map[string]interface{})
  988. }
  989. p.p["pagesize"] = v
  990. return
  991. }
  992. func (p *ListCountersParams) SetSource(v string) {
  993. if p.p == nil {
  994. p.p = make(map[string]interface{})
  995. }
  996. p.p["source"] = v
  997. return
  998. }
  999. // You should always use this function to get a new ListCountersParams instance,
  1000. // as then you are sure you have configured all required params
  1001. func (s *AutoScaleService) NewListCountersParams() *ListCountersParams {
  1002. p := &ListCountersParams{}
  1003. p.p = make(map[string]interface{})
  1004. return p
  1005. }
  1006. // This is a courtesy helper function, which in some cases may not work as expected!
  1007. func (s *AutoScaleService) GetCounterID(name string, opts ...OptionFunc) (string, int, error) {
  1008. p := &ListCountersParams{}
  1009. p.p = make(map[string]interface{})
  1010. p.p["name"] = name
  1011. for _, fn := range opts {
  1012. if err := fn(s.cs, p); err != nil {
  1013. return "", -1, err
  1014. }
  1015. }
  1016. l, err := s.ListCounters(p)
  1017. if err != nil {
  1018. return "", -1, err
  1019. }
  1020. if l.Count == 0 {
  1021. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  1022. }
  1023. if l.Count == 1 {
  1024. return l.Counters[0].Id, l.Count, nil
  1025. }
  1026. if l.Count > 1 {
  1027. for _, v := range l.Counters {
  1028. if v.Name == name {
  1029. return v.Id, l.Count, nil
  1030. }
  1031. }
  1032. }
  1033. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  1034. }
  1035. // This is a courtesy helper function, which in some cases may not work as expected!
  1036. func (s *AutoScaleService) GetCounterByName(name string, opts ...OptionFunc) (*Counter, int, error) {
  1037. id, count, err := s.GetCounterID(name, opts...)
  1038. if err != nil {
  1039. return nil, count, err
  1040. }
  1041. r, count, err := s.GetCounterByID(id, opts...)
  1042. if err != nil {
  1043. return nil, count, err
  1044. }
  1045. return r, count, nil
  1046. }
  1047. // This is a courtesy helper function, which in some cases may not work as expected!
  1048. func (s *AutoScaleService) GetCounterByID(id string, opts ...OptionFunc) (*Counter, int, error) {
  1049. p := &ListCountersParams{}
  1050. p.p = make(map[string]interface{})
  1051. p.p["id"] = id
  1052. for _, fn := range opts {
  1053. if err := fn(s.cs, p); err != nil {
  1054. return nil, -1, err
  1055. }
  1056. }
  1057. l, err := s.ListCounters(p)
  1058. if err != nil {
  1059. if strings.Contains(err.Error(), fmt.Sprintf(
  1060. "Invalid parameter id value=%s due to incorrect long value format, "+
  1061. "or entity does not exist", id)) {
  1062. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1063. }
  1064. return nil, -1, err
  1065. }
  1066. if l.Count == 0 {
  1067. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1068. }
  1069. if l.Count == 1 {
  1070. return l.Counters[0], l.Count, nil
  1071. }
  1072. return nil, l.Count, fmt.Errorf("There is more then one result for Counter UUID: %s!", id)
  1073. }
  1074. // List the counters
  1075. func (s *AutoScaleService) ListCounters(p *ListCountersParams) (*ListCountersResponse, error) {
  1076. resp, err := s.cs.newRequest("listCounters", p.toURLValues())
  1077. if err != nil {
  1078. return nil, err
  1079. }
  1080. var r ListCountersResponse
  1081. if err := json.Unmarshal(resp, &r); err != nil {
  1082. return nil, err
  1083. }
  1084. return &r, nil
  1085. }
  1086. type ListCountersResponse struct {
  1087. Count int `json:"count"`
  1088. Counters []*Counter `json:"counter"`
  1089. }
  1090. type Counter struct {
  1091. Id string `json:"id,omitempty"`
  1092. Name string `json:"name,omitempty"`
  1093. Source string `json:"source,omitempty"`
  1094. Value string `json:"value,omitempty"`
  1095. Zoneid string `json:"zoneid,omitempty"`
  1096. }
  1097. type ListConditionsParams struct {
  1098. p map[string]interface{}
  1099. }
  1100. func (p *ListConditionsParams) toURLValues() url.Values {
  1101. u := url.Values{}
  1102. if p.p == nil {
  1103. return u
  1104. }
  1105. if v, found := p.p["account"]; found {
  1106. u.Set("account", v.(string))
  1107. }
  1108. if v, found := p.p["counterid"]; found {
  1109. u.Set("counterid", v.(string))
  1110. }
  1111. if v, found := p.p["domainid"]; found {
  1112. u.Set("domainid", v.(string))
  1113. }
  1114. if v, found := p.p["id"]; found {
  1115. u.Set("id", v.(string))
  1116. }
  1117. if v, found := p.p["isrecursive"]; found {
  1118. vv := strconv.FormatBool(v.(bool))
  1119. u.Set("isrecursive", vv)
  1120. }
  1121. if v, found := p.p["keyword"]; found {
  1122. u.Set("keyword", v.(string))
  1123. }
  1124. if v, found := p.p["listall"]; found {
  1125. vv := strconv.FormatBool(v.(bool))
  1126. u.Set("listall", vv)
  1127. }
  1128. if v, found := p.p["page"]; found {
  1129. vv := strconv.Itoa(v.(int))
  1130. u.Set("page", vv)
  1131. }
  1132. if v, found := p.p["pagesize"]; found {
  1133. vv := strconv.Itoa(v.(int))
  1134. u.Set("pagesize", vv)
  1135. }
  1136. if v, found := p.p["policyid"]; found {
  1137. u.Set("policyid", v.(string))
  1138. }
  1139. return u
  1140. }
  1141. func (p *ListConditionsParams) SetAccount(v string) {
  1142. if p.p == nil {
  1143. p.p = make(map[string]interface{})
  1144. }
  1145. p.p["account"] = v
  1146. return
  1147. }
  1148. func (p *ListConditionsParams) SetCounterid(v string) {
  1149. if p.p == nil {
  1150. p.p = make(map[string]interface{})
  1151. }
  1152. p.p["counterid"] = v
  1153. return
  1154. }
  1155. func (p *ListConditionsParams) SetDomainid(v string) {
  1156. if p.p == nil {
  1157. p.p = make(map[string]interface{})
  1158. }
  1159. p.p["domainid"] = v
  1160. return
  1161. }
  1162. func (p *ListConditionsParams) SetId(v string) {
  1163. if p.p == nil {
  1164. p.p = make(map[string]interface{})
  1165. }
  1166. p.p["id"] = v
  1167. return
  1168. }
  1169. func (p *ListConditionsParams) SetIsrecursive(v bool) {
  1170. if p.p == nil {
  1171. p.p = make(map[string]interface{})
  1172. }
  1173. p.p["isrecursive"] = v
  1174. return
  1175. }
  1176. func (p *ListConditionsParams) SetKeyword(v string) {
  1177. if p.p == nil {
  1178. p.p = make(map[string]interface{})
  1179. }
  1180. p.p["keyword"] = v
  1181. return
  1182. }
  1183. func (p *ListConditionsParams) SetListall(v bool) {
  1184. if p.p == nil {
  1185. p.p = make(map[string]interface{})
  1186. }
  1187. p.p["listall"] = v
  1188. return
  1189. }
  1190. func (p *ListConditionsParams) SetPage(v int) {
  1191. if p.p == nil {
  1192. p.p = make(map[string]interface{})
  1193. }
  1194. p.p["page"] = v
  1195. return
  1196. }
  1197. func (p *ListConditionsParams) SetPagesize(v int) {
  1198. if p.p == nil {
  1199. p.p = make(map[string]interface{})
  1200. }
  1201. p.p["pagesize"] = v
  1202. return
  1203. }
  1204. func (p *ListConditionsParams) SetPolicyid(v string) {
  1205. if p.p == nil {
  1206. p.p = make(map[string]interface{})
  1207. }
  1208. p.p["policyid"] = v
  1209. return
  1210. }
  1211. // You should always use this function to get a new ListConditionsParams instance,
  1212. // as then you are sure you have configured all required params
  1213. func (s *AutoScaleService) NewListConditionsParams() *ListConditionsParams {
  1214. p := &ListConditionsParams{}
  1215. p.p = make(map[string]interface{})
  1216. return p
  1217. }
  1218. // This is a courtesy helper function, which in some cases may not work as expected!
  1219. func (s *AutoScaleService) GetConditionByID(id string, opts ...OptionFunc) (*Condition, int, error) {
  1220. p := &ListConditionsParams{}
  1221. p.p = make(map[string]interface{})
  1222. p.p["id"] = id
  1223. for _, fn := range opts {
  1224. if err := fn(s.cs, p); err != nil {
  1225. return nil, -1, err
  1226. }
  1227. }
  1228. l, err := s.ListConditions(p)
  1229. if err != nil {
  1230. if strings.Contains(err.Error(), fmt.Sprintf(
  1231. "Invalid parameter id value=%s due to incorrect long value format, "+
  1232. "or entity does not exist", id)) {
  1233. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1234. }
  1235. return nil, -1, err
  1236. }
  1237. if l.Count == 0 {
  1238. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1239. }
  1240. if l.Count == 1 {
  1241. return l.Conditions[0], l.Count, nil
  1242. }
  1243. return nil, l.Count, fmt.Errorf("There is more then one result for Condition UUID: %s!", id)
  1244. }
  1245. // List Conditions for the specific user
  1246. func (s *AutoScaleService) ListConditions(p *ListConditionsParams) (*ListConditionsResponse, error) {
  1247. resp, err := s.cs.newRequest("listConditions", p.toURLValues())
  1248. if err != nil {
  1249. return nil, err
  1250. }
  1251. var r ListConditionsResponse
  1252. if err := json.Unmarshal(resp, &r); err != nil {
  1253. return nil, err
  1254. }
  1255. return &r, nil
  1256. }
  1257. type ListConditionsResponse struct {
  1258. Count int `json:"count"`
  1259. Conditions []*Condition `json:"condition"`
  1260. }
  1261. type Condition struct {
  1262. Account string `json:"account,omitempty"`
  1263. Counter []string `json:"counter,omitempty"`
  1264. Domain string `json:"domain,omitempty"`
  1265. Domainid string `json:"domainid,omitempty"`
  1266. Id string `json:"id,omitempty"`
  1267. Project string `json:"project,omitempty"`
  1268. Projectid string `json:"projectid,omitempty"`
  1269. Relationaloperator string `json:"relationaloperator,omitempty"`
  1270. Threshold int64 `json:"threshold,omitempty"`
  1271. Zoneid string `json:"zoneid,omitempty"`
  1272. }
  1273. type ListAutoScalePoliciesParams struct {
  1274. p map[string]interface{}
  1275. }
  1276. func (p *ListAutoScalePoliciesParams) toURLValues() url.Values {
  1277. u := url.Values{}
  1278. if p.p == nil {
  1279. return u
  1280. }
  1281. if v, found := p.p["account"]; found {
  1282. u.Set("account", v.(string))
  1283. }
  1284. if v, found := p.p["action"]; found {
  1285. u.Set("action", v.(string))
  1286. }
  1287. if v, found := p.p["conditionid"]; found {
  1288. u.Set("conditionid", v.(string))
  1289. }
  1290. if v, found := p.p["domainid"]; found {
  1291. u.Set("domainid", v.(string))
  1292. }
  1293. if v, found := p.p["id"]; found {
  1294. u.Set("id", v.(string))
  1295. }
  1296. if v, found := p.p["isrecursive"]; found {
  1297. vv := strconv.FormatBool(v.(bool))
  1298. u.Set("isrecursive", vv)
  1299. }
  1300. if v, found := p.p["keyword"]; found {
  1301. u.Set("keyword", v.(string))
  1302. }
  1303. if v, found := p.p["listall"]; found {
  1304. vv := strconv.FormatBool(v.(bool))
  1305. u.Set("listall", vv)
  1306. }
  1307. if v, found := p.p["page"]; found {
  1308. vv := strconv.Itoa(v.(int))
  1309. u.Set("page", vv)
  1310. }
  1311. if v, found := p.p["pagesize"]; found {
  1312. vv := strconv.Itoa(v.(int))
  1313. u.Set("pagesize", vv)
  1314. }
  1315. if v, found := p.p["vmgroupid"]; found {
  1316. u.Set("vmgroupid", v.(string))
  1317. }
  1318. return u
  1319. }
  1320. func (p *ListAutoScalePoliciesParams) SetAccount(v string) {
  1321. if p.p == nil {
  1322. p.p = make(map[string]interface{})
  1323. }
  1324. p.p["account"] = v
  1325. return
  1326. }
  1327. func (p *ListAutoScalePoliciesParams) SetAction(v string) {
  1328. if p.p == nil {
  1329. p.p = make(map[string]interface{})
  1330. }
  1331. p.p["action"] = v
  1332. return
  1333. }
  1334. func (p *ListAutoScalePoliciesParams) SetConditionid(v string) {
  1335. if p.p == nil {
  1336. p.p = make(map[string]interface{})
  1337. }
  1338. p.p["conditionid"] = v
  1339. return
  1340. }
  1341. func (p *ListAutoScalePoliciesParams) SetDomainid(v string) {
  1342. if p.p == nil {
  1343. p.p = make(map[string]interface{})
  1344. }
  1345. p.p["domainid"] = v
  1346. return
  1347. }
  1348. func (p *ListAutoScalePoliciesParams) SetId(v string) {
  1349. if p.p == nil {
  1350. p.p = make(map[string]interface{})
  1351. }
  1352. p.p["id"] = v
  1353. return
  1354. }
  1355. func (p *ListAutoScalePoliciesParams) SetIsrecursive(v bool) {
  1356. if p.p == nil {
  1357. p.p = make(map[string]interface{})
  1358. }
  1359. p.p["isrecursive"] = v
  1360. return
  1361. }
  1362. func (p *ListAutoScalePoliciesParams) SetKeyword(v string) {
  1363. if p.p == nil {
  1364. p.p = make(map[string]interface{})
  1365. }
  1366. p.p["keyword"] = v
  1367. return
  1368. }
  1369. func (p *ListAutoScalePoliciesParams) SetListall(v bool) {
  1370. if p.p == nil {
  1371. p.p = make(map[string]interface{})
  1372. }
  1373. p.p["listall"] = v
  1374. return
  1375. }
  1376. func (p *ListAutoScalePoliciesParams) SetPage(v int) {
  1377. if p.p == nil {
  1378. p.p = make(map[string]interface{})
  1379. }
  1380. p.p["page"] = v
  1381. return
  1382. }
  1383. func (p *ListAutoScalePoliciesParams) SetPagesize(v int) {
  1384. if p.p == nil {
  1385. p.p = make(map[string]interface{})
  1386. }
  1387. p.p["pagesize"] = v
  1388. return
  1389. }
  1390. func (p *ListAutoScalePoliciesParams) SetVmgroupid(v string) {
  1391. if p.p == nil {
  1392. p.p = make(map[string]interface{})
  1393. }
  1394. p.p["vmgroupid"] = v
  1395. return
  1396. }
  1397. // You should always use this function to get a new ListAutoScalePoliciesParams instance,
  1398. // as then you are sure you have configured all required params
  1399. func (s *AutoScaleService) NewListAutoScalePoliciesParams() *ListAutoScalePoliciesParams {
  1400. p := &ListAutoScalePoliciesParams{}
  1401. p.p = make(map[string]interface{})
  1402. return p
  1403. }
  1404. // This is a courtesy helper function, which in some cases may not work as expected!
  1405. func (s *AutoScaleService) GetAutoScalePolicyByID(id string, opts ...OptionFunc) (*AutoScalePolicy, int, error) {
  1406. p := &ListAutoScalePoliciesParams{}
  1407. p.p = make(map[string]interface{})
  1408. p.p["id"] = id
  1409. for _, fn := range opts {
  1410. if err := fn(s.cs, p); err != nil {
  1411. return nil, -1, err
  1412. }
  1413. }
  1414. l, err := s.ListAutoScalePolicies(p)
  1415. if err != nil {
  1416. if strings.Contains(err.Error(), fmt.Sprintf(
  1417. "Invalid parameter id value=%s due to incorrect long value format, "+
  1418. "or entity does not exist", id)) {
  1419. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1420. }
  1421. return nil, -1, err
  1422. }
  1423. if l.Count == 0 {
  1424. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1425. }
  1426. if l.Count == 1 {
  1427. return l.AutoScalePolicies[0], l.Count, nil
  1428. }
  1429. return nil, l.Count, fmt.Errorf("There is more then one result for AutoScalePolicy UUID: %s!", id)
  1430. }
  1431. // Lists autoscale policies.
  1432. func (s *AutoScaleService) ListAutoScalePolicies(p *ListAutoScalePoliciesParams) (*ListAutoScalePoliciesResponse, error) {
  1433. resp, err := s.cs.newRequest("listAutoScalePolicies", p.toURLValues())
  1434. if err != nil {
  1435. return nil, err
  1436. }
  1437. var r ListAutoScalePoliciesResponse
  1438. if err := json.Unmarshal(resp, &r); err != nil {
  1439. return nil, err
  1440. }
  1441. return &r, nil
  1442. }
  1443. type ListAutoScalePoliciesResponse struct {
  1444. Count int `json:"count"`
  1445. AutoScalePolicies []*AutoScalePolicy `json:"autoscalepolicy"`
  1446. }
  1447. type AutoScalePolicy struct {
  1448. Account string `json:"account,omitempty"`
  1449. Action string `json:"action,omitempty"`
  1450. Conditions []string `json:"conditions,omitempty"`
  1451. Domain string `json:"domain,omitempty"`
  1452. Domainid string `json:"domainid,omitempty"`
  1453. Duration int `json:"duration,omitempty"`
  1454. Id string `json:"id,omitempty"`
  1455. Project string `json:"project,omitempty"`
  1456. Projectid string `json:"projectid,omitempty"`
  1457. Quiettime int `json:"quiettime,omitempty"`
  1458. }
  1459. type ListAutoScaleVmProfilesParams struct {
  1460. p map[string]interface{}
  1461. }
  1462. func (p *ListAutoScaleVmProfilesParams) toURLValues() url.Values {
  1463. u := url.Values{}
  1464. if p.p == nil {
  1465. return u
  1466. }
  1467. if v, found := p.p["account"]; found {
  1468. u.Set("account", v.(string))
  1469. }
  1470. if v, found := p.p["domainid"]; found {
  1471. u.Set("domainid", v.(string))
  1472. }
  1473. if v, found := p.p["fordisplay"]; found {
  1474. vv := strconv.FormatBool(v.(bool))
  1475. u.Set("fordisplay", vv)
  1476. }
  1477. if v, found := p.p["id"]; found {
  1478. u.Set("id", v.(string))
  1479. }
  1480. if v, found := p.p["isrecursive"]; found {
  1481. vv := strconv.FormatBool(v.(bool))
  1482. u.Set("isrecursive", vv)
  1483. }
  1484. if v, found := p.p["keyword"]; found {
  1485. u.Set("keyword", v.(string))
  1486. }
  1487. if v, found := p.p["listall"]; found {
  1488. vv := strconv.FormatBool(v.(bool))
  1489. u.Set("listall", vv)
  1490. }
  1491. if v, found := p.p["otherdeployparams"]; found {
  1492. u.Set("otherdeployparams", v.(string))
  1493. }
  1494. if v, found := p.p["page"]; found {
  1495. vv := strconv.Itoa(v.(int))
  1496. u.Set("page", vv)
  1497. }
  1498. if v, found := p.p["pagesize"]; found {
  1499. vv := strconv.Itoa(v.(int))
  1500. u.Set("pagesize", vv)
  1501. }
  1502. if v, found := p.p["projectid"]; found {
  1503. u.Set("projectid", v.(string))
  1504. }
  1505. if v, found := p.p["serviceofferingid"]; found {
  1506. u.Set("serviceofferingid", v.(string))
  1507. }
  1508. if v, found := p.p["templateid"]; found {
  1509. u.Set("templateid", v.(string))
  1510. }
  1511. if v, found := p.p["zoneid"]; found {
  1512. u.Set("zoneid", v.(string))
  1513. }
  1514. return u
  1515. }
  1516. func (p *ListAutoScaleVmProfilesParams) SetAccount(v string) {
  1517. if p.p == nil {
  1518. p.p = make(map[string]interface{})
  1519. }
  1520. p.p["account"] = v
  1521. return
  1522. }
  1523. func (p *ListAutoScaleVmProfilesParams) SetDomainid(v string) {
  1524. if p.p == nil {
  1525. p.p = make(map[string]interface{})
  1526. }
  1527. p.p["domainid"] = v
  1528. return
  1529. }
  1530. func (p *ListAutoScaleVmProfilesParams) SetFordisplay(v bool) {
  1531. if p.p == nil {
  1532. p.p = make(map[string]interface{})
  1533. }
  1534. p.p["fordisplay"] = v
  1535. return
  1536. }
  1537. func (p *ListAutoScaleVmProfilesParams) SetId(v string) {
  1538. if p.p == nil {
  1539. p.p = make(map[string]interface{})
  1540. }
  1541. p.p["id"] = v
  1542. return
  1543. }
  1544. func (p *ListAutoScaleVmProfilesParams) SetIsrecursive(v bool) {
  1545. if p.p == nil {
  1546. p.p = make(map[string]interface{})
  1547. }
  1548. p.p["isrecursive"] = v
  1549. return
  1550. }
  1551. func (p *ListAutoScaleVmProfilesParams) SetKeyword(v string) {
  1552. if p.p == nil {
  1553. p.p = make(map[string]interface{})
  1554. }
  1555. p.p["keyword"] = v
  1556. return
  1557. }
  1558. func (p *ListAutoScaleVmProfilesParams) SetListall(v bool) {
  1559. if p.p == nil {
  1560. p.p = make(map[string]interface{})
  1561. }
  1562. p.p["listall"] = v
  1563. return
  1564. }
  1565. func (p *ListAutoScaleVmProfilesParams) SetOtherdeployparams(v string) {
  1566. if p.p == nil {
  1567. p.p = make(map[string]interface{})
  1568. }
  1569. p.p["otherdeployparams"] = v
  1570. return
  1571. }
  1572. func (p *ListAutoScaleVmProfilesParams) SetPage(v int) {
  1573. if p.p == nil {
  1574. p.p = make(map[string]interface{})
  1575. }
  1576. p.p["page"] = v
  1577. return
  1578. }
  1579. func (p *ListAutoScaleVmProfilesParams) SetPagesize(v int) {
  1580. if p.p == nil {
  1581. p.p = make(map[string]interface{})
  1582. }
  1583. p.p["pagesize"] = v
  1584. return
  1585. }
  1586. func (p *ListAutoScaleVmProfilesParams) SetProjectid(v string) {
  1587. if p.p == nil {
  1588. p.p = make(map[string]interface{})
  1589. }
  1590. p.p["projectid"] = v
  1591. return
  1592. }
  1593. func (p *ListAutoScaleVmProfilesParams) SetServiceofferingid(v string) {
  1594. if p.p == nil {
  1595. p.p = make(map[string]interface{})
  1596. }
  1597. p.p["serviceofferingid"] = v
  1598. return
  1599. }
  1600. func (p *ListAutoScaleVmProfilesParams) SetTemplateid(v string) {
  1601. if p.p == nil {
  1602. p.p = make(map[string]interface{})
  1603. }
  1604. p.p["templateid"] = v
  1605. return
  1606. }
  1607. func (p *ListAutoScaleVmProfilesParams) SetZoneid(v string) {
  1608. if p.p == nil {
  1609. p.p = make(map[string]interface{})
  1610. }
  1611. p.p["zoneid"] = v
  1612. return
  1613. }
  1614. // You should always use this function to get a new ListAutoScaleVmProfilesParams instance,
  1615. // as then you are sure you have configured all required params
  1616. func (s *AutoScaleService) NewListAutoScaleVmProfilesParams() *ListAutoScaleVmProfilesParams {
  1617. p := &ListAutoScaleVmProfilesParams{}
  1618. p.p = make(map[string]interface{})
  1619. return p
  1620. }
  1621. // This is a courtesy helper function, which in some cases may not work as expected!
  1622. func (s *AutoScaleService) GetAutoScaleVmProfileByID(id string, opts ...OptionFunc) (*AutoScaleVmProfile, int, error) {
  1623. p := &ListAutoScaleVmProfilesParams{}
  1624. p.p = make(map[string]interface{})
  1625. p.p["id"] = id
  1626. for _, fn := range opts {
  1627. if err := fn(s.cs, p); err != nil {
  1628. return nil, -1, err
  1629. }
  1630. }
  1631. l, err := s.ListAutoScaleVmProfiles(p)
  1632. if err != nil {
  1633. if strings.Contains(err.Error(), fmt.Sprintf(
  1634. "Invalid parameter id value=%s due to incorrect long value format, "+
  1635. "or entity does not exist", id)) {
  1636. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1637. }
  1638. return nil, -1, err
  1639. }
  1640. if l.Count == 0 {
  1641. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1642. }
  1643. if l.Count == 1 {
  1644. return l.AutoScaleVmProfiles[0], l.Count, nil
  1645. }
  1646. return nil, l.Count, fmt.Errorf("There is more then one result for AutoScaleVmProfile UUID: %s!", id)
  1647. }
  1648. // Lists autoscale vm profiles.
  1649. func (s *AutoScaleService) ListAutoScaleVmProfiles(p *ListAutoScaleVmProfilesParams) (*ListAutoScaleVmProfilesResponse, error) {
  1650. resp, err := s.cs.newRequest("listAutoScaleVmProfiles", p.toURLValues())
  1651. if err != nil {
  1652. return nil, err
  1653. }
  1654. var r ListAutoScaleVmProfilesResponse
  1655. if err := json.Unmarshal(resp, &r); err != nil {
  1656. return nil, err
  1657. }
  1658. return &r, nil
  1659. }
  1660. type ListAutoScaleVmProfilesResponse struct {
  1661. Count int `json:"count"`
  1662. AutoScaleVmProfiles []*AutoScaleVmProfile `json:"autoscalevmprofile"`
  1663. }
  1664. type AutoScaleVmProfile struct {
  1665. Account string `json:"account,omitempty"`
  1666. Autoscaleuserid string `json:"autoscaleuserid,omitempty"`
  1667. Destroyvmgraceperiod int `json:"destroyvmgraceperiod,omitempty"`
  1668. Domain string `json:"domain,omitempty"`
  1669. Domainid string `json:"domainid,omitempty"`
  1670. Fordisplay bool `json:"fordisplay,omitempty"`
  1671. Id string `json:"id,omitempty"`
  1672. Otherdeployparams string `json:"otherdeployparams,omitempty"`
  1673. Project string `json:"project,omitempty"`
  1674. Projectid string `json:"projectid,omitempty"`
  1675. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  1676. Templateid string `json:"templateid,omitempty"`
  1677. Zoneid string `json:"zoneid,omitempty"`
  1678. }
  1679. type ListAutoScaleVmGroupsParams struct {
  1680. p map[string]interface{}
  1681. }
  1682. func (p *ListAutoScaleVmGroupsParams) toURLValues() url.Values {
  1683. u := url.Values{}
  1684. if p.p == nil {
  1685. return u
  1686. }
  1687. if v, found := p.p["account"]; found {
  1688. u.Set("account", v.(string))
  1689. }
  1690. if v, found := p.p["domainid"]; found {
  1691. u.Set("domainid", v.(string))
  1692. }
  1693. if v, found := p.p["fordisplay"]; found {
  1694. vv := strconv.FormatBool(v.(bool))
  1695. u.Set("fordisplay", vv)
  1696. }
  1697. if v, found := p.p["id"]; found {
  1698. u.Set("id", v.(string))
  1699. }
  1700. if v, found := p.p["isrecursive"]; found {
  1701. vv := strconv.FormatBool(v.(bool))
  1702. u.Set("isrecursive", vv)
  1703. }
  1704. if v, found := p.p["keyword"]; found {
  1705. u.Set("keyword", v.(string))
  1706. }
  1707. if v, found := p.p["lbruleid"]; found {
  1708. u.Set("lbruleid", v.(string))
  1709. }
  1710. if v, found := p.p["listall"]; found {
  1711. vv := strconv.FormatBool(v.(bool))
  1712. u.Set("listall", vv)
  1713. }
  1714. if v, found := p.p["page"]; found {
  1715. vv := strconv.Itoa(v.(int))
  1716. u.Set("page", vv)
  1717. }
  1718. if v, found := p.p["pagesize"]; found {
  1719. vv := strconv.Itoa(v.(int))
  1720. u.Set("pagesize", vv)
  1721. }
  1722. if v, found := p.p["policyid"]; found {
  1723. u.Set("policyid", v.(string))
  1724. }
  1725. if v, found := p.p["projectid"]; found {
  1726. u.Set("projectid", v.(string))
  1727. }
  1728. if v, found := p.p["vmprofileid"]; found {
  1729. u.Set("vmprofileid", v.(string))
  1730. }
  1731. if v, found := p.p["zoneid"]; found {
  1732. u.Set("zoneid", v.(string))
  1733. }
  1734. return u
  1735. }
  1736. func (p *ListAutoScaleVmGroupsParams) SetAccount(v string) {
  1737. if p.p == nil {
  1738. p.p = make(map[string]interface{})
  1739. }
  1740. p.p["account"] = v
  1741. return
  1742. }
  1743. func (p *ListAutoScaleVmGroupsParams) SetDomainid(v string) {
  1744. if p.p == nil {
  1745. p.p = make(map[string]interface{})
  1746. }
  1747. p.p["domainid"] = v
  1748. return
  1749. }
  1750. func (p *ListAutoScaleVmGroupsParams) SetFordisplay(v bool) {
  1751. if p.p == nil {
  1752. p.p = make(map[string]interface{})
  1753. }
  1754. p.p["fordisplay"] = v
  1755. return
  1756. }
  1757. func (p *ListAutoScaleVmGroupsParams) SetId(v string) {
  1758. if p.p == nil {
  1759. p.p = make(map[string]interface{})
  1760. }
  1761. p.p["id"] = v
  1762. return
  1763. }
  1764. func (p *ListAutoScaleVmGroupsParams) SetIsrecursive(v bool) {
  1765. if p.p == nil {
  1766. p.p = make(map[string]interface{})
  1767. }
  1768. p.p["isrecursive"] = v
  1769. return
  1770. }
  1771. func (p *ListAutoScaleVmGroupsParams) SetKeyword(v string) {
  1772. if p.p == nil {
  1773. p.p = make(map[string]interface{})
  1774. }
  1775. p.p["keyword"] = v
  1776. return
  1777. }
  1778. func (p *ListAutoScaleVmGroupsParams) SetLbruleid(v string) {
  1779. if p.p == nil {
  1780. p.p = make(map[string]interface{})
  1781. }
  1782. p.p["lbruleid"] = v
  1783. return
  1784. }
  1785. func (p *ListAutoScaleVmGroupsParams) SetListall(v bool) {
  1786. if p.p == nil {
  1787. p.p = make(map[string]interface{})
  1788. }
  1789. p.p["listall"] = v
  1790. return
  1791. }
  1792. func (p *ListAutoScaleVmGroupsParams) SetPage(v int) {
  1793. if p.p == nil {
  1794. p.p = make(map[string]interface{})
  1795. }
  1796. p.p["page"] = v
  1797. return
  1798. }
  1799. func (p *ListAutoScaleVmGroupsParams) SetPagesize(v int) {
  1800. if p.p == nil {
  1801. p.p = make(map[string]interface{})
  1802. }
  1803. p.p["pagesize"] = v
  1804. return
  1805. }
  1806. func (p *ListAutoScaleVmGroupsParams) SetPolicyid(v string) {
  1807. if p.p == nil {
  1808. p.p = make(map[string]interface{})
  1809. }
  1810. p.p["policyid"] = v
  1811. return
  1812. }
  1813. func (p *ListAutoScaleVmGroupsParams) SetProjectid(v string) {
  1814. if p.p == nil {
  1815. p.p = make(map[string]interface{})
  1816. }
  1817. p.p["projectid"] = v
  1818. return
  1819. }
  1820. func (p *ListAutoScaleVmGroupsParams) SetVmprofileid(v string) {
  1821. if p.p == nil {
  1822. p.p = make(map[string]interface{})
  1823. }
  1824. p.p["vmprofileid"] = v
  1825. return
  1826. }
  1827. func (p *ListAutoScaleVmGroupsParams) SetZoneid(v string) {
  1828. if p.p == nil {
  1829. p.p = make(map[string]interface{})
  1830. }
  1831. p.p["zoneid"] = v
  1832. return
  1833. }
  1834. // You should always use this function to get a new ListAutoScaleVmGroupsParams instance,
  1835. // as then you are sure you have configured all required params
  1836. func (s *AutoScaleService) NewListAutoScaleVmGroupsParams() *ListAutoScaleVmGroupsParams {
  1837. p := &ListAutoScaleVmGroupsParams{}
  1838. p.p = make(map[string]interface{})
  1839. return p
  1840. }
  1841. // This is a courtesy helper function, which in some cases may not work as expected!
  1842. func (s *AutoScaleService) GetAutoScaleVmGroupByID(id string, opts ...OptionFunc) (*AutoScaleVmGroup, int, error) {
  1843. p := &ListAutoScaleVmGroupsParams{}
  1844. p.p = make(map[string]interface{})
  1845. p.p["id"] = id
  1846. for _, fn := range opts {
  1847. if err := fn(s.cs, p); err != nil {
  1848. return nil, -1, err
  1849. }
  1850. }
  1851. l, err := s.ListAutoScaleVmGroups(p)
  1852. if err != nil {
  1853. if strings.Contains(err.Error(), fmt.Sprintf(
  1854. "Invalid parameter id value=%s due to incorrect long value format, "+
  1855. "or entity does not exist", id)) {
  1856. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1857. }
  1858. return nil, -1, err
  1859. }
  1860. if l.Count == 0 {
  1861. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1862. }
  1863. if l.Count == 1 {
  1864. return l.AutoScaleVmGroups[0], l.Count, nil
  1865. }
  1866. return nil, l.Count, fmt.Errorf("There is more then one result for AutoScaleVmGroup UUID: %s!", id)
  1867. }
  1868. // Lists autoscale vm groups.
  1869. func (s *AutoScaleService) ListAutoScaleVmGroups(p *ListAutoScaleVmGroupsParams) (*ListAutoScaleVmGroupsResponse, error) {
  1870. resp, err := s.cs.newRequest("listAutoScaleVmGroups", p.toURLValues())
  1871. if err != nil {
  1872. return nil, err
  1873. }
  1874. var r ListAutoScaleVmGroupsResponse
  1875. if err := json.Unmarshal(resp, &r); err != nil {
  1876. return nil, err
  1877. }
  1878. return &r, nil
  1879. }
  1880. type ListAutoScaleVmGroupsResponse struct {
  1881. Count int `json:"count"`
  1882. AutoScaleVmGroups []*AutoScaleVmGroup `json:"autoscalevmgroup"`
  1883. }
  1884. type AutoScaleVmGroup struct {
  1885. Account string `json:"account,omitempty"`
  1886. Domain string `json:"domain,omitempty"`
  1887. Domainid string `json:"domainid,omitempty"`
  1888. Fordisplay bool `json:"fordisplay,omitempty"`
  1889. Id string `json:"id,omitempty"`
  1890. Interval int `json:"interval,omitempty"`
  1891. Lbruleid string `json:"lbruleid,omitempty"`
  1892. Maxmembers int `json:"maxmembers,omitempty"`
  1893. Minmembers int `json:"minmembers,omitempty"`
  1894. Project string `json:"project,omitempty"`
  1895. Projectid string `json:"projectid,omitempty"`
  1896. Scaledownpolicies []string `json:"scaledownpolicies,omitempty"`
  1897. Scaleuppolicies []string `json:"scaleuppolicies,omitempty"`
  1898. State string `json:"state,omitempty"`
  1899. Vmprofileid string `json:"vmprofileid,omitempty"`
  1900. }
  1901. type EnableAutoScaleVmGroupParams struct {
  1902. p map[string]interface{}
  1903. }
  1904. func (p *EnableAutoScaleVmGroupParams) toURLValues() url.Values {
  1905. u := url.Values{}
  1906. if p.p == nil {
  1907. return u
  1908. }
  1909. if v, found := p.p["id"]; found {
  1910. u.Set("id", v.(string))
  1911. }
  1912. return u
  1913. }
  1914. func (p *EnableAutoScaleVmGroupParams) SetId(v string) {
  1915. if p.p == nil {
  1916. p.p = make(map[string]interface{})
  1917. }
  1918. p.p["id"] = v
  1919. return
  1920. }
  1921. // You should always use this function to get a new EnableAutoScaleVmGroupParams instance,
  1922. // as then you are sure you have configured all required params
  1923. func (s *AutoScaleService) NewEnableAutoScaleVmGroupParams(id string) *EnableAutoScaleVmGroupParams {
  1924. p := &EnableAutoScaleVmGroupParams{}
  1925. p.p = make(map[string]interface{})
  1926. p.p["id"] = id
  1927. return p
  1928. }
  1929. // Enables an AutoScale Vm Group
  1930. func (s *AutoScaleService) EnableAutoScaleVmGroup(p *EnableAutoScaleVmGroupParams) (*EnableAutoScaleVmGroupResponse, error) {
  1931. resp, err := s.cs.newRequest("enableAutoScaleVmGroup", p.toURLValues())
  1932. if err != nil {
  1933. return nil, err
  1934. }
  1935. var r EnableAutoScaleVmGroupResponse
  1936. if err := json.Unmarshal(resp, &r); err != nil {
  1937. return nil, err
  1938. }
  1939. // If we have a async client, we need to wait for the async result
  1940. if s.cs.async {
  1941. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1942. if err != nil {
  1943. if err == AsyncTimeoutErr {
  1944. return &r, err
  1945. }
  1946. return nil, err
  1947. }
  1948. b, err = getRawValue(b)
  1949. if err != nil {
  1950. return nil, err
  1951. }
  1952. if err := json.Unmarshal(b, &r); err != nil {
  1953. return nil, err
  1954. }
  1955. }
  1956. return &r, nil
  1957. }
  1958. type EnableAutoScaleVmGroupResponse struct {
  1959. JobID string `json:"jobid,omitempty"`
  1960. Account string `json:"account,omitempty"`
  1961. Domain string `json:"domain,omitempty"`
  1962. Domainid string `json:"domainid,omitempty"`
  1963. Fordisplay bool `json:"fordisplay,omitempty"`
  1964. Id string `json:"id,omitempty"`
  1965. Interval int `json:"interval,omitempty"`
  1966. Lbruleid string `json:"lbruleid,omitempty"`
  1967. Maxmembers int `json:"maxmembers,omitempty"`
  1968. Minmembers int `json:"minmembers,omitempty"`
  1969. Project string `json:"project,omitempty"`
  1970. Projectid string `json:"projectid,omitempty"`
  1971. Scaledownpolicies []string `json:"scaledownpolicies,omitempty"`
  1972. Scaleuppolicies []string `json:"scaleuppolicies,omitempty"`
  1973. State string `json:"state,omitempty"`
  1974. Vmprofileid string `json:"vmprofileid,omitempty"`
  1975. }
  1976. type DisableAutoScaleVmGroupParams struct {
  1977. p map[string]interface{}
  1978. }
  1979. func (p *DisableAutoScaleVmGroupParams) toURLValues() url.Values {
  1980. u := url.Values{}
  1981. if p.p == nil {
  1982. return u
  1983. }
  1984. if v, found := p.p["id"]; found {
  1985. u.Set("id", v.(string))
  1986. }
  1987. return u
  1988. }
  1989. func (p *DisableAutoScaleVmGroupParams) SetId(v string) {
  1990. if p.p == nil {
  1991. p.p = make(map[string]interface{})
  1992. }
  1993. p.p["id"] = v
  1994. return
  1995. }
  1996. // You should always use this function to get a new DisableAutoScaleVmGroupParams instance,
  1997. // as then you are sure you have configured all required params
  1998. func (s *AutoScaleService) NewDisableAutoScaleVmGroupParams(id string) *DisableAutoScaleVmGroupParams {
  1999. p := &DisableAutoScaleVmGroupParams{}
  2000. p.p = make(map[string]interface{})
  2001. p.p["id"] = id
  2002. return p
  2003. }
  2004. // Disables an AutoScale Vm Group
  2005. func (s *AutoScaleService) DisableAutoScaleVmGroup(p *DisableAutoScaleVmGroupParams) (*DisableAutoScaleVmGroupResponse, error) {
  2006. resp, err := s.cs.newRequest("disableAutoScaleVmGroup", p.toURLValues())
  2007. if err != nil {
  2008. return nil, err
  2009. }
  2010. var r DisableAutoScaleVmGroupResponse
  2011. if err := json.Unmarshal(resp, &r); err != nil {
  2012. return nil, err
  2013. }
  2014. // If we have a async client, we need to wait for the async result
  2015. if s.cs.async {
  2016. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  2017. if err != nil {
  2018. if err == AsyncTimeoutErr {
  2019. return &r, err
  2020. }
  2021. return nil, err
  2022. }
  2023. b, err = getRawValue(b)
  2024. if err != nil {
  2025. return nil, err
  2026. }
  2027. if err := json.Unmarshal(b, &r); err != nil {
  2028. return nil, err
  2029. }
  2030. }
  2031. return &r, nil
  2032. }
  2033. type DisableAutoScaleVmGroupResponse struct {
  2034. JobID string `json:"jobid,omitempty"`
  2035. Account string `json:"account,omitempty"`
  2036. Domain string `json:"domain,omitempty"`
  2037. Domainid string `json:"domainid,omitempty"`
  2038. Fordisplay bool `json:"fordisplay,omitempty"`
  2039. Id string `json:"id,omitempty"`
  2040. Interval int `json:"interval,omitempty"`
  2041. Lbruleid string `json:"lbruleid,omitempty"`
  2042. Maxmembers int `json:"maxmembers,omitempty"`
  2043. Minmembers int `json:"minmembers,omitempty"`
  2044. Project string `json:"project,omitempty"`
  2045. Projectid string `json:"projectid,omitempty"`
  2046. Scaledownpolicies []string `json:"scaledownpolicies,omitempty"`
  2047. Scaleuppolicies []string `json:"scaleuppolicies,omitempty"`
  2048. State string `json:"state,omitempty"`
  2049. Vmprofileid string `json:"vmprofileid,omitempty"`
  2050. }
  2051. type UpdateAutoScalePolicyParams struct {
  2052. p map[string]interface{}
  2053. }
  2054. func (p *UpdateAutoScalePolicyParams) toURLValues() url.Values {
  2055. u := url.Values{}
  2056. if p.p == nil {
  2057. return u
  2058. }
  2059. if v, found := p.p["conditionids"]; found {
  2060. vv := strings.Join(v.([]string), ",")
  2061. u.Set("conditionids", vv)
  2062. }
  2063. if v, found := p.p["duration"]; found {
  2064. vv := strconv.Itoa(v.(int))
  2065. u.Set("duration", vv)
  2066. }
  2067. if v, found := p.p["id"]; found {
  2068. u.Set("id", v.(string))
  2069. }
  2070. if v, found := p.p["quiettime"]; found {
  2071. vv := strconv.Itoa(v.(int))
  2072. u.Set("quiettime", vv)
  2073. }
  2074. return u
  2075. }
  2076. func (p *UpdateAutoScalePolicyParams) SetConditionids(v []string) {
  2077. if p.p == nil {
  2078. p.p = make(map[string]interface{})
  2079. }
  2080. p.p["conditionids"] = v
  2081. return
  2082. }
  2083. func (p *UpdateAutoScalePolicyParams) SetDuration(v int) {
  2084. if p.p == nil {
  2085. p.p = make(map[string]interface{})
  2086. }
  2087. p.p["duration"] = v
  2088. return
  2089. }
  2090. func (p *UpdateAutoScalePolicyParams) SetId(v string) {
  2091. if p.p == nil {
  2092. p.p = make(map[string]interface{})
  2093. }
  2094. p.p["id"] = v
  2095. return
  2096. }
  2097. func (p *UpdateAutoScalePolicyParams) SetQuiettime(v int) {
  2098. if p.p == nil {
  2099. p.p = make(map[string]interface{})
  2100. }
  2101. p.p["quiettime"] = v
  2102. return
  2103. }
  2104. // You should always use this function to get a new UpdateAutoScalePolicyParams instance,
  2105. // as then you are sure you have configured all required params
  2106. func (s *AutoScaleService) NewUpdateAutoScalePolicyParams(id string) *UpdateAutoScalePolicyParams {
  2107. p := &UpdateAutoScalePolicyParams{}
  2108. p.p = make(map[string]interface{})
  2109. p.p["id"] = id
  2110. return p
  2111. }
  2112. // Updates an existing autoscale policy.
  2113. func (s *AutoScaleService) UpdateAutoScalePolicy(p *UpdateAutoScalePolicyParams) (*UpdateAutoScalePolicyResponse, error) {
  2114. resp, err := s.cs.newRequest("updateAutoScalePolicy", p.toURLValues())
  2115. if err != nil {
  2116. return nil, err
  2117. }
  2118. var r UpdateAutoScalePolicyResponse
  2119. if err := json.Unmarshal(resp, &r); err != nil {
  2120. return nil, err
  2121. }
  2122. // If we have a async client, we need to wait for the async result
  2123. if s.cs.async {
  2124. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  2125. if err != nil {
  2126. if err == AsyncTimeoutErr {
  2127. return &r, err
  2128. }
  2129. return nil, err
  2130. }
  2131. b, err = getRawValue(b)
  2132. if err != nil {
  2133. return nil, err
  2134. }
  2135. if err := json.Unmarshal(b, &r); err != nil {
  2136. return nil, err
  2137. }
  2138. }
  2139. return &r, nil
  2140. }
  2141. type UpdateAutoScalePolicyResponse struct {
  2142. JobID string `json:"jobid,omitempty"`
  2143. Account string `json:"account,omitempty"`
  2144. Action string `json:"action,omitempty"`
  2145. Conditions []string `json:"conditions,omitempty"`
  2146. Domain string `json:"domain,omitempty"`
  2147. Domainid string `json:"domainid,omitempty"`
  2148. Duration int `json:"duration,omitempty"`
  2149. Id string `json:"id,omitempty"`
  2150. Project string `json:"project,omitempty"`
  2151. Projectid string `json:"projectid,omitempty"`
  2152. Quiettime int `json:"quiettime,omitempty"`
  2153. }
  2154. type UpdateAutoScaleVmProfileParams struct {
  2155. p map[string]interface{}
  2156. }
  2157. func (p *UpdateAutoScaleVmProfileParams) toURLValues() url.Values {
  2158. u := url.Values{}
  2159. if p.p == nil {
  2160. return u
  2161. }
  2162. if v, found := p.p["autoscaleuserid"]; found {
  2163. u.Set("autoscaleuserid", v.(string))
  2164. }
  2165. if v, found := p.p["counterparam"]; found {
  2166. i := 0
  2167. for k, vv := range v.(map[string]string) {
  2168. u.Set(fmt.Sprintf("counterparam[%d].key", i), k)
  2169. u.Set(fmt.Sprintf("counterparam[%d].value", i), vv)
  2170. i++
  2171. }
  2172. }
  2173. if v, found := p.p["customid"]; found {
  2174. u.Set("customid", v.(string))
  2175. }
  2176. if v, found := p.p["destroyvmgraceperiod"]; found {
  2177. vv := strconv.Itoa(v.(int))
  2178. u.Set("destroyvmgraceperiod", vv)
  2179. }
  2180. if v, found := p.p["fordisplay"]; found {
  2181. vv := strconv.FormatBool(v.(bool))
  2182. u.Set("fordisplay", vv)
  2183. }
  2184. if v, found := p.p["id"]; found {
  2185. u.Set("id", v.(string))
  2186. }
  2187. if v, found := p.p["templateid"]; found {
  2188. u.Set("templateid", v.(string))
  2189. }
  2190. return u
  2191. }
  2192. func (p *UpdateAutoScaleVmProfileParams) SetAutoscaleuserid(v string) {
  2193. if p.p == nil {
  2194. p.p = make(map[string]interface{})
  2195. }
  2196. p.p["autoscaleuserid"] = v
  2197. return
  2198. }
  2199. func (p *UpdateAutoScaleVmProfileParams) SetCounterparam(v map[string]string) {
  2200. if p.p == nil {
  2201. p.p = make(map[string]interface{})
  2202. }
  2203. p.p["counterparam"] = v
  2204. return
  2205. }
  2206. func (p *UpdateAutoScaleVmProfileParams) SetCustomid(v string) {
  2207. if p.p == nil {
  2208. p.p = make(map[string]interface{})
  2209. }
  2210. p.p["customid"] = v
  2211. return
  2212. }
  2213. func (p *UpdateAutoScaleVmProfileParams) SetDestroyvmgraceperiod(v int) {
  2214. if p.p == nil {
  2215. p.p = make(map[string]interface{})
  2216. }
  2217. p.p["destroyvmgraceperiod"] = v
  2218. return
  2219. }
  2220. func (p *UpdateAutoScaleVmProfileParams) SetFordisplay(v bool) {
  2221. if p.p == nil {
  2222. p.p = make(map[string]interface{})
  2223. }
  2224. p.p["fordisplay"] = v
  2225. return
  2226. }
  2227. func (p *UpdateAutoScaleVmProfileParams) SetId(v string) {
  2228. if p.p == nil {
  2229. p.p = make(map[string]interface{})
  2230. }
  2231. p.p["id"] = v
  2232. return
  2233. }
  2234. func (p *UpdateAutoScaleVmProfileParams) SetTemplateid(v string) {
  2235. if p.p == nil {
  2236. p.p = make(map[string]interface{})
  2237. }
  2238. p.p["templateid"] = v
  2239. return
  2240. }
  2241. // You should always use this function to get a new UpdateAutoScaleVmProfileParams instance,
  2242. // as then you are sure you have configured all required params
  2243. func (s *AutoScaleService) NewUpdateAutoScaleVmProfileParams(id string) *UpdateAutoScaleVmProfileParams {
  2244. p := &UpdateAutoScaleVmProfileParams{}
  2245. p.p = make(map[string]interface{})
  2246. p.p["id"] = id
  2247. return p
  2248. }
  2249. // Updates an existing autoscale vm profile.
  2250. func (s *AutoScaleService) UpdateAutoScaleVmProfile(p *UpdateAutoScaleVmProfileParams) (*UpdateAutoScaleVmProfileResponse, error) {
  2251. resp, err := s.cs.newRequest("updateAutoScaleVmProfile", p.toURLValues())
  2252. if err != nil {
  2253. return nil, err
  2254. }
  2255. var r UpdateAutoScaleVmProfileResponse
  2256. if err := json.Unmarshal(resp, &r); err != nil {
  2257. return nil, err
  2258. }
  2259. // If we have a async client, we need to wait for the async result
  2260. if s.cs.async {
  2261. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  2262. if err != nil {
  2263. if err == AsyncTimeoutErr {
  2264. return &r, err
  2265. }
  2266. return nil, err
  2267. }
  2268. b, err = getRawValue(b)
  2269. if err != nil {
  2270. return nil, err
  2271. }
  2272. if err := json.Unmarshal(b, &r); err != nil {
  2273. return nil, err
  2274. }
  2275. }
  2276. return &r, nil
  2277. }
  2278. type UpdateAutoScaleVmProfileResponse struct {
  2279. JobID string `json:"jobid,omitempty"`
  2280. Account string `json:"account,omitempty"`
  2281. Autoscaleuserid string `json:"autoscaleuserid,omitempty"`
  2282. Destroyvmgraceperiod int `json:"destroyvmgraceperiod,omitempty"`
  2283. Domain string `json:"domain,omitempty"`
  2284. Domainid string `json:"domainid,omitempty"`
  2285. Fordisplay bool `json:"fordisplay,omitempty"`
  2286. Id string `json:"id,omitempty"`
  2287. Otherdeployparams string `json:"otherdeployparams,omitempty"`
  2288. Project string `json:"project,omitempty"`
  2289. Projectid string `json:"projectid,omitempty"`
  2290. Serviceofferingid string `json:"serviceofferingid,omitempty"`
  2291. Templateid string `json:"templateid,omitempty"`
  2292. Zoneid string `json:"zoneid,omitempty"`
  2293. }
  2294. type UpdateAutoScaleVmGroupParams struct {
  2295. p map[string]interface{}
  2296. }
  2297. func (p *UpdateAutoScaleVmGroupParams) toURLValues() url.Values {
  2298. u := url.Values{}
  2299. if p.p == nil {
  2300. return u
  2301. }
  2302. if v, found := p.p["customid"]; found {
  2303. u.Set("customid", v.(string))
  2304. }
  2305. if v, found := p.p["fordisplay"]; found {
  2306. vv := strconv.FormatBool(v.(bool))
  2307. u.Set("fordisplay", vv)
  2308. }
  2309. if v, found := p.p["id"]; found {
  2310. u.Set("id", v.(string))
  2311. }
  2312. if v, found := p.p["interval"]; found {
  2313. vv := strconv.Itoa(v.(int))
  2314. u.Set("interval", vv)
  2315. }
  2316. if v, found := p.p["maxmembers"]; found {
  2317. vv := strconv.Itoa(v.(int))
  2318. u.Set("maxmembers", vv)
  2319. }
  2320. if v, found := p.p["minmembers"]; found {
  2321. vv := strconv.Itoa(v.(int))
  2322. u.Set("minmembers", vv)
  2323. }
  2324. if v, found := p.p["scaledownpolicyids"]; found {
  2325. vv := strings.Join(v.([]string), ",")
  2326. u.Set("scaledownpolicyids", vv)
  2327. }
  2328. if v, found := p.p["scaleuppolicyids"]; found {
  2329. vv := strings.Join(v.([]string), ",")
  2330. u.Set("scaleuppolicyids", vv)
  2331. }
  2332. return u
  2333. }
  2334. func (p *UpdateAutoScaleVmGroupParams) SetCustomid(v string) {
  2335. if p.p == nil {
  2336. p.p = make(map[string]interface{})
  2337. }
  2338. p.p["customid"] = v
  2339. return
  2340. }
  2341. func (p *UpdateAutoScaleVmGroupParams) SetFordisplay(v bool) {
  2342. if p.p == nil {
  2343. p.p = make(map[string]interface{})
  2344. }
  2345. p.p["fordisplay"] = v
  2346. return
  2347. }
  2348. func (p *UpdateAutoScaleVmGroupParams) SetId(v string) {
  2349. if p.p == nil {
  2350. p.p = make(map[string]interface{})
  2351. }
  2352. p.p["id"] = v
  2353. return
  2354. }
  2355. func (p *UpdateAutoScaleVmGroupParams) SetInterval(v int) {
  2356. if p.p == nil {
  2357. p.p = make(map[string]interface{})
  2358. }
  2359. p.p["interval"] = v
  2360. return
  2361. }
  2362. func (p *UpdateAutoScaleVmGroupParams) SetMaxmembers(v int) {
  2363. if p.p == nil {
  2364. p.p = make(map[string]interface{})
  2365. }
  2366. p.p["maxmembers"] = v
  2367. return
  2368. }
  2369. func (p *UpdateAutoScaleVmGroupParams) SetMinmembers(v int) {
  2370. if p.p == nil {
  2371. p.p = make(map[string]interface{})
  2372. }
  2373. p.p["minmembers"] = v
  2374. return
  2375. }
  2376. func (p *UpdateAutoScaleVmGroupParams) SetScaledownpolicyids(v []string) {
  2377. if p.p == nil {
  2378. p.p = make(map[string]interface{})
  2379. }
  2380. p.p["scaledownpolicyids"] = v
  2381. return
  2382. }
  2383. func (p *UpdateAutoScaleVmGroupParams) SetScaleuppolicyids(v []string) {
  2384. if p.p == nil {
  2385. p.p = make(map[string]interface{})
  2386. }
  2387. p.p["scaleuppolicyids"] = v
  2388. return
  2389. }
  2390. // You should always use this function to get a new UpdateAutoScaleVmGroupParams instance,
  2391. // as then you are sure you have configured all required params
  2392. func (s *AutoScaleService) NewUpdateAutoScaleVmGroupParams(id string) *UpdateAutoScaleVmGroupParams {
  2393. p := &UpdateAutoScaleVmGroupParams{}
  2394. p.p = make(map[string]interface{})
  2395. p.p["id"] = id
  2396. return p
  2397. }
  2398. // Updates an existing autoscale vm group.
  2399. func (s *AutoScaleService) UpdateAutoScaleVmGroup(p *UpdateAutoScaleVmGroupParams) (*UpdateAutoScaleVmGroupResponse, error) {
  2400. resp, err := s.cs.newRequest("updateAutoScaleVmGroup", p.toURLValues())
  2401. if err != nil {
  2402. return nil, err
  2403. }
  2404. var r UpdateAutoScaleVmGroupResponse
  2405. if err := json.Unmarshal(resp, &r); err != nil {
  2406. return nil, err
  2407. }
  2408. // If we have a async client, we need to wait for the async result
  2409. if s.cs.async {
  2410. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  2411. if err != nil {
  2412. if err == AsyncTimeoutErr {
  2413. return &r, err
  2414. }
  2415. return nil, err
  2416. }
  2417. b, err = getRawValue(b)
  2418. if err != nil {
  2419. return nil, err
  2420. }
  2421. if err := json.Unmarshal(b, &r); err != nil {
  2422. return nil, err
  2423. }
  2424. }
  2425. return &r, nil
  2426. }
  2427. type UpdateAutoScaleVmGroupResponse struct {
  2428. JobID string `json:"jobid,omitempty"`
  2429. Account string `json:"account,omitempty"`
  2430. Domain string `json:"domain,omitempty"`
  2431. Domainid string `json:"domainid,omitempty"`
  2432. Fordisplay bool `json:"fordisplay,omitempty"`
  2433. Id string `json:"id,omitempty"`
  2434. Interval int `json:"interval,omitempty"`
  2435. Lbruleid string `json:"lbruleid,omitempty"`
  2436. Maxmembers int `json:"maxmembers,omitempty"`
  2437. Minmembers int `json:"minmembers,omitempty"`
  2438. Project string `json:"project,omitempty"`
  2439. Projectid string `json:"projectid,omitempty"`
  2440. Scaledownpolicies []string `json:"scaledownpolicies,omitempty"`
  2441. Scaleuppolicies []string `json:"scaleuppolicies,omitempty"`
  2442. State string `json:"state,omitempty"`
  2443. Vmprofileid string `json:"vmprofileid,omitempty"`
  2444. }