AccountService.go 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904
  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 CreateAccountParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *CreateAccountParams) toURLValues() url.Values {
  28. u := url.Values{}
  29. if p.p == nil {
  30. return u
  31. }
  32. if v, found := p.p["account"]; found {
  33. u.Set("account", v.(string))
  34. }
  35. if v, found := p.p["accountdetails"]; found {
  36. i := 0
  37. for k, vv := range v.(map[string]string) {
  38. u.Set(fmt.Sprintf("accountdetails[%d].key", i), k)
  39. u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv)
  40. i++
  41. }
  42. }
  43. if v, found := p.p["accountid"]; found {
  44. u.Set("accountid", v.(string))
  45. }
  46. if v, found := p.p["accounttype"]; found {
  47. vv := strconv.Itoa(v.(int))
  48. u.Set("accounttype", vv)
  49. }
  50. if v, found := p.p["domainid"]; found {
  51. u.Set("domainid", v.(string))
  52. }
  53. if v, found := p.p["email"]; found {
  54. u.Set("email", v.(string))
  55. }
  56. if v, found := p.p["firstname"]; found {
  57. u.Set("firstname", v.(string))
  58. }
  59. if v, found := p.p["lastname"]; found {
  60. u.Set("lastname", v.(string))
  61. }
  62. if v, found := p.p["networkdomain"]; found {
  63. u.Set("networkdomain", v.(string))
  64. }
  65. if v, found := p.p["password"]; found {
  66. u.Set("password", v.(string))
  67. }
  68. if v, found := p.p["timezone"]; found {
  69. u.Set("timezone", v.(string))
  70. }
  71. if v, found := p.p["userid"]; found {
  72. u.Set("userid", v.(string))
  73. }
  74. if v, found := p.p["username"]; found {
  75. u.Set("username", v.(string))
  76. }
  77. return u
  78. }
  79. func (p *CreateAccountParams) SetAccount(v string) {
  80. if p.p == nil {
  81. p.p = make(map[string]interface{})
  82. }
  83. p.p["account"] = v
  84. return
  85. }
  86. func (p *CreateAccountParams) SetAccountdetails(v map[string]string) {
  87. if p.p == nil {
  88. p.p = make(map[string]interface{})
  89. }
  90. p.p["accountdetails"] = v
  91. return
  92. }
  93. func (p *CreateAccountParams) SetAccountid(v string) {
  94. if p.p == nil {
  95. p.p = make(map[string]interface{})
  96. }
  97. p.p["accountid"] = v
  98. return
  99. }
  100. func (p *CreateAccountParams) SetAccounttype(v int) {
  101. if p.p == nil {
  102. p.p = make(map[string]interface{})
  103. }
  104. p.p["accounttype"] = v
  105. return
  106. }
  107. func (p *CreateAccountParams) SetDomainid(v string) {
  108. if p.p == nil {
  109. p.p = make(map[string]interface{})
  110. }
  111. p.p["domainid"] = v
  112. return
  113. }
  114. func (p *CreateAccountParams) SetEmail(v string) {
  115. if p.p == nil {
  116. p.p = make(map[string]interface{})
  117. }
  118. p.p["email"] = v
  119. return
  120. }
  121. func (p *CreateAccountParams) SetFirstname(v string) {
  122. if p.p == nil {
  123. p.p = make(map[string]interface{})
  124. }
  125. p.p["firstname"] = v
  126. return
  127. }
  128. func (p *CreateAccountParams) SetLastname(v string) {
  129. if p.p == nil {
  130. p.p = make(map[string]interface{})
  131. }
  132. p.p["lastname"] = v
  133. return
  134. }
  135. func (p *CreateAccountParams) SetNetworkdomain(v string) {
  136. if p.p == nil {
  137. p.p = make(map[string]interface{})
  138. }
  139. p.p["networkdomain"] = v
  140. return
  141. }
  142. func (p *CreateAccountParams) SetPassword(v string) {
  143. if p.p == nil {
  144. p.p = make(map[string]interface{})
  145. }
  146. p.p["password"] = v
  147. return
  148. }
  149. func (p *CreateAccountParams) SetTimezone(v string) {
  150. if p.p == nil {
  151. p.p = make(map[string]interface{})
  152. }
  153. p.p["timezone"] = v
  154. return
  155. }
  156. func (p *CreateAccountParams) SetUserid(v string) {
  157. if p.p == nil {
  158. p.p = make(map[string]interface{})
  159. }
  160. p.p["userid"] = v
  161. return
  162. }
  163. func (p *CreateAccountParams) SetUsername(v string) {
  164. if p.p == nil {
  165. p.p = make(map[string]interface{})
  166. }
  167. p.p["username"] = v
  168. return
  169. }
  170. // You should always use this function to get a new CreateAccountParams instance,
  171. // as then you are sure you have configured all required params
  172. func (s *AccountService) NewCreateAccountParams(accounttype int, email string, firstname string, lastname string, password string, username string) *CreateAccountParams {
  173. p := &CreateAccountParams{}
  174. p.p = make(map[string]interface{})
  175. p.p["accounttype"] = accounttype
  176. p.p["email"] = email
  177. p.p["firstname"] = firstname
  178. p.p["lastname"] = lastname
  179. p.p["password"] = password
  180. p.p["username"] = username
  181. return p
  182. }
  183. // Creates an account
  184. func (s *AccountService) CreateAccount(p *CreateAccountParams) (*CreateAccountResponse, error) {
  185. resp, err := s.cs.newRequest("createAccount", p.toURLValues())
  186. if err != nil {
  187. return nil, err
  188. }
  189. var r CreateAccountResponse
  190. if err := json.Unmarshal(resp, &r); err != nil {
  191. return nil, err
  192. }
  193. return &r, nil
  194. }
  195. type CreateAccountResponse struct {
  196. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  197. Accounttype int `json:"accounttype,omitempty"`
  198. Cpuavailable string `json:"cpuavailable,omitempty"`
  199. Cpulimit string `json:"cpulimit,omitempty"`
  200. Cputotal int64 `json:"cputotal,omitempty"`
  201. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  202. Domain string `json:"domain,omitempty"`
  203. Domainid string `json:"domainid,omitempty"`
  204. Groups []string `json:"groups,omitempty"`
  205. Id string `json:"id,omitempty"`
  206. Ipavailable string `json:"ipavailable,omitempty"`
  207. Iplimit string `json:"iplimit,omitempty"`
  208. Iptotal int64 `json:"iptotal,omitempty"`
  209. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  210. Isdefault bool `json:"isdefault,omitempty"`
  211. Memoryavailable string `json:"memoryavailable,omitempty"`
  212. Memorylimit string `json:"memorylimit,omitempty"`
  213. Memorytotal int64 `json:"memorytotal,omitempty"`
  214. Name string `json:"name,omitempty"`
  215. Networkavailable string `json:"networkavailable,omitempty"`
  216. Networkdomain string `json:"networkdomain,omitempty"`
  217. Networklimit string `json:"networklimit,omitempty"`
  218. Networktotal int64 `json:"networktotal,omitempty"`
  219. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  220. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  221. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  222. Projectavailable string `json:"projectavailable,omitempty"`
  223. Projectlimit string `json:"projectlimit,omitempty"`
  224. Projecttotal int64 `json:"projecttotal,omitempty"`
  225. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  226. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  227. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  228. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  229. Sentbytes int64 `json:"sentbytes,omitempty"`
  230. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  231. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  232. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  233. State string `json:"state,omitempty"`
  234. Templateavailable string `json:"templateavailable,omitempty"`
  235. Templatelimit string `json:"templatelimit,omitempty"`
  236. Templatetotal int64 `json:"templatetotal,omitempty"`
  237. User []struct {
  238. Account string `json:"account,omitempty"`
  239. Accountid string `json:"accountid,omitempty"`
  240. Accounttype int `json:"accounttype,omitempty"`
  241. Apikey string `json:"apikey,omitempty"`
  242. Created string `json:"created,omitempty"`
  243. Domain string `json:"domain,omitempty"`
  244. Domainid string `json:"domainid,omitempty"`
  245. Email string `json:"email,omitempty"`
  246. Firstname string `json:"firstname,omitempty"`
  247. Id string `json:"id,omitempty"`
  248. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  249. Isdefault bool `json:"isdefault,omitempty"`
  250. Lastname string `json:"lastname,omitempty"`
  251. Secretkey string `json:"secretkey,omitempty"`
  252. State string `json:"state,omitempty"`
  253. Timezone string `json:"timezone,omitempty"`
  254. Username string `json:"username,omitempty"`
  255. } `json:"user,omitempty"`
  256. Vmavailable string `json:"vmavailable,omitempty"`
  257. Vmlimit string `json:"vmlimit,omitempty"`
  258. Vmrunning int `json:"vmrunning,omitempty"`
  259. Vmstopped int `json:"vmstopped,omitempty"`
  260. Vmtotal int64 `json:"vmtotal,omitempty"`
  261. Volumeavailable string `json:"volumeavailable,omitempty"`
  262. Volumelimit string `json:"volumelimit,omitempty"`
  263. Volumetotal int64 `json:"volumetotal,omitempty"`
  264. Vpcavailable string `json:"vpcavailable,omitempty"`
  265. Vpclimit string `json:"vpclimit,omitempty"`
  266. Vpctotal int64 `json:"vpctotal,omitempty"`
  267. }
  268. type DeleteAccountParams struct {
  269. p map[string]interface{}
  270. }
  271. func (p *DeleteAccountParams) toURLValues() url.Values {
  272. u := url.Values{}
  273. if p.p == nil {
  274. return u
  275. }
  276. if v, found := p.p["id"]; found {
  277. u.Set("id", v.(string))
  278. }
  279. return u
  280. }
  281. func (p *DeleteAccountParams) SetId(v string) {
  282. if p.p == nil {
  283. p.p = make(map[string]interface{})
  284. }
  285. p.p["id"] = v
  286. return
  287. }
  288. // You should always use this function to get a new DeleteAccountParams instance,
  289. // as then you are sure you have configured all required params
  290. func (s *AccountService) NewDeleteAccountParams(id string) *DeleteAccountParams {
  291. p := &DeleteAccountParams{}
  292. p.p = make(map[string]interface{})
  293. p.p["id"] = id
  294. return p
  295. }
  296. // Deletes a account, and all users associated with this account
  297. func (s *AccountService) DeleteAccount(p *DeleteAccountParams) (*DeleteAccountResponse, error) {
  298. resp, err := s.cs.newRequest("deleteAccount", p.toURLValues())
  299. if err != nil {
  300. return nil, err
  301. }
  302. var r DeleteAccountResponse
  303. if err := json.Unmarshal(resp, &r); err != nil {
  304. return nil, err
  305. }
  306. // If we have a async client, we need to wait for the async result
  307. if s.cs.async {
  308. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  309. if err != nil {
  310. if err == AsyncTimeoutErr {
  311. return &r, err
  312. }
  313. return nil, err
  314. }
  315. if err := json.Unmarshal(b, &r); err != nil {
  316. return nil, err
  317. }
  318. }
  319. return &r, nil
  320. }
  321. type DeleteAccountResponse struct {
  322. JobID string `json:"jobid,omitempty"`
  323. Displaytext string `json:"displaytext,omitempty"`
  324. Success bool `json:"success,omitempty"`
  325. }
  326. type UpdateAccountParams struct {
  327. p map[string]interface{}
  328. }
  329. func (p *UpdateAccountParams) toURLValues() url.Values {
  330. u := url.Values{}
  331. if p.p == nil {
  332. return u
  333. }
  334. if v, found := p.p["account"]; found {
  335. u.Set("account", v.(string))
  336. }
  337. if v, found := p.p["accountdetails"]; found {
  338. i := 0
  339. for k, vv := range v.(map[string]string) {
  340. u.Set(fmt.Sprintf("accountdetails[%d].key", i), k)
  341. u.Set(fmt.Sprintf("accountdetails[%d].value", i), vv)
  342. i++
  343. }
  344. }
  345. if v, found := p.p["domainid"]; found {
  346. u.Set("domainid", v.(string))
  347. }
  348. if v, found := p.p["id"]; found {
  349. u.Set("id", v.(string))
  350. }
  351. if v, found := p.p["networkdomain"]; found {
  352. u.Set("networkdomain", v.(string))
  353. }
  354. if v, found := p.p["newname"]; found {
  355. u.Set("newname", v.(string))
  356. }
  357. return u
  358. }
  359. func (p *UpdateAccountParams) SetAccount(v string) {
  360. if p.p == nil {
  361. p.p = make(map[string]interface{})
  362. }
  363. p.p["account"] = v
  364. return
  365. }
  366. func (p *UpdateAccountParams) SetAccountdetails(v map[string]string) {
  367. if p.p == nil {
  368. p.p = make(map[string]interface{})
  369. }
  370. p.p["accountdetails"] = v
  371. return
  372. }
  373. func (p *UpdateAccountParams) SetDomainid(v string) {
  374. if p.p == nil {
  375. p.p = make(map[string]interface{})
  376. }
  377. p.p["domainid"] = v
  378. return
  379. }
  380. func (p *UpdateAccountParams) SetId(v string) {
  381. if p.p == nil {
  382. p.p = make(map[string]interface{})
  383. }
  384. p.p["id"] = v
  385. return
  386. }
  387. func (p *UpdateAccountParams) SetNetworkdomain(v string) {
  388. if p.p == nil {
  389. p.p = make(map[string]interface{})
  390. }
  391. p.p["networkdomain"] = v
  392. return
  393. }
  394. func (p *UpdateAccountParams) SetNewname(v string) {
  395. if p.p == nil {
  396. p.p = make(map[string]interface{})
  397. }
  398. p.p["newname"] = v
  399. return
  400. }
  401. // You should always use this function to get a new UpdateAccountParams instance,
  402. // as then you are sure you have configured all required params
  403. func (s *AccountService) NewUpdateAccountParams(newname string) *UpdateAccountParams {
  404. p := &UpdateAccountParams{}
  405. p.p = make(map[string]interface{})
  406. p.p["newname"] = newname
  407. return p
  408. }
  409. // Updates account information for the authenticated user
  410. func (s *AccountService) UpdateAccount(p *UpdateAccountParams) (*UpdateAccountResponse, error) {
  411. resp, err := s.cs.newRequest("updateAccount", p.toURLValues())
  412. if err != nil {
  413. return nil, err
  414. }
  415. var r UpdateAccountResponse
  416. if err := json.Unmarshal(resp, &r); err != nil {
  417. return nil, err
  418. }
  419. return &r, nil
  420. }
  421. type UpdateAccountResponse struct {
  422. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  423. Accounttype int `json:"accounttype,omitempty"`
  424. Cpuavailable string `json:"cpuavailable,omitempty"`
  425. Cpulimit string `json:"cpulimit,omitempty"`
  426. Cputotal int64 `json:"cputotal,omitempty"`
  427. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  428. Domain string `json:"domain,omitempty"`
  429. Domainid string `json:"domainid,omitempty"`
  430. Groups []string `json:"groups,omitempty"`
  431. Id string `json:"id,omitempty"`
  432. Ipavailable string `json:"ipavailable,omitempty"`
  433. Iplimit string `json:"iplimit,omitempty"`
  434. Iptotal int64 `json:"iptotal,omitempty"`
  435. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  436. Isdefault bool `json:"isdefault,omitempty"`
  437. Memoryavailable string `json:"memoryavailable,omitempty"`
  438. Memorylimit string `json:"memorylimit,omitempty"`
  439. Memorytotal int64 `json:"memorytotal,omitempty"`
  440. Name string `json:"name,omitempty"`
  441. Networkavailable string `json:"networkavailable,omitempty"`
  442. Networkdomain string `json:"networkdomain,omitempty"`
  443. Networklimit string `json:"networklimit,omitempty"`
  444. Networktotal int64 `json:"networktotal,omitempty"`
  445. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  446. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  447. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  448. Projectavailable string `json:"projectavailable,omitempty"`
  449. Projectlimit string `json:"projectlimit,omitempty"`
  450. Projecttotal int64 `json:"projecttotal,omitempty"`
  451. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  452. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  453. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  454. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  455. Sentbytes int64 `json:"sentbytes,omitempty"`
  456. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  457. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  458. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  459. State string `json:"state,omitempty"`
  460. Templateavailable string `json:"templateavailable,omitempty"`
  461. Templatelimit string `json:"templatelimit,omitempty"`
  462. Templatetotal int64 `json:"templatetotal,omitempty"`
  463. User []struct {
  464. Account string `json:"account,omitempty"`
  465. Accountid string `json:"accountid,omitempty"`
  466. Accounttype int `json:"accounttype,omitempty"`
  467. Apikey string `json:"apikey,omitempty"`
  468. Created string `json:"created,omitempty"`
  469. Domain string `json:"domain,omitempty"`
  470. Domainid string `json:"domainid,omitempty"`
  471. Email string `json:"email,omitempty"`
  472. Firstname string `json:"firstname,omitempty"`
  473. Id string `json:"id,omitempty"`
  474. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  475. Isdefault bool `json:"isdefault,omitempty"`
  476. Lastname string `json:"lastname,omitempty"`
  477. Secretkey string `json:"secretkey,omitempty"`
  478. State string `json:"state,omitempty"`
  479. Timezone string `json:"timezone,omitempty"`
  480. Username string `json:"username,omitempty"`
  481. } `json:"user,omitempty"`
  482. Vmavailable string `json:"vmavailable,omitempty"`
  483. Vmlimit string `json:"vmlimit,omitempty"`
  484. Vmrunning int `json:"vmrunning,omitempty"`
  485. Vmstopped int `json:"vmstopped,omitempty"`
  486. Vmtotal int64 `json:"vmtotal,omitempty"`
  487. Volumeavailable string `json:"volumeavailable,omitempty"`
  488. Volumelimit string `json:"volumelimit,omitempty"`
  489. Volumetotal int64 `json:"volumetotal,omitempty"`
  490. Vpcavailable string `json:"vpcavailable,omitempty"`
  491. Vpclimit string `json:"vpclimit,omitempty"`
  492. Vpctotal int64 `json:"vpctotal,omitempty"`
  493. }
  494. type DisableAccountParams struct {
  495. p map[string]interface{}
  496. }
  497. func (p *DisableAccountParams) toURLValues() url.Values {
  498. u := url.Values{}
  499. if p.p == nil {
  500. return u
  501. }
  502. if v, found := p.p["account"]; found {
  503. u.Set("account", v.(string))
  504. }
  505. if v, found := p.p["domainid"]; found {
  506. u.Set("domainid", v.(string))
  507. }
  508. if v, found := p.p["id"]; found {
  509. u.Set("id", v.(string))
  510. }
  511. if v, found := p.p["lock"]; found {
  512. vv := strconv.FormatBool(v.(bool))
  513. u.Set("lock", vv)
  514. }
  515. return u
  516. }
  517. func (p *DisableAccountParams) SetAccount(v string) {
  518. if p.p == nil {
  519. p.p = make(map[string]interface{})
  520. }
  521. p.p["account"] = v
  522. return
  523. }
  524. func (p *DisableAccountParams) SetDomainid(v string) {
  525. if p.p == nil {
  526. p.p = make(map[string]interface{})
  527. }
  528. p.p["domainid"] = v
  529. return
  530. }
  531. func (p *DisableAccountParams) SetId(v string) {
  532. if p.p == nil {
  533. p.p = make(map[string]interface{})
  534. }
  535. p.p["id"] = v
  536. return
  537. }
  538. func (p *DisableAccountParams) SetLock(v bool) {
  539. if p.p == nil {
  540. p.p = make(map[string]interface{})
  541. }
  542. p.p["lock"] = v
  543. return
  544. }
  545. // You should always use this function to get a new DisableAccountParams instance,
  546. // as then you are sure you have configured all required params
  547. func (s *AccountService) NewDisableAccountParams(lock bool) *DisableAccountParams {
  548. p := &DisableAccountParams{}
  549. p.p = make(map[string]interface{})
  550. p.p["lock"] = lock
  551. return p
  552. }
  553. // Disables an account
  554. func (s *AccountService) DisableAccount(p *DisableAccountParams) (*DisableAccountResponse, error) {
  555. resp, err := s.cs.newRequest("disableAccount", p.toURLValues())
  556. if err != nil {
  557. return nil, err
  558. }
  559. var r DisableAccountResponse
  560. if err := json.Unmarshal(resp, &r); err != nil {
  561. return nil, err
  562. }
  563. // If we have a async client, we need to wait for the async result
  564. if s.cs.async {
  565. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  566. if err != nil {
  567. if err == AsyncTimeoutErr {
  568. return &r, err
  569. }
  570. return nil, err
  571. }
  572. b, err = getRawValue(b)
  573. if err != nil {
  574. return nil, err
  575. }
  576. if err := json.Unmarshal(b, &r); err != nil {
  577. return nil, err
  578. }
  579. }
  580. return &r, nil
  581. }
  582. type DisableAccountResponse struct {
  583. JobID string `json:"jobid,omitempty"`
  584. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  585. Accounttype int `json:"accounttype,omitempty"`
  586. Cpuavailable string `json:"cpuavailable,omitempty"`
  587. Cpulimit string `json:"cpulimit,omitempty"`
  588. Cputotal int64 `json:"cputotal,omitempty"`
  589. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  590. Domain string `json:"domain,omitempty"`
  591. Domainid string `json:"domainid,omitempty"`
  592. Groups []string `json:"groups,omitempty"`
  593. Id string `json:"id,omitempty"`
  594. Ipavailable string `json:"ipavailable,omitempty"`
  595. Iplimit string `json:"iplimit,omitempty"`
  596. Iptotal int64 `json:"iptotal,omitempty"`
  597. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  598. Isdefault bool `json:"isdefault,omitempty"`
  599. Memoryavailable string `json:"memoryavailable,omitempty"`
  600. Memorylimit string `json:"memorylimit,omitempty"`
  601. Memorytotal int64 `json:"memorytotal,omitempty"`
  602. Name string `json:"name,omitempty"`
  603. Networkavailable string `json:"networkavailable,omitempty"`
  604. Networkdomain string `json:"networkdomain,omitempty"`
  605. Networklimit string `json:"networklimit,omitempty"`
  606. Networktotal int64 `json:"networktotal,omitempty"`
  607. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  608. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  609. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  610. Projectavailable string `json:"projectavailable,omitempty"`
  611. Projectlimit string `json:"projectlimit,omitempty"`
  612. Projecttotal int64 `json:"projecttotal,omitempty"`
  613. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  614. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  615. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  616. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  617. Sentbytes int64 `json:"sentbytes,omitempty"`
  618. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  619. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  620. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  621. State string `json:"state,omitempty"`
  622. Templateavailable string `json:"templateavailable,omitempty"`
  623. Templatelimit string `json:"templatelimit,omitempty"`
  624. Templatetotal int64 `json:"templatetotal,omitempty"`
  625. User []struct {
  626. Account string `json:"account,omitempty"`
  627. Accountid string `json:"accountid,omitempty"`
  628. Accounttype int `json:"accounttype,omitempty"`
  629. Apikey string `json:"apikey,omitempty"`
  630. Created string `json:"created,omitempty"`
  631. Domain string `json:"domain,omitempty"`
  632. Domainid string `json:"domainid,omitempty"`
  633. Email string `json:"email,omitempty"`
  634. Firstname string `json:"firstname,omitempty"`
  635. Id string `json:"id,omitempty"`
  636. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  637. Isdefault bool `json:"isdefault,omitempty"`
  638. Lastname string `json:"lastname,omitempty"`
  639. Secretkey string `json:"secretkey,omitempty"`
  640. State string `json:"state,omitempty"`
  641. Timezone string `json:"timezone,omitempty"`
  642. Username string `json:"username,omitempty"`
  643. } `json:"user,omitempty"`
  644. Vmavailable string `json:"vmavailable,omitempty"`
  645. Vmlimit string `json:"vmlimit,omitempty"`
  646. Vmrunning int `json:"vmrunning,omitempty"`
  647. Vmstopped int `json:"vmstopped,omitempty"`
  648. Vmtotal int64 `json:"vmtotal,omitempty"`
  649. Volumeavailable string `json:"volumeavailable,omitempty"`
  650. Volumelimit string `json:"volumelimit,omitempty"`
  651. Volumetotal int64 `json:"volumetotal,omitempty"`
  652. Vpcavailable string `json:"vpcavailable,omitempty"`
  653. Vpclimit string `json:"vpclimit,omitempty"`
  654. Vpctotal int64 `json:"vpctotal,omitempty"`
  655. }
  656. type EnableAccountParams struct {
  657. p map[string]interface{}
  658. }
  659. func (p *EnableAccountParams) toURLValues() url.Values {
  660. u := url.Values{}
  661. if p.p == nil {
  662. return u
  663. }
  664. if v, found := p.p["account"]; found {
  665. u.Set("account", v.(string))
  666. }
  667. if v, found := p.p["domainid"]; found {
  668. u.Set("domainid", v.(string))
  669. }
  670. if v, found := p.p["id"]; found {
  671. u.Set("id", v.(string))
  672. }
  673. return u
  674. }
  675. func (p *EnableAccountParams) SetAccount(v string) {
  676. if p.p == nil {
  677. p.p = make(map[string]interface{})
  678. }
  679. p.p["account"] = v
  680. return
  681. }
  682. func (p *EnableAccountParams) SetDomainid(v string) {
  683. if p.p == nil {
  684. p.p = make(map[string]interface{})
  685. }
  686. p.p["domainid"] = v
  687. return
  688. }
  689. func (p *EnableAccountParams) SetId(v string) {
  690. if p.p == nil {
  691. p.p = make(map[string]interface{})
  692. }
  693. p.p["id"] = v
  694. return
  695. }
  696. // You should always use this function to get a new EnableAccountParams instance,
  697. // as then you are sure you have configured all required params
  698. func (s *AccountService) NewEnableAccountParams() *EnableAccountParams {
  699. p := &EnableAccountParams{}
  700. p.p = make(map[string]interface{})
  701. return p
  702. }
  703. // Enables an account
  704. func (s *AccountService) EnableAccount(p *EnableAccountParams) (*EnableAccountResponse, error) {
  705. resp, err := s.cs.newRequest("enableAccount", p.toURLValues())
  706. if err != nil {
  707. return nil, err
  708. }
  709. var r EnableAccountResponse
  710. if err := json.Unmarshal(resp, &r); err != nil {
  711. return nil, err
  712. }
  713. return &r, nil
  714. }
  715. type EnableAccountResponse struct {
  716. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  717. Accounttype int `json:"accounttype,omitempty"`
  718. Cpuavailable string `json:"cpuavailable,omitempty"`
  719. Cpulimit string `json:"cpulimit,omitempty"`
  720. Cputotal int64 `json:"cputotal,omitempty"`
  721. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  722. Domain string `json:"domain,omitempty"`
  723. Domainid string `json:"domainid,omitempty"`
  724. Groups []string `json:"groups,omitempty"`
  725. Id string `json:"id,omitempty"`
  726. Ipavailable string `json:"ipavailable,omitempty"`
  727. Iplimit string `json:"iplimit,omitempty"`
  728. Iptotal int64 `json:"iptotal,omitempty"`
  729. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  730. Isdefault bool `json:"isdefault,omitempty"`
  731. Memoryavailable string `json:"memoryavailable,omitempty"`
  732. Memorylimit string `json:"memorylimit,omitempty"`
  733. Memorytotal int64 `json:"memorytotal,omitempty"`
  734. Name string `json:"name,omitempty"`
  735. Networkavailable string `json:"networkavailable,omitempty"`
  736. Networkdomain string `json:"networkdomain,omitempty"`
  737. Networklimit string `json:"networklimit,omitempty"`
  738. Networktotal int64 `json:"networktotal,omitempty"`
  739. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  740. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  741. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  742. Projectavailable string `json:"projectavailable,omitempty"`
  743. Projectlimit string `json:"projectlimit,omitempty"`
  744. Projecttotal int64 `json:"projecttotal,omitempty"`
  745. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  746. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  747. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  748. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  749. Sentbytes int64 `json:"sentbytes,omitempty"`
  750. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  751. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  752. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  753. State string `json:"state,omitempty"`
  754. Templateavailable string `json:"templateavailable,omitempty"`
  755. Templatelimit string `json:"templatelimit,omitempty"`
  756. Templatetotal int64 `json:"templatetotal,omitempty"`
  757. User []struct {
  758. Account string `json:"account,omitempty"`
  759. Accountid string `json:"accountid,omitempty"`
  760. Accounttype int `json:"accounttype,omitempty"`
  761. Apikey string `json:"apikey,omitempty"`
  762. Created string `json:"created,omitempty"`
  763. Domain string `json:"domain,omitempty"`
  764. Domainid string `json:"domainid,omitempty"`
  765. Email string `json:"email,omitempty"`
  766. Firstname string `json:"firstname,omitempty"`
  767. Id string `json:"id,omitempty"`
  768. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  769. Isdefault bool `json:"isdefault,omitempty"`
  770. Lastname string `json:"lastname,omitempty"`
  771. Secretkey string `json:"secretkey,omitempty"`
  772. State string `json:"state,omitempty"`
  773. Timezone string `json:"timezone,omitempty"`
  774. Username string `json:"username,omitempty"`
  775. } `json:"user,omitempty"`
  776. Vmavailable string `json:"vmavailable,omitempty"`
  777. Vmlimit string `json:"vmlimit,omitempty"`
  778. Vmrunning int `json:"vmrunning,omitempty"`
  779. Vmstopped int `json:"vmstopped,omitempty"`
  780. Vmtotal int64 `json:"vmtotal,omitempty"`
  781. Volumeavailable string `json:"volumeavailable,omitempty"`
  782. Volumelimit string `json:"volumelimit,omitempty"`
  783. Volumetotal int64 `json:"volumetotal,omitempty"`
  784. Vpcavailable string `json:"vpcavailable,omitempty"`
  785. Vpclimit string `json:"vpclimit,omitempty"`
  786. Vpctotal int64 `json:"vpctotal,omitempty"`
  787. }
  788. type LockAccountParams struct {
  789. p map[string]interface{}
  790. }
  791. func (p *LockAccountParams) toURLValues() url.Values {
  792. u := url.Values{}
  793. if p.p == nil {
  794. return u
  795. }
  796. if v, found := p.p["account"]; found {
  797. u.Set("account", v.(string))
  798. }
  799. if v, found := p.p["domainid"]; found {
  800. u.Set("domainid", v.(string))
  801. }
  802. return u
  803. }
  804. func (p *LockAccountParams) SetAccount(v string) {
  805. if p.p == nil {
  806. p.p = make(map[string]interface{})
  807. }
  808. p.p["account"] = v
  809. return
  810. }
  811. func (p *LockAccountParams) SetDomainid(v string) {
  812. if p.p == nil {
  813. p.p = make(map[string]interface{})
  814. }
  815. p.p["domainid"] = v
  816. return
  817. }
  818. // You should always use this function to get a new LockAccountParams instance,
  819. // as then you are sure you have configured all required params
  820. func (s *AccountService) NewLockAccountParams(account string, domainid string) *LockAccountParams {
  821. p := &LockAccountParams{}
  822. p.p = make(map[string]interface{})
  823. p.p["account"] = account
  824. p.p["domainid"] = domainid
  825. return p
  826. }
  827. // This deprecated function used to locks an account. Look for the API DisableAccount instead
  828. func (s *AccountService) LockAccount(p *LockAccountParams) (*LockAccountResponse, error) {
  829. resp, err := s.cs.newRequest("lockAccount", p.toURLValues())
  830. if err != nil {
  831. return nil, err
  832. }
  833. var r LockAccountResponse
  834. if err := json.Unmarshal(resp, &r); err != nil {
  835. return nil, err
  836. }
  837. return &r, nil
  838. }
  839. type LockAccountResponse struct {
  840. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  841. Accounttype int `json:"accounttype,omitempty"`
  842. Cpuavailable string `json:"cpuavailable,omitempty"`
  843. Cpulimit string `json:"cpulimit,omitempty"`
  844. Cputotal int64 `json:"cputotal,omitempty"`
  845. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  846. Domain string `json:"domain,omitempty"`
  847. Domainid string `json:"domainid,omitempty"`
  848. Groups []string `json:"groups,omitempty"`
  849. Id string `json:"id,omitempty"`
  850. Ipavailable string `json:"ipavailable,omitempty"`
  851. Iplimit string `json:"iplimit,omitempty"`
  852. Iptotal int64 `json:"iptotal,omitempty"`
  853. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  854. Isdefault bool `json:"isdefault,omitempty"`
  855. Memoryavailable string `json:"memoryavailable,omitempty"`
  856. Memorylimit string `json:"memorylimit,omitempty"`
  857. Memorytotal int64 `json:"memorytotal,omitempty"`
  858. Name string `json:"name,omitempty"`
  859. Networkavailable string `json:"networkavailable,omitempty"`
  860. Networkdomain string `json:"networkdomain,omitempty"`
  861. Networklimit string `json:"networklimit,omitempty"`
  862. Networktotal int64 `json:"networktotal,omitempty"`
  863. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  864. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  865. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  866. Projectavailable string `json:"projectavailable,omitempty"`
  867. Projectlimit string `json:"projectlimit,omitempty"`
  868. Projecttotal int64 `json:"projecttotal,omitempty"`
  869. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  870. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  871. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  872. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  873. Sentbytes int64 `json:"sentbytes,omitempty"`
  874. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  875. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  876. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  877. State string `json:"state,omitempty"`
  878. Templateavailable string `json:"templateavailable,omitempty"`
  879. Templatelimit string `json:"templatelimit,omitempty"`
  880. Templatetotal int64 `json:"templatetotal,omitempty"`
  881. User []struct {
  882. Account string `json:"account,omitempty"`
  883. Accountid string `json:"accountid,omitempty"`
  884. Accounttype int `json:"accounttype,omitempty"`
  885. Apikey string `json:"apikey,omitempty"`
  886. Created string `json:"created,omitempty"`
  887. Domain string `json:"domain,omitempty"`
  888. Domainid string `json:"domainid,omitempty"`
  889. Email string `json:"email,omitempty"`
  890. Firstname string `json:"firstname,omitempty"`
  891. Id string `json:"id,omitempty"`
  892. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  893. Isdefault bool `json:"isdefault,omitempty"`
  894. Lastname string `json:"lastname,omitempty"`
  895. Secretkey string `json:"secretkey,omitempty"`
  896. State string `json:"state,omitempty"`
  897. Timezone string `json:"timezone,omitempty"`
  898. Username string `json:"username,omitempty"`
  899. } `json:"user,omitempty"`
  900. Vmavailable string `json:"vmavailable,omitempty"`
  901. Vmlimit string `json:"vmlimit,omitempty"`
  902. Vmrunning int `json:"vmrunning,omitempty"`
  903. Vmstopped int `json:"vmstopped,omitempty"`
  904. Vmtotal int64 `json:"vmtotal,omitempty"`
  905. Volumeavailable string `json:"volumeavailable,omitempty"`
  906. Volumelimit string `json:"volumelimit,omitempty"`
  907. Volumetotal int64 `json:"volumetotal,omitempty"`
  908. Vpcavailable string `json:"vpcavailable,omitempty"`
  909. Vpclimit string `json:"vpclimit,omitempty"`
  910. Vpctotal int64 `json:"vpctotal,omitempty"`
  911. }
  912. type ListAccountsParams struct {
  913. p map[string]interface{}
  914. }
  915. func (p *ListAccountsParams) toURLValues() url.Values {
  916. u := url.Values{}
  917. if p.p == nil {
  918. return u
  919. }
  920. if v, found := p.p["accounttype"]; found {
  921. vv := strconv.FormatInt(v.(int64), 10)
  922. u.Set("accounttype", vv)
  923. }
  924. if v, found := p.p["domainid"]; found {
  925. u.Set("domainid", v.(string))
  926. }
  927. if v, found := p.p["id"]; found {
  928. u.Set("id", v.(string))
  929. }
  930. if v, found := p.p["iscleanuprequired"]; found {
  931. vv := strconv.FormatBool(v.(bool))
  932. u.Set("iscleanuprequired", vv)
  933. }
  934. if v, found := p.p["isrecursive"]; found {
  935. vv := strconv.FormatBool(v.(bool))
  936. u.Set("isrecursive", vv)
  937. }
  938. if v, found := p.p["keyword"]; found {
  939. u.Set("keyword", v.(string))
  940. }
  941. if v, found := p.p["listall"]; found {
  942. vv := strconv.FormatBool(v.(bool))
  943. u.Set("listall", vv)
  944. }
  945. if v, found := p.p["name"]; found {
  946. u.Set("name", v.(string))
  947. }
  948. if v, found := p.p["page"]; found {
  949. vv := strconv.Itoa(v.(int))
  950. u.Set("page", vv)
  951. }
  952. if v, found := p.p["pagesize"]; found {
  953. vv := strconv.Itoa(v.(int))
  954. u.Set("pagesize", vv)
  955. }
  956. if v, found := p.p["state"]; found {
  957. u.Set("state", v.(string))
  958. }
  959. return u
  960. }
  961. func (p *ListAccountsParams) SetAccounttype(v int64) {
  962. if p.p == nil {
  963. p.p = make(map[string]interface{})
  964. }
  965. p.p["accounttype"] = v
  966. return
  967. }
  968. func (p *ListAccountsParams) SetDomainid(v string) {
  969. if p.p == nil {
  970. p.p = make(map[string]interface{})
  971. }
  972. p.p["domainid"] = v
  973. return
  974. }
  975. func (p *ListAccountsParams) SetId(v string) {
  976. if p.p == nil {
  977. p.p = make(map[string]interface{})
  978. }
  979. p.p["id"] = v
  980. return
  981. }
  982. func (p *ListAccountsParams) SetIscleanuprequired(v bool) {
  983. if p.p == nil {
  984. p.p = make(map[string]interface{})
  985. }
  986. p.p["iscleanuprequired"] = v
  987. return
  988. }
  989. func (p *ListAccountsParams) SetIsrecursive(v bool) {
  990. if p.p == nil {
  991. p.p = make(map[string]interface{})
  992. }
  993. p.p["isrecursive"] = v
  994. return
  995. }
  996. func (p *ListAccountsParams) SetKeyword(v string) {
  997. if p.p == nil {
  998. p.p = make(map[string]interface{})
  999. }
  1000. p.p["keyword"] = v
  1001. return
  1002. }
  1003. func (p *ListAccountsParams) SetListall(v bool) {
  1004. if p.p == nil {
  1005. p.p = make(map[string]interface{})
  1006. }
  1007. p.p["listall"] = v
  1008. return
  1009. }
  1010. func (p *ListAccountsParams) SetName(v string) {
  1011. if p.p == nil {
  1012. p.p = make(map[string]interface{})
  1013. }
  1014. p.p["name"] = v
  1015. return
  1016. }
  1017. func (p *ListAccountsParams) SetPage(v int) {
  1018. if p.p == nil {
  1019. p.p = make(map[string]interface{})
  1020. }
  1021. p.p["page"] = v
  1022. return
  1023. }
  1024. func (p *ListAccountsParams) SetPagesize(v int) {
  1025. if p.p == nil {
  1026. p.p = make(map[string]interface{})
  1027. }
  1028. p.p["pagesize"] = v
  1029. return
  1030. }
  1031. func (p *ListAccountsParams) SetState(v string) {
  1032. if p.p == nil {
  1033. p.p = make(map[string]interface{})
  1034. }
  1035. p.p["state"] = v
  1036. return
  1037. }
  1038. // You should always use this function to get a new ListAccountsParams instance,
  1039. // as then you are sure you have configured all required params
  1040. func (s *AccountService) NewListAccountsParams() *ListAccountsParams {
  1041. p := &ListAccountsParams{}
  1042. p.p = make(map[string]interface{})
  1043. return p
  1044. }
  1045. // This is a courtesy helper function, which in some cases may not work as expected!
  1046. func (s *AccountService) GetAccountID(name string, opts ...OptionFunc) (string, int, error) {
  1047. p := &ListAccountsParams{}
  1048. p.p = make(map[string]interface{})
  1049. p.p["name"] = name
  1050. for _, fn := range opts {
  1051. if err := fn(s.cs, p); err != nil {
  1052. return "", -1, err
  1053. }
  1054. }
  1055. l, err := s.ListAccounts(p)
  1056. if err != nil {
  1057. return "", -1, err
  1058. }
  1059. if l.Count == 0 {
  1060. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  1061. }
  1062. if l.Count == 1 {
  1063. return l.Accounts[0].Id, l.Count, nil
  1064. }
  1065. if l.Count > 1 {
  1066. for _, v := range l.Accounts {
  1067. if v.Name == name {
  1068. return v.Id, l.Count, nil
  1069. }
  1070. }
  1071. }
  1072. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  1073. }
  1074. // This is a courtesy helper function, which in some cases may not work as expected!
  1075. func (s *AccountService) GetAccountByName(name string, opts ...OptionFunc) (*Account, int, error) {
  1076. id, count, err := s.GetAccountID(name, opts...)
  1077. if err != nil {
  1078. return nil, count, err
  1079. }
  1080. r, count, err := s.GetAccountByID(id, opts...)
  1081. if err != nil {
  1082. return nil, count, err
  1083. }
  1084. return r, count, nil
  1085. }
  1086. // This is a courtesy helper function, which in some cases may not work as expected!
  1087. func (s *AccountService) GetAccountByID(id string, opts ...OptionFunc) (*Account, int, error) {
  1088. p := &ListAccountsParams{}
  1089. p.p = make(map[string]interface{})
  1090. p.p["id"] = id
  1091. for _, fn := range opts {
  1092. if err := fn(s.cs, p); err != nil {
  1093. return nil, -1, err
  1094. }
  1095. }
  1096. l, err := s.ListAccounts(p)
  1097. if err != nil {
  1098. if strings.Contains(err.Error(), fmt.Sprintf(
  1099. "Invalid parameter id value=%s due to incorrect long value format, "+
  1100. "or entity does not exist", id)) {
  1101. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1102. }
  1103. return nil, -1, err
  1104. }
  1105. if l.Count == 0 {
  1106. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1107. }
  1108. if l.Count == 1 {
  1109. return l.Accounts[0], l.Count, nil
  1110. }
  1111. return nil, l.Count, fmt.Errorf("There is more then one result for Account UUID: %s!", id)
  1112. }
  1113. // Lists accounts and provides detailed account information for listed accounts
  1114. func (s *AccountService) ListAccounts(p *ListAccountsParams) (*ListAccountsResponse, error) {
  1115. resp, err := s.cs.newRequest("listAccounts", p.toURLValues())
  1116. if err != nil {
  1117. return nil, err
  1118. }
  1119. var r ListAccountsResponse
  1120. if err := json.Unmarshal(resp, &r); err != nil {
  1121. return nil, err
  1122. }
  1123. return &r, nil
  1124. }
  1125. type ListAccountsResponse struct {
  1126. Count int `json:"count"`
  1127. Accounts []*Account `json:"account"`
  1128. }
  1129. type Account struct {
  1130. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  1131. Accounttype int `json:"accounttype,omitempty"`
  1132. Cpuavailable string `json:"cpuavailable,omitempty"`
  1133. Cpulimit string `json:"cpulimit,omitempty"`
  1134. Cputotal int64 `json:"cputotal,omitempty"`
  1135. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  1136. Domain string `json:"domain,omitempty"`
  1137. Domainid string `json:"domainid,omitempty"`
  1138. Groups []string `json:"groups,omitempty"`
  1139. Id string `json:"id,omitempty"`
  1140. Ipavailable string `json:"ipavailable,omitempty"`
  1141. Iplimit string `json:"iplimit,omitempty"`
  1142. Iptotal int64 `json:"iptotal,omitempty"`
  1143. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  1144. Isdefault bool `json:"isdefault,omitempty"`
  1145. Memoryavailable string `json:"memoryavailable,omitempty"`
  1146. Memorylimit string `json:"memorylimit,omitempty"`
  1147. Memorytotal int64 `json:"memorytotal,omitempty"`
  1148. Name string `json:"name,omitempty"`
  1149. Networkavailable string `json:"networkavailable,omitempty"`
  1150. Networkdomain string `json:"networkdomain,omitempty"`
  1151. Networklimit string `json:"networklimit,omitempty"`
  1152. Networktotal int64 `json:"networktotal,omitempty"`
  1153. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  1154. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  1155. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  1156. Projectavailable string `json:"projectavailable,omitempty"`
  1157. Projectlimit string `json:"projectlimit,omitempty"`
  1158. Projecttotal int64 `json:"projecttotal,omitempty"`
  1159. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  1160. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  1161. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  1162. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  1163. Sentbytes int64 `json:"sentbytes,omitempty"`
  1164. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  1165. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  1166. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  1167. State string `json:"state,omitempty"`
  1168. Templateavailable string `json:"templateavailable,omitempty"`
  1169. Templatelimit string `json:"templatelimit,omitempty"`
  1170. Templatetotal int64 `json:"templatetotal,omitempty"`
  1171. User []struct {
  1172. Account string `json:"account,omitempty"`
  1173. Accountid string `json:"accountid,omitempty"`
  1174. Accounttype int `json:"accounttype,omitempty"`
  1175. Apikey string `json:"apikey,omitempty"`
  1176. Created string `json:"created,omitempty"`
  1177. Domain string `json:"domain,omitempty"`
  1178. Domainid string `json:"domainid,omitempty"`
  1179. Email string `json:"email,omitempty"`
  1180. Firstname string `json:"firstname,omitempty"`
  1181. Id string `json:"id,omitempty"`
  1182. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  1183. Isdefault bool `json:"isdefault,omitempty"`
  1184. Lastname string `json:"lastname,omitempty"`
  1185. Secretkey string `json:"secretkey,omitempty"`
  1186. State string `json:"state,omitempty"`
  1187. Timezone string `json:"timezone,omitempty"`
  1188. Username string `json:"username,omitempty"`
  1189. } `json:"user,omitempty"`
  1190. Vmavailable string `json:"vmavailable,omitempty"`
  1191. Vmlimit string `json:"vmlimit,omitempty"`
  1192. Vmrunning int `json:"vmrunning,omitempty"`
  1193. Vmstopped int `json:"vmstopped,omitempty"`
  1194. Vmtotal int64 `json:"vmtotal,omitempty"`
  1195. Volumeavailable string `json:"volumeavailable,omitempty"`
  1196. Volumelimit string `json:"volumelimit,omitempty"`
  1197. Volumetotal int64 `json:"volumetotal,omitempty"`
  1198. Vpcavailable string `json:"vpcavailable,omitempty"`
  1199. Vpclimit string `json:"vpclimit,omitempty"`
  1200. Vpctotal int64 `json:"vpctotal,omitempty"`
  1201. }
  1202. type MarkDefaultZoneForAccountParams struct {
  1203. p map[string]interface{}
  1204. }
  1205. func (p *MarkDefaultZoneForAccountParams) toURLValues() url.Values {
  1206. u := url.Values{}
  1207. if p.p == nil {
  1208. return u
  1209. }
  1210. if v, found := p.p["account"]; found {
  1211. u.Set("account", v.(string))
  1212. }
  1213. if v, found := p.p["domainid"]; found {
  1214. u.Set("domainid", v.(string))
  1215. }
  1216. if v, found := p.p["zoneid"]; found {
  1217. u.Set("zoneid", v.(string))
  1218. }
  1219. return u
  1220. }
  1221. func (p *MarkDefaultZoneForAccountParams) SetAccount(v string) {
  1222. if p.p == nil {
  1223. p.p = make(map[string]interface{})
  1224. }
  1225. p.p["account"] = v
  1226. return
  1227. }
  1228. func (p *MarkDefaultZoneForAccountParams) SetDomainid(v string) {
  1229. if p.p == nil {
  1230. p.p = make(map[string]interface{})
  1231. }
  1232. p.p["domainid"] = v
  1233. return
  1234. }
  1235. func (p *MarkDefaultZoneForAccountParams) SetZoneid(v string) {
  1236. if p.p == nil {
  1237. p.p = make(map[string]interface{})
  1238. }
  1239. p.p["zoneid"] = v
  1240. return
  1241. }
  1242. // You should always use this function to get a new MarkDefaultZoneForAccountParams instance,
  1243. // as then you are sure you have configured all required params
  1244. func (s *AccountService) NewMarkDefaultZoneForAccountParams(account string, domainid string, zoneid string) *MarkDefaultZoneForAccountParams {
  1245. p := &MarkDefaultZoneForAccountParams{}
  1246. p.p = make(map[string]interface{})
  1247. p.p["account"] = account
  1248. p.p["domainid"] = domainid
  1249. p.p["zoneid"] = zoneid
  1250. return p
  1251. }
  1252. // Marks a default zone for this account
  1253. func (s *AccountService) MarkDefaultZoneForAccount(p *MarkDefaultZoneForAccountParams) (*MarkDefaultZoneForAccountResponse, error) {
  1254. resp, err := s.cs.newRequest("markDefaultZoneForAccount", p.toURLValues())
  1255. if err != nil {
  1256. return nil, err
  1257. }
  1258. var r MarkDefaultZoneForAccountResponse
  1259. if err := json.Unmarshal(resp, &r); err != nil {
  1260. return nil, err
  1261. }
  1262. // If we have a async client, we need to wait for the async result
  1263. if s.cs.async {
  1264. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1265. if err != nil {
  1266. if err == AsyncTimeoutErr {
  1267. return &r, err
  1268. }
  1269. return nil, err
  1270. }
  1271. b, err = getRawValue(b)
  1272. if err != nil {
  1273. return nil, err
  1274. }
  1275. if err := json.Unmarshal(b, &r); err != nil {
  1276. return nil, err
  1277. }
  1278. }
  1279. return &r, nil
  1280. }
  1281. type MarkDefaultZoneForAccountResponse struct {
  1282. JobID string `json:"jobid,omitempty"`
  1283. Accountdetails map[string]string `json:"accountdetails,omitempty"`
  1284. Accounttype int `json:"accounttype,omitempty"`
  1285. Cpuavailable string `json:"cpuavailable,omitempty"`
  1286. Cpulimit string `json:"cpulimit,omitempty"`
  1287. Cputotal int64 `json:"cputotal,omitempty"`
  1288. Defaultzoneid string `json:"defaultzoneid,omitempty"`
  1289. Domain string `json:"domain,omitempty"`
  1290. Domainid string `json:"domainid,omitempty"`
  1291. Groups []string `json:"groups,omitempty"`
  1292. Id string `json:"id,omitempty"`
  1293. Ipavailable string `json:"ipavailable,omitempty"`
  1294. Iplimit string `json:"iplimit,omitempty"`
  1295. Iptotal int64 `json:"iptotal,omitempty"`
  1296. Iscleanuprequired bool `json:"iscleanuprequired,omitempty"`
  1297. Isdefault bool `json:"isdefault,omitempty"`
  1298. Memoryavailable string `json:"memoryavailable,omitempty"`
  1299. Memorylimit string `json:"memorylimit,omitempty"`
  1300. Memorytotal int64 `json:"memorytotal,omitempty"`
  1301. Name string `json:"name,omitempty"`
  1302. Networkavailable string `json:"networkavailable,omitempty"`
  1303. Networkdomain string `json:"networkdomain,omitempty"`
  1304. Networklimit string `json:"networklimit,omitempty"`
  1305. Networktotal int64 `json:"networktotal,omitempty"`
  1306. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  1307. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  1308. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  1309. Projectavailable string `json:"projectavailable,omitempty"`
  1310. Projectlimit string `json:"projectlimit,omitempty"`
  1311. Projecttotal int64 `json:"projecttotal,omitempty"`
  1312. Receivedbytes int64 `json:"receivedbytes,omitempty"`
  1313. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  1314. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  1315. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  1316. Sentbytes int64 `json:"sentbytes,omitempty"`
  1317. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  1318. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  1319. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  1320. State string `json:"state,omitempty"`
  1321. Templateavailable string `json:"templateavailable,omitempty"`
  1322. Templatelimit string `json:"templatelimit,omitempty"`
  1323. Templatetotal int64 `json:"templatetotal,omitempty"`
  1324. User []struct {
  1325. Account string `json:"account,omitempty"`
  1326. Accountid string `json:"accountid,omitempty"`
  1327. Accounttype int `json:"accounttype,omitempty"`
  1328. Apikey string `json:"apikey,omitempty"`
  1329. Created string `json:"created,omitempty"`
  1330. Domain string `json:"domain,omitempty"`
  1331. Domainid string `json:"domainid,omitempty"`
  1332. Email string `json:"email,omitempty"`
  1333. Firstname string `json:"firstname,omitempty"`
  1334. Id string `json:"id,omitempty"`
  1335. Iscallerchilddomain bool `json:"iscallerchilddomain,omitempty"`
  1336. Isdefault bool `json:"isdefault,omitempty"`
  1337. Lastname string `json:"lastname,omitempty"`
  1338. Secretkey string `json:"secretkey,omitempty"`
  1339. State string `json:"state,omitempty"`
  1340. Timezone string `json:"timezone,omitempty"`
  1341. Username string `json:"username,omitempty"`
  1342. } `json:"user,omitempty"`
  1343. Vmavailable string `json:"vmavailable,omitempty"`
  1344. Vmlimit string `json:"vmlimit,omitempty"`
  1345. Vmrunning int `json:"vmrunning,omitempty"`
  1346. Vmstopped int `json:"vmstopped,omitempty"`
  1347. Vmtotal int64 `json:"vmtotal,omitempty"`
  1348. Volumeavailable string `json:"volumeavailable,omitempty"`
  1349. Volumelimit string `json:"volumelimit,omitempty"`
  1350. Volumetotal int64 `json:"volumetotal,omitempty"`
  1351. Vpcavailable string `json:"vpcavailable,omitempty"`
  1352. Vpclimit string `json:"vpclimit,omitempty"`
  1353. Vpctotal int64 `json:"vpctotal,omitempty"`
  1354. }
  1355. type AddAccountToProjectParams struct {
  1356. p map[string]interface{}
  1357. }
  1358. func (p *AddAccountToProjectParams) toURLValues() url.Values {
  1359. u := url.Values{}
  1360. if p.p == nil {
  1361. return u
  1362. }
  1363. if v, found := p.p["account"]; found {
  1364. u.Set("account", v.(string))
  1365. }
  1366. if v, found := p.p["email"]; found {
  1367. u.Set("email", v.(string))
  1368. }
  1369. if v, found := p.p["projectid"]; found {
  1370. u.Set("projectid", v.(string))
  1371. }
  1372. return u
  1373. }
  1374. func (p *AddAccountToProjectParams) SetAccount(v string) {
  1375. if p.p == nil {
  1376. p.p = make(map[string]interface{})
  1377. }
  1378. p.p["account"] = v
  1379. return
  1380. }
  1381. func (p *AddAccountToProjectParams) SetEmail(v string) {
  1382. if p.p == nil {
  1383. p.p = make(map[string]interface{})
  1384. }
  1385. p.p["email"] = v
  1386. return
  1387. }
  1388. func (p *AddAccountToProjectParams) SetProjectid(v string) {
  1389. if p.p == nil {
  1390. p.p = make(map[string]interface{})
  1391. }
  1392. p.p["projectid"] = v
  1393. return
  1394. }
  1395. // You should always use this function to get a new AddAccountToProjectParams instance,
  1396. // as then you are sure you have configured all required params
  1397. func (s *AccountService) NewAddAccountToProjectParams(projectid string) *AddAccountToProjectParams {
  1398. p := &AddAccountToProjectParams{}
  1399. p.p = make(map[string]interface{})
  1400. p.p["projectid"] = projectid
  1401. return p
  1402. }
  1403. // Adds account to a project
  1404. func (s *AccountService) AddAccountToProject(p *AddAccountToProjectParams) (*AddAccountToProjectResponse, error) {
  1405. resp, err := s.cs.newRequest("addAccountToProject", p.toURLValues())
  1406. if err != nil {
  1407. return nil, err
  1408. }
  1409. var r AddAccountToProjectResponse
  1410. if err := json.Unmarshal(resp, &r); err != nil {
  1411. return nil, err
  1412. }
  1413. // If we have a async client, we need to wait for the async result
  1414. if s.cs.async {
  1415. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1416. if err != nil {
  1417. if err == AsyncTimeoutErr {
  1418. return &r, err
  1419. }
  1420. return nil, err
  1421. }
  1422. if err := json.Unmarshal(b, &r); err != nil {
  1423. return nil, err
  1424. }
  1425. }
  1426. return &r, nil
  1427. }
  1428. type AddAccountToProjectResponse struct {
  1429. JobID string `json:"jobid,omitempty"`
  1430. Displaytext string `json:"displaytext,omitempty"`
  1431. Success bool `json:"success,omitempty"`
  1432. }
  1433. type DeleteAccountFromProjectParams struct {
  1434. p map[string]interface{}
  1435. }
  1436. func (p *DeleteAccountFromProjectParams) toURLValues() url.Values {
  1437. u := url.Values{}
  1438. if p.p == nil {
  1439. return u
  1440. }
  1441. if v, found := p.p["account"]; found {
  1442. u.Set("account", v.(string))
  1443. }
  1444. if v, found := p.p["projectid"]; found {
  1445. u.Set("projectid", v.(string))
  1446. }
  1447. return u
  1448. }
  1449. func (p *DeleteAccountFromProjectParams) SetAccount(v string) {
  1450. if p.p == nil {
  1451. p.p = make(map[string]interface{})
  1452. }
  1453. p.p["account"] = v
  1454. return
  1455. }
  1456. func (p *DeleteAccountFromProjectParams) SetProjectid(v string) {
  1457. if p.p == nil {
  1458. p.p = make(map[string]interface{})
  1459. }
  1460. p.p["projectid"] = v
  1461. return
  1462. }
  1463. // You should always use this function to get a new DeleteAccountFromProjectParams instance,
  1464. // as then you are sure you have configured all required params
  1465. func (s *AccountService) NewDeleteAccountFromProjectParams(account string, projectid string) *DeleteAccountFromProjectParams {
  1466. p := &DeleteAccountFromProjectParams{}
  1467. p.p = make(map[string]interface{})
  1468. p.p["account"] = account
  1469. p.p["projectid"] = projectid
  1470. return p
  1471. }
  1472. // Deletes account from the project
  1473. func (s *AccountService) DeleteAccountFromProject(p *DeleteAccountFromProjectParams) (*DeleteAccountFromProjectResponse, error) {
  1474. resp, err := s.cs.newRequest("deleteAccountFromProject", p.toURLValues())
  1475. if err != nil {
  1476. return nil, err
  1477. }
  1478. var r DeleteAccountFromProjectResponse
  1479. if err := json.Unmarshal(resp, &r); err != nil {
  1480. return nil, err
  1481. }
  1482. // If we have a async client, we need to wait for the async result
  1483. if s.cs.async {
  1484. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1485. if err != nil {
  1486. if err == AsyncTimeoutErr {
  1487. return &r, err
  1488. }
  1489. return nil, err
  1490. }
  1491. if err := json.Unmarshal(b, &r); err != nil {
  1492. return nil, err
  1493. }
  1494. }
  1495. return &r, nil
  1496. }
  1497. type DeleteAccountFromProjectResponse struct {
  1498. JobID string `json:"jobid,omitempty"`
  1499. Displaytext string `json:"displaytext,omitempty"`
  1500. Success bool `json:"success,omitempty"`
  1501. }
  1502. type ListProjectAccountsParams struct {
  1503. p map[string]interface{}
  1504. }
  1505. func (p *ListProjectAccountsParams) toURLValues() url.Values {
  1506. u := url.Values{}
  1507. if p.p == nil {
  1508. return u
  1509. }
  1510. if v, found := p.p["account"]; found {
  1511. u.Set("account", v.(string))
  1512. }
  1513. if v, found := p.p["keyword"]; found {
  1514. u.Set("keyword", v.(string))
  1515. }
  1516. if v, found := p.p["page"]; found {
  1517. vv := strconv.Itoa(v.(int))
  1518. u.Set("page", vv)
  1519. }
  1520. if v, found := p.p["pagesize"]; found {
  1521. vv := strconv.Itoa(v.(int))
  1522. u.Set("pagesize", vv)
  1523. }
  1524. if v, found := p.p["projectid"]; found {
  1525. u.Set("projectid", v.(string))
  1526. }
  1527. if v, found := p.p["role"]; found {
  1528. u.Set("role", v.(string))
  1529. }
  1530. return u
  1531. }
  1532. func (p *ListProjectAccountsParams) SetAccount(v string) {
  1533. if p.p == nil {
  1534. p.p = make(map[string]interface{})
  1535. }
  1536. p.p["account"] = v
  1537. return
  1538. }
  1539. func (p *ListProjectAccountsParams) SetKeyword(v string) {
  1540. if p.p == nil {
  1541. p.p = make(map[string]interface{})
  1542. }
  1543. p.p["keyword"] = v
  1544. return
  1545. }
  1546. func (p *ListProjectAccountsParams) SetPage(v int) {
  1547. if p.p == nil {
  1548. p.p = make(map[string]interface{})
  1549. }
  1550. p.p["page"] = v
  1551. return
  1552. }
  1553. func (p *ListProjectAccountsParams) SetPagesize(v int) {
  1554. if p.p == nil {
  1555. p.p = make(map[string]interface{})
  1556. }
  1557. p.p["pagesize"] = v
  1558. return
  1559. }
  1560. func (p *ListProjectAccountsParams) SetProjectid(v string) {
  1561. if p.p == nil {
  1562. p.p = make(map[string]interface{})
  1563. }
  1564. p.p["projectid"] = v
  1565. return
  1566. }
  1567. func (p *ListProjectAccountsParams) SetRole(v string) {
  1568. if p.p == nil {
  1569. p.p = make(map[string]interface{})
  1570. }
  1571. p.p["role"] = v
  1572. return
  1573. }
  1574. // You should always use this function to get a new ListProjectAccountsParams instance,
  1575. // as then you are sure you have configured all required params
  1576. func (s *AccountService) NewListProjectAccountsParams(projectid string) *ListProjectAccountsParams {
  1577. p := &ListProjectAccountsParams{}
  1578. p.p = make(map[string]interface{})
  1579. p.p["projectid"] = projectid
  1580. return p
  1581. }
  1582. // This is a courtesy helper function, which in some cases may not work as expected!
  1583. func (s *AccountService) GetProjectAccountID(keyword string, projectid string, opts ...OptionFunc) (string, int, error) {
  1584. p := &ListProjectAccountsParams{}
  1585. p.p = make(map[string]interface{})
  1586. p.p["keyword"] = keyword
  1587. p.p["projectid"] = projectid
  1588. for _, fn := range opts {
  1589. if err := fn(s.cs, p); err != nil {
  1590. return "", -1, err
  1591. }
  1592. }
  1593. l, err := s.ListProjectAccounts(p)
  1594. if err != nil {
  1595. return "", -1, err
  1596. }
  1597. if l.Count == 0 {
  1598. return "", l.Count, fmt.Errorf("No match found for %s: %+v", keyword, l)
  1599. }
  1600. if l.Count == 1 {
  1601. return l.ProjectAccounts[0].Id, l.Count, nil
  1602. }
  1603. if l.Count > 1 {
  1604. for _, v := range l.ProjectAccounts {
  1605. if v.Name == keyword {
  1606. return v.Id, l.Count, nil
  1607. }
  1608. }
  1609. }
  1610. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", keyword, l)
  1611. }
  1612. // Lists project's accounts
  1613. func (s *AccountService) ListProjectAccounts(p *ListProjectAccountsParams) (*ListProjectAccountsResponse, error) {
  1614. resp, err := s.cs.newRequest("listProjectAccounts", p.toURLValues())
  1615. if err != nil {
  1616. return nil, err
  1617. }
  1618. var r ListProjectAccountsResponse
  1619. if err := json.Unmarshal(resp, &r); err != nil {
  1620. return nil, err
  1621. }
  1622. return &r, nil
  1623. }
  1624. type ListProjectAccountsResponse struct {
  1625. Count int `json:"count"`
  1626. ProjectAccounts []*ProjectAccount `json:"projectaccount"`
  1627. }
  1628. type ProjectAccount struct {
  1629. Account string `json:"account,omitempty"`
  1630. Cpuavailable string `json:"cpuavailable,omitempty"`
  1631. Cpulimit string `json:"cpulimit,omitempty"`
  1632. Cputotal int64 `json:"cputotal,omitempty"`
  1633. Displaytext string `json:"displaytext,omitempty"`
  1634. Domain string `json:"domain,omitempty"`
  1635. Domainid string `json:"domainid,omitempty"`
  1636. Id string `json:"id,omitempty"`
  1637. Ipavailable string `json:"ipavailable,omitempty"`
  1638. Iplimit string `json:"iplimit,omitempty"`
  1639. Iptotal int64 `json:"iptotal,omitempty"`
  1640. Memoryavailable string `json:"memoryavailable,omitempty"`
  1641. Memorylimit string `json:"memorylimit,omitempty"`
  1642. Memorytotal int64 `json:"memorytotal,omitempty"`
  1643. Name string `json:"name,omitempty"`
  1644. Networkavailable string `json:"networkavailable,omitempty"`
  1645. Networklimit string `json:"networklimit,omitempty"`
  1646. Networktotal int64 `json:"networktotal,omitempty"`
  1647. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  1648. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  1649. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  1650. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  1651. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  1652. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  1653. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  1654. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  1655. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  1656. State string `json:"state,omitempty"`
  1657. Tags []struct {
  1658. Account string `json:"account,omitempty"`
  1659. Customer string `json:"customer,omitempty"`
  1660. Domain string `json:"domain,omitempty"`
  1661. Domainid string `json:"domainid,omitempty"`
  1662. Key string `json:"key,omitempty"`
  1663. Project string `json:"project,omitempty"`
  1664. Projectid string `json:"projectid,omitempty"`
  1665. Resourceid string `json:"resourceid,omitempty"`
  1666. Resourcetype string `json:"resourcetype,omitempty"`
  1667. Value string `json:"value,omitempty"`
  1668. } `json:"tags,omitempty"`
  1669. Templateavailable string `json:"templateavailable,omitempty"`
  1670. Templatelimit string `json:"templatelimit,omitempty"`
  1671. Templatetotal int64 `json:"templatetotal,omitempty"`
  1672. Vmavailable string `json:"vmavailable,omitempty"`
  1673. Vmlimit string `json:"vmlimit,omitempty"`
  1674. Vmrunning int `json:"vmrunning,omitempty"`
  1675. Vmstopped int `json:"vmstopped,omitempty"`
  1676. Vmtotal int64 `json:"vmtotal,omitempty"`
  1677. Volumeavailable string `json:"volumeavailable,omitempty"`
  1678. Volumelimit string `json:"volumelimit,omitempty"`
  1679. Volumetotal int64 `json:"volumetotal,omitempty"`
  1680. Vpcavailable string `json:"vpcavailable,omitempty"`
  1681. Vpclimit string `json:"vpclimit,omitempty"`
  1682. Vpctotal int64 `json:"vpctotal,omitempty"`
  1683. }
  1684. type GetSolidFireAccountIdParams struct {
  1685. p map[string]interface{}
  1686. }
  1687. func (p *GetSolidFireAccountIdParams) toURLValues() url.Values {
  1688. u := url.Values{}
  1689. if p.p == nil {
  1690. return u
  1691. }
  1692. if v, found := p.p["accountid"]; found {
  1693. u.Set("accountid", v.(string))
  1694. }
  1695. if v, found := p.p["storageid"]; found {
  1696. u.Set("storageid", v.(string))
  1697. }
  1698. return u
  1699. }
  1700. func (p *GetSolidFireAccountIdParams) SetAccountid(v string) {
  1701. if p.p == nil {
  1702. p.p = make(map[string]interface{})
  1703. }
  1704. p.p["accountid"] = v
  1705. return
  1706. }
  1707. func (p *GetSolidFireAccountIdParams) SetStorageid(v string) {
  1708. if p.p == nil {
  1709. p.p = make(map[string]interface{})
  1710. }
  1711. p.p["storageid"] = v
  1712. return
  1713. }
  1714. // You should always use this function to get a new GetSolidFireAccountIdParams instance,
  1715. // as then you are sure you have configured all required params
  1716. func (s *AccountService) NewGetSolidFireAccountIdParams(accountid string, storageid string) *GetSolidFireAccountIdParams {
  1717. p := &GetSolidFireAccountIdParams{}
  1718. p.p = make(map[string]interface{})
  1719. p.p["accountid"] = accountid
  1720. p.p["storageid"] = storageid
  1721. return p
  1722. }
  1723. // Get SolidFire Account ID
  1724. func (s *AccountService) GetSolidFireAccountId(p *GetSolidFireAccountIdParams) (*GetSolidFireAccountIdResponse, error) {
  1725. resp, err := s.cs.newRequest("getSolidFireAccountId", p.toURLValues())
  1726. if err != nil {
  1727. return nil, err
  1728. }
  1729. var r GetSolidFireAccountIdResponse
  1730. if err := json.Unmarshal(resp, &r); err != nil {
  1731. return nil, err
  1732. }
  1733. return &r, nil
  1734. }
  1735. type GetSolidFireAccountIdResponse struct {
  1736. SolidFireAccountId int64 `json:"solidFireAccountId,omitempty"`
  1737. }