ProjectService.go 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342
  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 CreateProjectParams struct {
  25. p map[string]interface{}
  26. }
  27. func (p *CreateProjectParams) 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["displaytext"]; found {
  36. u.Set("displaytext", v.(string))
  37. }
  38. if v, found := p.p["domainid"]; found {
  39. u.Set("domainid", v.(string))
  40. }
  41. if v, found := p.p["name"]; found {
  42. u.Set("name", v.(string))
  43. }
  44. return u
  45. }
  46. func (p *CreateProjectParams) SetAccount(v string) {
  47. if p.p == nil {
  48. p.p = make(map[string]interface{})
  49. }
  50. p.p["account"] = v
  51. return
  52. }
  53. func (p *CreateProjectParams) SetDisplaytext(v string) {
  54. if p.p == nil {
  55. p.p = make(map[string]interface{})
  56. }
  57. p.p["displaytext"] = v
  58. return
  59. }
  60. func (p *CreateProjectParams) SetDomainid(v string) {
  61. if p.p == nil {
  62. p.p = make(map[string]interface{})
  63. }
  64. p.p["domainid"] = v
  65. return
  66. }
  67. func (p *CreateProjectParams) SetName(v string) {
  68. if p.p == nil {
  69. p.p = make(map[string]interface{})
  70. }
  71. p.p["name"] = v
  72. return
  73. }
  74. // You should always use this function to get a new CreateProjectParams instance,
  75. // as then you are sure you have configured all required params
  76. func (s *ProjectService) NewCreateProjectParams(displaytext string, name string) *CreateProjectParams {
  77. p := &CreateProjectParams{}
  78. p.p = make(map[string]interface{})
  79. p.p["displaytext"] = displaytext
  80. p.p["name"] = name
  81. return p
  82. }
  83. // Creates a project
  84. func (s *ProjectService) CreateProject(p *CreateProjectParams) (*CreateProjectResponse, error) {
  85. resp, err := s.cs.newRequest("createProject", p.toURLValues())
  86. if err != nil {
  87. return nil, err
  88. }
  89. var r CreateProjectResponse
  90. if err := json.Unmarshal(resp, &r); err != nil {
  91. return nil, err
  92. }
  93. // If we have a async client, we need to wait for the async result
  94. if s.cs.async {
  95. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  96. if err != nil {
  97. if err == AsyncTimeoutErr {
  98. return &r, err
  99. }
  100. return nil, err
  101. }
  102. b, err = getRawValue(b)
  103. if err != nil {
  104. return nil, err
  105. }
  106. if err := json.Unmarshal(b, &r); err != nil {
  107. return nil, err
  108. }
  109. }
  110. return &r, nil
  111. }
  112. type CreateProjectResponse struct {
  113. JobID string `json:"jobid,omitempty"`
  114. Account string `json:"account,omitempty"`
  115. Cpuavailable string `json:"cpuavailable,omitempty"`
  116. Cpulimit string `json:"cpulimit,omitempty"`
  117. Cputotal int64 `json:"cputotal,omitempty"`
  118. Displaytext string `json:"displaytext,omitempty"`
  119. Domain string `json:"domain,omitempty"`
  120. Domainid string `json:"domainid,omitempty"`
  121. Id string `json:"id,omitempty"`
  122. Ipavailable string `json:"ipavailable,omitempty"`
  123. Iplimit string `json:"iplimit,omitempty"`
  124. Iptotal int64 `json:"iptotal,omitempty"`
  125. Memoryavailable string `json:"memoryavailable,omitempty"`
  126. Memorylimit string `json:"memorylimit,omitempty"`
  127. Memorytotal int64 `json:"memorytotal,omitempty"`
  128. Name string `json:"name,omitempty"`
  129. Networkavailable string `json:"networkavailable,omitempty"`
  130. Networklimit string `json:"networklimit,omitempty"`
  131. Networktotal int64 `json:"networktotal,omitempty"`
  132. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  133. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  134. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  135. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  136. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  137. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  138. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  139. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  140. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  141. State string `json:"state,omitempty"`
  142. Tags []struct {
  143. Account string `json:"account,omitempty"`
  144. Customer string `json:"customer,omitempty"`
  145. Domain string `json:"domain,omitempty"`
  146. Domainid string `json:"domainid,omitempty"`
  147. Key string `json:"key,omitempty"`
  148. Project string `json:"project,omitempty"`
  149. Projectid string `json:"projectid,omitempty"`
  150. Resourceid string `json:"resourceid,omitempty"`
  151. Resourcetype string `json:"resourcetype,omitempty"`
  152. Value string `json:"value,omitempty"`
  153. } `json:"tags,omitempty"`
  154. Templateavailable string `json:"templateavailable,omitempty"`
  155. Templatelimit string `json:"templatelimit,omitempty"`
  156. Templatetotal int64 `json:"templatetotal,omitempty"`
  157. Vmavailable string `json:"vmavailable,omitempty"`
  158. Vmlimit string `json:"vmlimit,omitempty"`
  159. Vmrunning int `json:"vmrunning,omitempty"`
  160. Vmstopped int `json:"vmstopped,omitempty"`
  161. Vmtotal int64 `json:"vmtotal,omitempty"`
  162. Volumeavailable string `json:"volumeavailable,omitempty"`
  163. Volumelimit string `json:"volumelimit,omitempty"`
  164. Volumetotal int64 `json:"volumetotal,omitempty"`
  165. Vpcavailable string `json:"vpcavailable,omitempty"`
  166. Vpclimit string `json:"vpclimit,omitempty"`
  167. Vpctotal int64 `json:"vpctotal,omitempty"`
  168. }
  169. type DeleteProjectParams struct {
  170. p map[string]interface{}
  171. }
  172. func (p *DeleteProjectParams) toURLValues() url.Values {
  173. u := url.Values{}
  174. if p.p == nil {
  175. return u
  176. }
  177. if v, found := p.p["id"]; found {
  178. u.Set("id", v.(string))
  179. }
  180. return u
  181. }
  182. func (p *DeleteProjectParams) SetId(v string) {
  183. if p.p == nil {
  184. p.p = make(map[string]interface{})
  185. }
  186. p.p["id"] = v
  187. return
  188. }
  189. // You should always use this function to get a new DeleteProjectParams instance,
  190. // as then you are sure you have configured all required params
  191. func (s *ProjectService) NewDeleteProjectParams(id string) *DeleteProjectParams {
  192. p := &DeleteProjectParams{}
  193. p.p = make(map[string]interface{})
  194. p.p["id"] = id
  195. return p
  196. }
  197. // Deletes a project
  198. func (s *ProjectService) DeleteProject(p *DeleteProjectParams) (*DeleteProjectResponse, error) {
  199. resp, err := s.cs.newRequest("deleteProject", p.toURLValues())
  200. if err != nil {
  201. return nil, err
  202. }
  203. var r DeleteProjectResponse
  204. if err := json.Unmarshal(resp, &r); err != nil {
  205. return nil, err
  206. }
  207. // If we have a async client, we need to wait for the async result
  208. if s.cs.async {
  209. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  210. if err != nil {
  211. if err == AsyncTimeoutErr {
  212. return &r, err
  213. }
  214. return nil, err
  215. }
  216. if err := json.Unmarshal(b, &r); err != nil {
  217. return nil, err
  218. }
  219. }
  220. return &r, nil
  221. }
  222. type DeleteProjectResponse struct {
  223. JobID string `json:"jobid,omitempty"`
  224. Displaytext string `json:"displaytext,omitempty"`
  225. Success bool `json:"success,omitempty"`
  226. }
  227. type UpdateProjectParams struct {
  228. p map[string]interface{}
  229. }
  230. func (p *UpdateProjectParams) toURLValues() url.Values {
  231. u := url.Values{}
  232. if p.p == nil {
  233. return u
  234. }
  235. if v, found := p.p["account"]; found {
  236. u.Set("account", v.(string))
  237. }
  238. if v, found := p.p["displaytext"]; found {
  239. u.Set("displaytext", v.(string))
  240. }
  241. if v, found := p.p["id"]; found {
  242. u.Set("id", v.(string))
  243. }
  244. return u
  245. }
  246. func (p *UpdateProjectParams) SetAccount(v string) {
  247. if p.p == nil {
  248. p.p = make(map[string]interface{})
  249. }
  250. p.p["account"] = v
  251. return
  252. }
  253. func (p *UpdateProjectParams) SetDisplaytext(v string) {
  254. if p.p == nil {
  255. p.p = make(map[string]interface{})
  256. }
  257. p.p["displaytext"] = v
  258. return
  259. }
  260. func (p *UpdateProjectParams) SetId(v string) {
  261. if p.p == nil {
  262. p.p = make(map[string]interface{})
  263. }
  264. p.p["id"] = v
  265. return
  266. }
  267. // You should always use this function to get a new UpdateProjectParams instance,
  268. // as then you are sure you have configured all required params
  269. func (s *ProjectService) NewUpdateProjectParams(id string) *UpdateProjectParams {
  270. p := &UpdateProjectParams{}
  271. p.p = make(map[string]interface{})
  272. p.p["id"] = id
  273. return p
  274. }
  275. // Updates a project
  276. func (s *ProjectService) UpdateProject(p *UpdateProjectParams) (*UpdateProjectResponse, error) {
  277. resp, err := s.cs.newRequest("updateProject", p.toURLValues())
  278. if err != nil {
  279. return nil, err
  280. }
  281. var r UpdateProjectResponse
  282. if err := json.Unmarshal(resp, &r); err != nil {
  283. return nil, err
  284. }
  285. // If we have a async client, we need to wait for the async result
  286. if s.cs.async {
  287. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  288. if err != nil {
  289. if err == AsyncTimeoutErr {
  290. return &r, err
  291. }
  292. return nil, err
  293. }
  294. b, err = getRawValue(b)
  295. if err != nil {
  296. return nil, err
  297. }
  298. if err := json.Unmarshal(b, &r); err != nil {
  299. return nil, err
  300. }
  301. }
  302. return &r, nil
  303. }
  304. type UpdateProjectResponse struct {
  305. JobID string `json:"jobid,omitempty"`
  306. Account string `json:"account,omitempty"`
  307. Cpuavailable string `json:"cpuavailable,omitempty"`
  308. Cpulimit string `json:"cpulimit,omitempty"`
  309. Cputotal int64 `json:"cputotal,omitempty"`
  310. Displaytext string `json:"displaytext,omitempty"`
  311. Domain string `json:"domain,omitempty"`
  312. Domainid string `json:"domainid,omitempty"`
  313. Id string `json:"id,omitempty"`
  314. Ipavailable string `json:"ipavailable,omitempty"`
  315. Iplimit string `json:"iplimit,omitempty"`
  316. Iptotal int64 `json:"iptotal,omitempty"`
  317. Memoryavailable string `json:"memoryavailable,omitempty"`
  318. Memorylimit string `json:"memorylimit,omitempty"`
  319. Memorytotal int64 `json:"memorytotal,omitempty"`
  320. Name string `json:"name,omitempty"`
  321. Networkavailable string `json:"networkavailable,omitempty"`
  322. Networklimit string `json:"networklimit,omitempty"`
  323. Networktotal int64 `json:"networktotal,omitempty"`
  324. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  325. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  326. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  327. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  328. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  329. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  330. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  331. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  332. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  333. State string `json:"state,omitempty"`
  334. Tags []struct {
  335. Account string `json:"account,omitempty"`
  336. Customer string `json:"customer,omitempty"`
  337. Domain string `json:"domain,omitempty"`
  338. Domainid string `json:"domainid,omitempty"`
  339. Key string `json:"key,omitempty"`
  340. Project string `json:"project,omitempty"`
  341. Projectid string `json:"projectid,omitempty"`
  342. Resourceid string `json:"resourceid,omitempty"`
  343. Resourcetype string `json:"resourcetype,omitempty"`
  344. Value string `json:"value,omitempty"`
  345. } `json:"tags,omitempty"`
  346. Templateavailable string `json:"templateavailable,omitempty"`
  347. Templatelimit string `json:"templatelimit,omitempty"`
  348. Templatetotal int64 `json:"templatetotal,omitempty"`
  349. Vmavailable string `json:"vmavailable,omitempty"`
  350. Vmlimit string `json:"vmlimit,omitempty"`
  351. Vmrunning int `json:"vmrunning,omitempty"`
  352. Vmstopped int `json:"vmstopped,omitempty"`
  353. Vmtotal int64 `json:"vmtotal,omitempty"`
  354. Volumeavailable string `json:"volumeavailable,omitempty"`
  355. Volumelimit string `json:"volumelimit,omitempty"`
  356. Volumetotal int64 `json:"volumetotal,omitempty"`
  357. Vpcavailable string `json:"vpcavailable,omitempty"`
  358. Vpclimit string `json:"vpclimit,omitempty"`
  359. Vpctotal int64 `json:"vpctotal,omitempty"`
  360. }
  361. type ActivateProjectParams struct {
  362. p map[string]interface{}
  363. }
  364. func (p *ActivateProjectParams) toURLValues() url.Values {
  365. u := url.Values{}
  366. if p.p == nil {
  367. return u
  368. }
  369. if v, found := p.p["id"]; found {
  370. u.Set("id", v.(string))
  371. }
  372. return u
  373. }
  374. func (p *ActivateProjectParams) SetId(v string) {
  375. if p.p == nil {
  376. p.p = make(map[string]interface{})
  377. }
  378. p.p["id"] = v
  379. return
  380. }
  381. // You should always use this function to get a new ActivateProjectParams instance,
  382. // as then you are sure you have configured all required params
  383. func (s *ProjectService) NewActivateProjectParams(id string) *ActivateProjectParams {
  384. p := &ActivateProjectParams{}
  385. p.p = make(map[string]interface{})
  386. p.p["id"] = id
  387. return p
  388. }
  389. // Activates a project
  390. func (s *ProjectService) ActivateProject(p *ActivateProjectParams) (*ActivateProjectResponse, error) {
  391. resp, err := s.cs.newRequest("activateProject", p.toURLValues())
  392. if err != nil {
  393. return nil, err
  394. }
  395. var r ActivateProjectResponse
  396. if err := json.Unmarshal(resp, &r); err != nil {
  397. return nil, err
  398. }
  399. // If we have a async client, we need to wait for the async result
  400. if s.cs.async {
  401. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  402. if err != nil {
  403. if err == AsyncTimeoutErr {
  404. return &r, err
  405. }
  406. return nil, err
  407. }
  408. b, err = getRawValue(b)
  409. if err != nil {
  410. return nil, err
  411. }
  412. if err := json.Unmarshal(b, &r); err != nil {
  413. return nil, err
  414. }
  415. }
  416. return &r, nil
  417. }
  418. type ActivateProjectResponse struct {
  419. JobID string `json:"jobid,omitempty"`
  420. Account string `json:"account,omitempty"`
  421. Cpuavailable string `json:"cpuavailable,omitempty"`
  422. Cpulimit string `json:"cpulimit,omitempty"`
  423. Cputotal int64 `json:"cputotal,omitempty"`
  424. Displaytext string `json:"displaytext,omitempty"`
  425. Domain string `json:"domain,omitempty"`
  426. Domainid string `json:"domainid,omitempty"`
  427. Id string `json:"id,omitempty"`
  428. Ipavailable string `json:"ipavailable,omitempty"`
  429. Iplimit string `json:"iplimit,omitempty"`
  430. Iptotal int64 `json:"iptotal,omitempty"`
  431. Memoryavailable string `json:"memoryavailable,omitempty"`
  432. Memorylimit string `json:"memorylimit,omitempty"`
  433. Memorytotal int64 `json:"memorytotal,omitempty"`
  434. Name string `json:"name,omitempty"`
  435. Networkavailable string `json:"networkavailable,omitempty"`
  436. Networklimit string `json:"networklimit,omitempty"`
  437. Networktotal int64 `json:"networktotal,omitempty"`
  438. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  439. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  440. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  441. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  442. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  443. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  444. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  445. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  446. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  447. State string `json:"state,omitempty"`
  448. Tags []struct {
  449. Account string `json:"account,omitempty"`
  450. Customer string `json:"customer,omitempty"`
  451. Domain string `json:"domain,omitempty"`
  452. Domainid string `json:"domainid,omitempty"`
  453. Key string `json:"key,omitempty"`
  454. Project string `json:"project,omitempty"`
  455. Projectid string `json:"projectid,omitempty"`
  456. Resourceid string `json:"resourceid,omitempty"`
  457. Resourcetype string `json:"resourcetype,omitempty"`
  458. Value string `json:"value,omitempty"`
  459. } `json:"tags,omitempty"`
  460. Templateavailable string `json:"templateavailable,omitempty"`
  461. Templatelimit string `json:"templatelimit,omitempty"`
  462. Templatetotal int64 `json:"templatetotal,omitempty"`
  463. Vmavailable string `json:"vmavailable,omitempty"`
  464. Vmlimit string `json:"vmlimit,omitempty"`
  465. Vmrunning int `json:"vmrunning,omitempty"`
  466. Vmstopped int `json:"vmstopped,omitempty"`
  467. Vmtotal int64 `json:"vmtotal,omitempty"`
  468. Volumeavailable string `json:"volumeavailable,omitempty"`
  469. Volumelimit string `json:"volumelimit,omitempty"`
  470. Volumetotal int64 `json:"volumetotal,omitempty"`
  471. Vpcavailable string `json:"vpcavailable,omitempty"`
  472. Vpclimit string `json:"vpclimit,omitempty"`
  473. Vpctotal int64 `json:"vpctotal,omitempty"`
  474. }
  475. type SuspendProjectParams struct {
  476. p map[string]interface{}
  477. }
  478. func (p *SuspendProjectParams) toURLValues() url.Values {
  479. u := url.Values{}
  480. if p.p == nil {
  481. return u
  482. }
  483. if v, found := p.p["id"]; found {
  484. u.Set("id", v.(string))
  485. }
  486. return u
  487. }
  488. func (p *SuspendProjectParams) SetId(v string) {
  489. if p.p == nil {
  490. p.p = make(map[string]interface{})
  491. }
  492. p.p["id"] = v
  493. return
  494. }
  495. // You should always use this function to get a new SuspendProjectParams instance,
  496. // as then you are sure you have configured all required params
  497. func (s *ProjectService) NewSuspendProjectParams(id string) *SuspendProjectParams {
  498. p := &SuspendProjectParams{}
  499. p.p = make(map[string]interface{})
  500. p.p["id"] = id
  501. return p
  502. }
  503. // Suspends a project
  504. func (s *ProjectService) SuspendProject(p *SuspendProjectParams) (*SuspendProjectResponse, error) {
  505. resp, err := s.cs.newRequest("suspendProject", p.toURLValues())
  506. if err != nil {
  507. return nil, err
  508. }
  509. var r SuspendProjectResponse
  510. if err := json.Unmarshal(resp, &r); err != nil {
  511. return nil, err
  512. }
  513. // If we have a async client, we need to wait for the async result
  514. if s.cs.async {
  515. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  516. if err != nil {
  517. if err == AsyncTimeoutErr {
  518. return &r, err
  519. }
  520. return nil, err
  521. }
  522. b, err = getRawValue(b)
  523. if err != nil {
  524. return nil, err
  525. }
  526. if err := json.Unmarshal(b, &r); err != nil {
  527. return nil, err
  528. }
  529. }
  530. return &r, nil
  531. }
  532. type SuspendProjectResponse struct {
  533. JobID string `json:"jobid,omitempty"`
  534. Account string `json:"account,omitempty"`
  535. Cpuavailable string `json:"cpuavailable,omitempty"`
  536. Cpulimit string `json:"cpulimit,omitempty"`
  537. Cputotal int64 `json:"cputotal,omitempty"`
  538. Displaytext string `json:"displaytext,omitempty"`
  539. Domain string `json:"domain,omitempty"`
  540. Domainid string `json:"domainid,omitempty"`
  541. Id string `json:"id,omitempty"`
  542. Ipavailable string `json:"ipavailable,omitempty"`
  543. Iplimit string `json:"iplimit,omitempty"`
  544. Iptotal int64 `json:"iptotal,omitempty"`
  545. Memoryavailable string `json:"memoryavailable,omitempty"`
  546. Memorylimit string `json:"memorylimit,omitempty"`
  547. Memorytotal int64 `json:"memorytotal,omitempty"`
  548. Name string `json:"name,omitempty"`
  549. Networkavailable string `json:"networkavailable,omitempty"`
  550. Networklimit string `json:"networklimit,omitempty"`
  551. Networktotal int64 `json:"networktotal,omitempty"`
  552. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  553. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  554. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  555. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  556. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  557. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  558. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  559. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  560. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  561. State string `json:"state,omitempty"`
  562. Tags []struct {
  563. Account string `json:"account,omitempty"`
  564. Customer string `json:"customer,omitempty"`
  565. Domain string `json:"domain,omitempty"`
  566. Domainid string `json:"domainid,omitempty"`
  567. Key string `json:"key,omitempty"`
  568. Project string `json:"project,omitempty"`
  569. Projectid string `json:"projectid,omitempty"`
  570. Resourceid string `json:"resourceid,omitempty"`
  571. Resourcetype string `json:"resourcetype,omitempty"`
  572. Value string `json:"value,omitempty"`
  573. } `json:"tags,omitempty"`
  574. Templateavailable string `json:"templateavailable,omitempty"`
  575. Templatelimit string `json:"templatelimit,omitempty"`
  576. Templatetotal int64 `json:"templatetotal,omitempty"`
  577. Vmavailable string `json:"vmavailable,omitempty"`
  578. Vmlimit string `json:"vmlimit,omitempty"`
  579. Vmrunning int `json:"vmrunning,omitempty"`
  580. Vmstopped int `json:"vmstopped,omitempty"`
  581. Vmtotal int64 `json:"vmtotal,omitempty"`
  582. Volumeavailable string `json:"volumeavailable,omitempty"`
  583. Volumelimit string `json:"volumelimit,omitempty"`
  584. Volumetotal int64 `json:"volumetotal,omitempty"`
  585. Vpcavailable string `json:"vpcavailable,omitempty"`
  586. Vpclimit string `json:"vpclimit,omitempty"`
  587. Vpctotal int64 `json:"vpctotal,omitempty"`
  588. }
  589. type ListProjectsParams struct {
  590. p map[string]interface{}
  591. }
  592. func (p *ListProjectsParams) toURLValues() url.Values {
  593. u := url.Values{}
  594. if p.p == nil {
  595. return u
  596. }
  597. if v, found := p.p["account"]; found {
  598. u.Set("account", v.(string))
  599. }
  600. if v, found := p.p["displaytext"]; found {
  601. u.Set("displaytext", v.(string))
  602. }
  603. if v, found := p.p["domainid"]; found {
  604. u.Set("domainid", v.(string))
  605. }
  606. if v, found := p.p["id"]; found {
  607. u.Set("id", v.(string))
  608. }
  609. if v, found := p.p["isrecursive"]; found {
  610. vv := strconv.FormatBool(v.(bool))
  611. u.Set("isrecursive", vv)
  612. }
  613. if v, found := p.p["keyword"]; found {
  614. u.Set("keyword", v.(string))
  615. }
  616. if v, found := p.p["listall"]; found {
  617. vv := strconv.FormatBool(v.(bool))
  618. u.Set("listall", vv)
  619. }
  620. if v, found := p.p["name"]; found {
  621. u.Set("name", v.(string))
  622. }
  623. if v, found := p.p["page"]; found {
  624. vv := strconv.Itoa(v.(int))
  625. u.Set("page", vv)
  626. }
  627. if v, found := p.p["pagesize"]; found {
  628. vv := strconv.Itoa(v.(int))
  629. u.Set("pagesize", vv)
  630. }
  631. if v, found := p.p["state"]; found {
  632. u.Set("state", v.(string))
  633. }
  634. if v, found := p.p["tags"]; found {
  635. i := 0
  636. for k, vv := range v.(map[string]string) {
  637. u.Set(fmt.Sprintf("tags[%d].key", i), k)
  638. u.Set(fmt.Sprintf("tags[%d].value", i), vv)
  639. i++
  640. }
  641. }
  642. return u
  643. }
  644. func (p *ListProjectsParams) SetAccount(v string) {
  645. if p.p == nil {
  646. p.p = make(map[string]interface{})
  647. }
  648. p.p["account"] = v
  649. return
  650. }
  651. func (p *ListProjectsParams) SetDisplaytext(v string) {
  652. if p.p == nil {
  653. p.p = make(map[string]interface{})
  654. }
  655. p.p["displaytext"] = v
  656. return
  657. }
  658. func (p *ListProjectsParams) SetDomainid(v string) {
  659. if p.p == nil {
  660. p.p = make(map[string]interface{})
  661. }
  662. p.p["domainid"] = v
  663. return
  664. }
  665. func (p *ListProjectsParams) SetId(v string) {
  666. if p.p == nil {
  667. p.p = make(map[string]interface{})
  668. }
  669. p.p["id"] = v
  670. return
  671. }
  672. func (p *ListProjectsParams) SetIsrecursive(v bool) {
  673. if p.p == nil {
  674. p.p = make(map[string]interface{})
  675. }
  676. p.p["isrecursive"] = v
  677. return
  678. }
  679. func (p *ListProjectsParams) SetKeyword(v string) {
  680. if p.p == nil {
  681. p.p = make(map[string]interface{})
  682. }
  683. p.p["keyword"] = v
  684. return
  685. }
  686. func (p *ListProjectsParams) SetListall(v bool) {
  687. if p.p == nil {
  688. p.p = make(map[string]interface{})
  689. }
  690. p.p["listall"] = v
  691. return
  692. }
  693. func (p *ListProjectsParams) SetName(v string) {
  694. if p.p == nil {
  695. p.p = make(map[string]interface{})
  696. }
  697. p.p["name"] = v
  698. return
  699. }
  700. func (p *ListProjectsParams) SetPage(v int) {
  701. if p.p == nil {
  702. p.p = make(map[string]interface{})
  703. }
  704. p.p["page"] = v
  705. return
  706. }
  707. func (p *ListProjectsParams) SetPagesize(v int) {
  708. if p.p == nil {
  709. p.p = make(map[string]interface{})
  710. }
  711. p.p["pagesize"] = v
  712. return
  713. }
  714. func (p *ListProjectsParams) SetState(v string) {
  715. if p.p == nil {
  716. p.p = make(map[string]interface{})
  717. }
  718. p.p["state"] = v
  719. return
  720. }
  721. func (p *ListProjectsParams) SetTags(v map[string]string) {
  722. if p.p == nil {
  723. p.p = make(map[string]interface{})
  724. }
  725. p.p["tags"] = v
  726. return
  727. }
  728. // You should always use this function to get a new ListProjectsParams instance,
  729. // as then you are sure you have configured all required params
  730. func (s *ProjectService) NewListProjectsParams() *ListProjectsParams {
  731. p := &ListProjectsParams{}
  732. p.p = make(map[string]interface{})
  733. return p
  734. }
  735. // This is a courtesy helper function, which in some cases may not work as expected!
  736. func (s *ProjectService) GetProjectID(name string, opts ...OptionFunc) (string, int, error) {
  737. p := &ListProjectsParams{}
  738. p.p = make(map[string]interface{})
  739. p.p["name"] = name
  740. for _, fn := range opts {
  741. if err := fn(s.cs, p); err != nil {
  742. return "", -1, err
  743. }
  744. }
  745. l, err := s.ListProjects(p)
  746. if err != nil {
  747. return "", -1, err
  748. }
  749. if l.Count == 0 {
  750. return "", l.Count, fmt.Errorf("No match found for %s: %+v", name, l)
  751. }
  752. if l.Count == 1 {
  753. return l.Projects[0].Id, l.Count, nil
  754. }
  755. if l.Count > 1 {
  756. for _, v := range l.Projects {
  757. if v.Name == name {
  758. return v.Id, l.Count, nil
  759. }
  760. }
  761. }
  762. return "", l.Count, fmt.Errorf("Could not find an exact match for %s: %+v", name, l)
  763. }
  764. // This is a courtesy helper function, which in some cases may not work as expected!
  765. func (s *ProjectService) GetProjectByName(name string, opts ...OptionFunc) (*Project, int, error) {
  766. id, count, err := s.GetProjectID(name, opts...)
  767. if err != nil {
  768. return nil, count, err
  769. }
  770. r, count, err := s.GetProjectByID(id, opts...)
  771. if err != nil {
  772. return nil, count, err
  773. }
  774. return r, count, nil
  775. }
  776. // This is a courtesy helper function, which in some cases may not work as expected!
  777. func (s *ProjectService) GetProjectByID(id string, opts ...OptionFunc) (*Project, int, error) {
  778. p := &ListProjectsParams{}
  779. p.p = make(map[string]interface{})
  780. p.p["id"] = id
  781. for _, fn := range opts {
  782. if err := fn(s.cs, p); err != nil {
  783. return nil, -1, err
  784. }
  785. }
  786. l, err := s.ListProjects(p)
  787. if err != nil {
  788. if strings.Contains(err.Error(), fmt.Sprintf(
  789. "Invalid parameter id value=%s due to incorrect long value format, "+
  790. "or entity does not exist", id)) {
  791. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  792. }
  793. return nil, -1, err
  794. }
  795. if l.Count == 0 {
  796. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  797. }
  798. if l.Count == 1 {
  799. return l.Projects[0], l.Count, nil
  800. }
  801. return nil, l.Count, fmt.Errorf("There is more then one result for Project UUID: %s!", id)
  802. }
  803. // Lists projects and provides detailed information for listed projects
  804. func (s *ProjectService) ListProjects(p *ListProjectsParams) (*ListProjectsResponse, error) {
  805. resp, err := s.cs.newRequest("listProjects", p.toURLValues())
  806. if err != nil {
  807. return nil, err
  808. }
  809. var r ListProjectsResponse
  810. if err := json.Unmarshal(resp, &r); err != nil {
  811. return nil, err
  812. }
  813. return &r, nil
  814. }
  815. type ListProjectsResponse struct {
  816. Count int `json:"count"`
  817. Projects []*Project `json:"project"`
  818. }
  819. type Project struct {
  820. Account string `json:"account,omitempty"`
  821. Cpuavailable string `json:"cpuavailable,omitempty"`
  822. Cpulimit string `json:"cpulimit,omitempty"`
  823. Cputotal int64 `json:"cputotal,omitempty"`
  824. Displaytext string `json:"displaytext,omitempty"`
  825. Domain string `json:"domain,omitempty"`
  826. Domainid string `json:"domainid,omitempty"`
  827. Id string `json:"id,omitempty"`
  828. Ipavailable string `json:"ipavailable,omitempty"`
  829. Iplimit string `json:"iplimit,omitempty"`
  830. Iptotal int64 `json:"iptotal,omitempty"`
  831. Memoryavailable string `json:"memoryavailable,omitempty"`
  832. Memorylimit string `json:"memorylimit,omitempty"`
  833. Memorytotal int64 `json:"memorytotal,omitempty"`
  834. Name string `json:"name,omitempty"`
  835. Networkavailable string `json:"networkavailable,omitempty"`
  836. Networklimit string `json:"networklimit,omitempty"`
  837. Networktotal int64 `json:"networktotal,omitempty"`
  838. Primarystorageavailable string `json:"primarystorageavailable,omitempty"`
  839. Primarystoragelimit string `json:"primarystoragelimit,omitempty"`
  840. Primarystoragetotal int64 `json:"primarystoragetotal,omitempty"`
  841. Secondarystorageavailable string `json:"secondarystorageavailable,omitempty"`
  842. Secondarystoragelimit string `json:"secondarystoragelimit,omitempty"`
  843. Secondarystoragetotal int64 `json:"secondarystoragetotal,omitempty"`
  844. Snapshotavailable string `json:"snapshotavailable,omitempty"`
  845. Snapshotlimit string `json:"snapshotlimit,omitempty"`
  846. Snapshottotal int64 `json:"snapshottotal,omitempty"`
  847. State string `json:"state,omitempty"`
  848. Tags []struct {
  849. Account string `json:"account,omitempty"`
  850. Customer string `json:"customer,omitempty"`
  851. Domain string `json:"domain,omitempty"`
  852. Domainid string `json:"domainid,omitempty"`
  853. Key string `json:"key,omitempty"`
  854. Project string `json:"project,omitempty"`
  855. Projectid string `json:"projectid,omitempty"`
  856. Resourceid string `json:"resourceid,omitempty"`
  857. Resourcetype string `json:"resourcetype,omitempty"`
  858. Value string `json:"value,omitempty"`
  859. } `json:"tags,omitempty"`
  860. Templateavailable string `json:"templateavailable,omitempty"`
  861. Templatelimit string `json:"templatelimit,omitempty"`
  862. Templatetotal int64 `json:"templatetotal,omitempty"`
  863. Vmavailable string `json:"vmavailable,omitempty"`
  864. Vmlimit string `json:"vmlimit,omitempty"`
  865. Vmrunning int `json:"vmrunning,omitempty"`
  866. Vmstopped int `json:"vmstopped,omitempty"`
  867. Vmtotal int64 `json:"vmtotal,omitempty"`
  868. Volumeavailable string `json:"volumeavailable,omitempty"`
  869. Volumelimit string `json:"volumelimit,omitempty"`
  870. Volumetotal int64 `json:"volumetotal,omitempty"`
  871. Vpcavailable string `json:"vpcavailable,omitempty"`
  872. Vpclimit string `json:"vpclimit,omitempty"`
  873. Vpctotal int64 `json:"vpctotal,omitempty"`
  874. }
  875. type ListProjectInvitationsParams struct {
  876. p map[string]interface{}
  877. }
  878. func (p *ListProjectInvitationsParams) toURLValues() url.Values {
  879. u := url.Values{}
  880. if p.p == nil {
  881. return u
  882. }
  883. if v, found := p.p["account"]; found {
  884. u.Set("account", v.(string))
  885. }
  886. if v, found := p.p["activeonly"]; found {
  887. vv := strconv.FormatBool(v.(bool))
  888. u.Set("activeonly", vv)
  889. }
  890. if v, found := p.p["domainid"]; found {
  891. u.Set("domainid", v.(string))
  892. }
  893. if v, found := p.p["id"]; found {
  894. u.Set("id", v.(string))
  895. }
  896. if v, found := p.p["isrecursive"]; found {
  897. vv := strconv.FormatBool(v.(bool))
  898. u.Set("isrecursive", vv)
  899. }
  900. if v, found := p.p["keyword"]; found {
  901. u.Set("keyword", v.(string))
  902. }
  903. if v, found := p.p["listall"]; found {
  904. vv := strconv.FormatBool(v.(bool))
  905. u.Set("listall", vv)
  906. }
  907. if v, found := p.p["page"]; found {
  908. vv := strconv.Itoa(v.(int))
  909. u.Set("page", vv)
  910. }
  911. if v, found := p.p["pagesize"]; found {
  912. vv := strconv.Itoa(v.(int))
  913. u.Set("pagesize", vv)
  914. }
  915. if v, found := p.p["projectid"]; found {
  916. u.Set("projectid", v.(string))
  917. }
  918. if v, found := p.p["state"]; found {
  919. u.Set("state", v.(string))
  920. }
  921. return u
  922. }
  923. func (p *ListProjectInvitationsParams) SetAccount(v string) {
  924. if p.p == nil {
  925. p.p = make(map[string]interface{})
  926. }
  927. p.p["account"] = v
  928. return
  929. }
  930. func (p *ListProjectInvitationsParams) SetActiveonly(v bool) {
  931. if p.p == nil {
  932. p.p = make(map[string]interface{})
  933. }
  934. p.p["activeonly"] = v
  935. return
  936. }
  937. func (p *ListProjectInvitationsParams) SetDomainid(v string) {
  938. if p.p == nil {
  939. p.p = make(map[string]interface{})
  940. }
  941. p.p["domainid"] = v
  942. return
  943. }
  944. func (p *ListProjectInvitationsParams) SetId(v string) {
  945. if p.p == nil {
  946. p.p = make(map[string]interface{})
  947. }
  948. p.p["id"] = v
  949. return
  950. }
  951. func (p *ListProjectInvitationsParams) SetIsrecursive(v bool) {
  952. if p.p == nil {
  953. p.p = make(map[string]interface{})
  954. }
  955. p.p["isrecursive"] = v
  956. return
  957. }
  958. func (p *ListProjectInvitationsParams) SetKeyword(v string) {
  959. if p.p == nil {
  960. p.p = make(map[string]interface{})
  961. }
  962. p.p["keyword"] = v
  963. return
  964. }
  965. func (p *ListProjectInvitationsParams) SetListall(v bool) {
  966. if p.p == nil {
  967. p.p = make(map[string]interface{})
  968. }
  969. p.p["listall"] = v
  970. return
  971. }
  972. func (p *ListProjectInvitationsParams) SetPage(v int) {
  973. if p.p == nil {
  974. p.p = make(map[string]interface{})
  975. }
  976. p.p["page"] = v
  977. return
  978. }
  979. func (p *ListProjectInvitationsParams) SetPagesize(v int) {
  980. if p.p == nil {
  981. p.p = make(map[string]interface{})
  982. }
  983. p.p["pagesize"] = v
  984. return
  985. }
  986. func (p *ListProjectInvitationsParams) SetProjectid(v string) {
  987. if p.p == nil {
  988. p.p = make(map[string]interface{})
  989. }
  990. p.p["projectid"] = v
  991. return
  992. }
  993. func (p *ListProjectInvitationsParams) SetState(v string) {
  994. if p.p == nil {
  995. p.p = make(map[string]interface{})
  996. }
  997. p.p["state"] = v
  998. return
  999. }
  1000. // You should always use this function to get a new ListProjectInvitationsParams instance,
  1001. // as then you are sure you have configured all required params
  1002. func (s *ProjectService) NewListProjectInvitationsParams() *ListProjectInvitationsParams {
  1003. p := &ListProjectInvitationsParams{}
  1004. p.p = make(map[string]interface{})
  1005. return p
  1006. }
  1007. // This is a courtesy helper function, which in some cases may not work as expected!
  1008. func (s *ProjectService) GetProjectInvitationByID(id string, opts ...OptionFunc) (*ProjectInvitation, int, error) {
  1009. p := &ListProjectInvitationsParams{}
  1010. p.p = make(map[string]interface{})
  1011. p.p["id"] = id
  1012. for _, fn := range opts {
  1013. if err := fn(s.cs, p); err != nil {
  1014. return nil, -1, err
  1015. }
  1016. }
  1017. l, err := s.ListProjectInvitations(p)
  1018. if err != nil {
  1019. if strings.Contains(err.Error(), fmt.Sprintf(
  1020. "Invalid parameter id value=%s due to incorrect long value format, "+
  1021. "or entity does not exist", id)) {
  1022. return nil, 0, fmt.Errorf("No match found for %s: %+v", id, l)
  1023. }
  1024. return nil, -1, err
  1025. }
  1026. if l.Count == 0 {
  1027. return nil, l.Count, fmt.Errorf("No match found for %s: %+v", id, l)
  1028. }
  1029. if l.Count == 1 {
  1030. return l.ProjectInvitations[0], l.Count, nil
  1031. }
  1032. return nil, l.Count, fmt.Errorf("There is more then one result for ProjectInvitation UUID: %s!", id)
  1033. }
  1034. // Lists project invitations and provides detailed information for listed invitations
  1035. func (s *ProjectService) ListProjectInvitations(p *ListProjectInvitationsParams) (*ListProjectInvitationsResponse, error) {
  1036. resp, err := s.cs.newRequest("listProjectInvitations", p.toURLValues())
  1037. if err != nil {
  1038. return nil, err
  1039. }
  1040. var r ListProjectInvitationsResponse
  1041. if err := json.Unmarshal(resp, &r); err != nil {
  1042. return nil, err
  1043. }
  1044. return &r, nil
  1045. }
  1046. type ListProjectInvitationsResponse struct {
  1047. Count int `json:"count"`
  1048. ProjectInvitations []*ProjectInvitation `json:"projectinvitation"`
  1049. }
  1050. type ProjectInvitation struct {
  1051. Account string `json:"account,omitempty"`
  1052. Domain string `json:"domain,omitempty"`
  1053. Domainid string `json:"domainid,omitempty"`
  1054. Email string `json:"email,omitempty"`
  1055. Id string `json:"id,omitempty"`
  1056. Project string `json:"project,omitempty"`
  1057. Projectid string `json:"projectid,omitempty"`
  1058. State string `json:"state,omitempty"`
  1059. }
  1060. type UpdateProjectInvitationParams struct {
  1061. p map[string]interface{}
  1062. }
  1063. func (p *UpdateProjectInvitationParams) toURLValues() url.Values {
  1064. u := url.Values{}
  1065. if p.p == nil {
  1066. return u
  1067. }
  1068. if v, found := p.p["accept"]; found {
  1069. vv := strconv.FormatBool(v.(bool))
  1070. u.Set("accept", vv)
  1071. }
  1072. if v, found := p.p["account"]; found {
  1073. u.Set("account", v.(string))
  1074. }
  1075. if v, found := p.p["projectid"]; found {
  1076. u.Set("projectid", v.(string))
  1077. }
  1078. if v, found := p.p["token"]; found {
  1079. u.Set("token", v.(string))
  1080. }
  1081. return u
  1082. }
  1083. func (p *UpdateProjectInvitationParams) SetAccept(v bool) {
  1084. if p.p == nil {
  1085. p.p = make(map[string]interface{})
  1086. }
  1087. p.p["accept"] = v
  1088. return
  1089. }
  1090. func (p *UpdateProjectInvitationParams) SetAccount(v string) {
  1091. if p.p == nil {
  1092. p.p = make(map[string]interface{})
  1093. }
  1094. p.p["account"] = v
  1095. return
  1096. }
  1097. func (p *UpdateProjectInvitationParams) SetProjectid(v string) {
  1098. if p.p == nil {
  1099. p.p = make(map[string]interface{})
  1100. }
  1101. p.p["projectid"] = v
  1102. return
  1103. }
  1104. func (p *UpdateProjectInvitationParams) SetToken(v string) {
  1105. if p.p == nil {
  1106. p.p = make(map[string]interface{})
  1107. }
  1108. p.p["token"] = v
  1109. return
  1110. }
  1111. // You should always use this function to get a new UpdateProjectInvitationParams instance,
  1112. // as then you are sure you have configured all required params
  1113. func (s *ProjectService) NewUpdateProjectInvitationParams(projectid string) *UpdateProjectInvitationParams {
  1114. p := &UpdateProjectInvitationParams{}
  1115. p.p = make(map[string]interface{})
  1116. p.p["projectid"] = projectid
  1117. return p
  1118. }
  1119. // Accepts or declines project invitation
  1120. func (s *ProjectService) UpdateProjectInvitation(p *UpdateProjectInvitationParams) (*UpdateProjectInvitationResponse, error) {
  1121. resp, err := s.cs.newRequest("updateProjectInvitation", p.toURLValues())
  1122. if err != nil {
  1123. return nil, err
  1124. }
  1125. var r UpdateProjectInvitationResponse
  1126. if err := json.Unmarshal(resp, &r); err != nil {
  1127. return nil, err
  1128. }
  1129. // If we have a async client, we need to wait for the async result
  1130. if s.cs.async {
  1131. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1132. if err != nil {
  1133. if err == AsyncTimeoutErr {
  1134. return &r, err
  1135. }
  1136. return nil, err
  1137. }
  1138. if err := json.Unmarshal(b, &r); err != nil {
  1139. return nil, err
  1140. }
  1141. }
  1142. return &r, nil
  1143. }
  1144. type UpdateProjectInvitationResponse struct {
  1145. JobID string `json:"jobid,omitempty"`
  1146. Displaytext string `json:"displaytext,omitempty"`
  1147. Success bool `json:"success,omitempty"`
  1148. }
  1149. type DeleteProjectInvitationParams struct {
  1150. p map[string]interface{}
  1151. }
  1152. func (p *DeleteProjectInvitationParams) toURLValues() url.Values {
  1153. u := url.Values{}
  1154. if p.p == nil {
  1155. return u
  1156. }
  1157. if v, found := p.p["id"]; found {
  1158. u.Set("id", v.(string))
  1159. }
  1160. return u
  1161. }
  1162. func (p *DeleteProjectInvitationParams) 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. // You should always use this function to get a new DeleteProjectInvitationParams instance,
  1170. // as then you are sure you have configured all required params
  1171. func (s *ProjectService) NewDeleteProjectInvitationParams(id string) *DeleteProjectInvitationParams {
  1172. p := &DeleteProjectInvitationParams{}
  1173. p.p = make(map[string]interface{})
  1174. p.p["id"] = id
  1175. return p
  1176. }
  1177. // Deletes project invitation
  1178. func (s *ProjectService) DeleteProjectInvitation(p *DeleteProjectInvitationParams) (*DeleteProjectInvitationResponse, error) {
  1179. resp, err := s.cs.newRequest("deleteProjectInvitation", p.toURLValues())
  1180. if err != nil {
  1181. return nil, err
  1182. }
  1183. var r DeleteProjectInvitationResponse
  1184. if err := json.Unmarshal(resp, &r); err != nil {
  1185. return nil, err
  1186. }
  1187. // If we have a async client, we need to wait for the async result
  1188. if s.cs.async {
  1189. b, err := s.cs.GetAsyncJobResult(r.JobID, s.cs.timeout)
  1190. if err != nil {
  1191. if err == AsyncTimeoutErr {
  1192. return &r, err
  1193. }
  1194. return nil, err
  1195. }
  1196. if err := json.Unmarshal(b, &r); err != nil {
  1197. return nil, err
  1198. }
  1199. }
  1200. return &r, nil
  1201. }
  1202. type DeleteProjectInvitationResponse struct {
  1203. JobID string `json:"jobid,omitempty"`
  1204. Displaytext string `json:"displaytext,omitempty"`
  1205. Success bool `json:"success,omitempty"`
  1206. }