LimitService.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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. "net/url"
  20. "strconv"
  21. )
  22. type UpdateResourceLimitParams struct {
  23. p map[string]interface{}
  24. }
  25. func (p *UpdateResourceLimitParams) toURLValues() url.Values {
  26. u := url.Values{}
  27. if p.p == nil {
  28. return u
  29. }
  30. if v, found := p.p["account"]; found {
  31. u.Set("account", v.(string))
  32. }
  33. if v, found := p.p["domainid"]; found {
  34. u.Set("domainid", v.(string))
  35. }
  36. if v, found := p.p["max"]; found {
  37. vv := strconv.FormatInt(v.(int64), 10)
  38. u.Set("max", vv)
  39. }
  40. if v, found := p.p["projectid"]; found {
  41. u.Set("projectid", v.(string))
  42. }
  43. if v, found := p.p["resourcetype"]; found {
  44. vv := strconv.Itoa(v.(int))
  45. u.Set("resourcetype", vv)
  46. }
  47. return u
  48. }
  49. func (p *UpdateResourceLimitParams) SetAccount(v string) {
  50. if p.p == nil {
  51. p.p = make(map[string]interface{})
  52. }
  53. p.p["account"] = v
  54. return
  55. }
  56. func (p *UpdateResourceLimitParams) SetDomainid(v string) {
  57. if p.p == nil {
  58. p.p = make(map[string]interface{})
  59. }
  60. p.p["domainid"] = v
  61. return
  62. }
  63. func (p *UpdateResourceLimitParams) SetMax(v int64) {
  64. if p.p == nil {
  65. p.p = make(map[string]interface{})
  66. }
  67. p.p["max"] = v
  68. return
  69. }
  70. func (p *UpdateResourceLimitParams) SetProjectid(v string) {
  71. if p.p == nil {
  72. p.p = make(map[string]interface{})
  73. }
  74. p.p["projectid"] = v
  75. return
  76. }
  77. func (p *UpdateResourceLimitParams) SetResourcetype(v int) {
  78. if p.p == nil {
  79. p.p = make(map[string]interface{})
  80. }
  81. p.p["resourcetype"] = v
  82. return
  83. }
  84. // You should always use this function to get a new UpdateResourceLimitParams instance,
  85. // as then you are sure you have configured all required params
  86. func (s *LimitService) NewUpdateResourceLimitParams(resourcetype int) *UpdateResourceLimitParams {
  87. p := &UpdateResourceLimitParams{}
  88. p.p = make(map[string]interface{})
  89. p.p["resourcetype"] = resourcetype
  90. return p
  91. }
  92. // Updates resource limits for an account or domain.
  93. func (s *LimitService) UpdateResourceLimit(p *UpdateResourceLimitParams) (*UpdateResourceLimitResponse, error) {
  94. resp, err := s.cs.newRequest("updateResourceLimit", p.toURLValues())
  95. if err != nil {
  96. return nil, err
  97. }
  98. var r UpdateResourceLimitResponse
  99. if err := json.Unmarshal(resp, &r); err != nil {
  100. return nil, err
  101. }
  102. return &r, nil
  103. }
  104. type UpdateResourceLimitResponse struct {
  105. Account string `json:"account,omitempty"`
  106. Domain string `json:"domain,omitempty"`
  107. Domainid string `json:"domainid,omitempty"`
  108. Max int64 `json:"max,omitempty"`
  109. Project string `json:"project,omitempty"`
  110. Projectid string `json:"projectid,omitempty"`
  111. Resourcetype string `json:"resourcetype,omitempty"`
  112. }
  113. type UpdateResourceCountParams struct {
  114. p map[string]interface{}
  115. }
  116. func (p *UpdateResourceCountParams) toURLValues() url.Values {
  117. u := url.Values{}
  118. if p.p == nil {
  119. return u
  120. }
  121. if v, found := p.p["account"]; found {
  122. u.Set("account", v.(string))
  123. }
  124. if v, found := p.p["domainid"]; found {
  125. u.Set("domainid", v.(string))
  126. }
  127. if v, found := p.p["projectid"]; found {
  128. u.Set("projectid", v.(string))
  129. }
  130. if v, found := p.p["resourcetype"]; found {
  131. vv := strconv.Itoa(v.(int))
  132. u.Set("resourcetype", vv)
  133. }
  134. return u
  135. }
  136. func (p *UpdateResourceCountParams) SetAccount(v string) {
  137. if p.p == nil {
  138. p.p = make(map[string]interface{})
  139. }
  140. p.p["account"] = v
  141. return
  142. }
  143. func (p *UpdateResourceCountParams) SetDomainid(v string) {
  144. if p.p == nil {
  145. p.p = make(map[string]interface{})
  146. }
  147. p.p["domainid"] = v
  148. return
  149. }
  150. func (p *UpdateResourceCountParams) SetProjectid(v string) {
  151. if p.p == nil {
  152. p.p = make(map[string]interface{})
  153. }
  154. p.p["projectid"] = v
  155. return
  156. }
  157. func (p *UpdateResourceCountParams) SetResourcetype(v int) {
  158. if p.p == nil {
  159. p.p = make(map[string]interface{})
  160. }
  161. p.p["resourcetype"] = v
  162. return
  163. }
  164. // You should always use this function to get a new UpdateResourceCountParams instance,
  165. // as then you are sure you have configured all required params
  166. func (s *LimitService) NewUpdateResourceCountParams(domainid string) *UpdateResourceCountParams {
  167. p := &UpdateResourceCountParams{}
  168. p.p = make(map[string]interface{})
  169. p.p["domainid"] = domainid
  170. return p
  171. }
  172. // Recalculate and update resource count for an account or domain.
  173. func (s *LimitService) UpdateResourceCount(p *UpdateResourceCountParams) (*UpdateResourceCountResponse, error) {
  174. resp, err := s.cs.newRequest("updateResourceCount", p.toURLValues())
  175. if err != nil {
  176. return nil, err
  177. }
  178. var r UpdateResourceCountResponse
  179. if err := json.Unmarshal(resp, &r); err != nil {
  180. return nil, err
  181. }
  182. return &r, nil
  183. }
  184. type UpdateResourceCountResponse struct {
  185. Account string `json:"account,omitempty"`
  186. Domain string `json:"domain,omitempty"`
  187. Domainid string `json:"domainid,omitempty"`
  188. Project string `json:"project,omitempty"`
  189. Projectid string `json:"projectid,omitempty"`
  190. Resourcecount int64 `json:"resourcecount,omitempty"`
  191. Resourcetype string `json:"resourcetype,omitempty"`
  192. }
  193. type ListResourceLimitsParams struct {
  194. p map[string]interface{}
  195. }
  196. func (p *ListResourceLimitsParams) toURLValues() url.Values {
  197. u := url.Values{}
  198. if p.p == nil {
  199. return u
  200. }
  201. if v, found := p.p["account"]; found {
  202. u.Set("account", v.(string))
  203. }
  204. if v, found := p.p["domainid"]; found {
  205. u.Set("domainid", v.(string))
  206. }
  207. if v, found := p.p["id"]; found {
  208. vv := strconv.FormatInt(v.(int64), 10)
  209. u.Set("id", vv)
  210. }
  211. if v, found := p.p["isrecursive"]; found {
  212. vv := strconv.FormatBool(v.(bool))
  213. u.Set("isrecursive", vv)
  214. }
  215. if v, found := p.p["keyword"]; found {
  216. u.Set("keyword", v.(string))
  217. }
  218. if v, found := p.p["listall"]; found {
  219. vv := strconv.FormatBool(v.(bool))
  220. u.Set("listall", vv)
  221. }
  222. if v, found := p.p["page"]; found {
  223. vv := strconv.Itoa(v.(int))
  224. u.Set("page", vv)
  225. }
  226. if v, found := p.p["pagesize"]; found {
  227. vv := strconv.Itoa(v.(int))
  228. u.Set("pagesize", vv)
  229. }
  230. if v, found := p.p["projectid"]; found {
  231. u.Set("projectid", v.(string))
  232. }
  233. if v, found := p.p["resourcetype"]; found {
  234. vv := strconv.Itoa(v.(int))
  235. u.Set("resourcetype", vv)
  236. }
  237. return u
  238. }
  239. func (p *ListResourceLimitsParams) SetAccount(v string) {
  240. if p.p == nil {
  241. p.p = make(map[string]interface{})
  242. }
  243. p.p["account"] = v
  244. return
  245. }
  246. func (p *ListResourceLimitsParams) SetDomainid(v string) {
  247. if p.p == nil {
  248. p.p = make(map[string]interface{})
  249. }
  250. p.p["domainid"] = v
  251. return
  252. }
  253. func (p *ListResourceLimitsParams) SetId(v int64) {
  254. if p.p == nil {
  255. p.p = make(map[string]interface{})
  256. }
  257. p.p["id"] = v
  258. return
  259. }
  260. func (p *ListResourceLimitsParams) SetIsrecursive(v bool) {
  261. if p.p == nil {
  262. p.p = make(map[string]interface{})
  263. }
  264. p.p["isrecursive"] = v
  265. return
  266. }
  267. func (p *ListResourceLimitsParams) SetKeyword(v string) {
  268. if p.p == nil {
  269. p.p = make(map[string]interface{})
  270. }
  271. p.p["keyword"] = v
  272. return
  273. }
  274. func (p *ListResourceLimitsParams) SetListall(v bool) {
  275. if p.p == nil {
  276. p.p = make(map[string]interface{})
  277. }
  278. p.p["listall"] = v
  279. return
  280. }
  281. func (p *ListResourceLimitsParams) SetPage(v int) {
  282. if p.p == nil {
  283. p.p = make(map[string]interface{})
  284. }
  285. p.p["page"] = v
  286. return
  287. }
  288. func (p *ListResourceLimitsParams) SetPagesize(v int) {
  289. if p.p == nil {
  290. p.p = make(map[string]interface{})
  291. }
  292. p.p["pagesize"] = v
  293. return
  294. }
  295. func (p *ListResourceLimitsParams) SetProjectid(v string) {
  296. if p.p == nil {
  297. p.p = make(map[string]interface{})
  298. }
  299. p.p["projectid"] = v
  300. return
  301. }
  302. func (p *ListResourceLimitsParams) SetResourcetype(v int) {
  303. if p.p == nil {
  304. p.p = make(map[string]interface{})
  305. }
  306. p.p["resourcetype"] = v
  307. return
  308. }
  309. // You should always use this function to get a new ListResourceLimitsParams instance,
  310. // as then you are sure you have configured all required params
  311. func (s *LimitService) NewListResourceLimitsParams() *ListResourceLimitsParams {
  312. p := &ListResourceLimitsParams{}
  313. p.p = make(map[string]interface{})
  314. return p
  315. }
  316. // Lists resource limits.
  317. func (s *LimitService) ListResourceLimits(p *ListResourceLimitsParams) (*ListResourceLimitsResponse, error) {
  318. resp, err := s.cs.newRequest("listResourceLimits", p.toURLValues())
  319. if err != nil {
  320. return nil, err
  321. }
  322. var r ListResourceLimitsResponse
  323. if err := json.Unmarshal(resp, &r); err != nil {
  324. return nil, err
  325. }
  326. return &r, nil
  327. }
  328. type ListResourceLimitsResponse struct {
  329. Count int `json:"count"`
  330. ResourceLimits []*ResourceLimit `json:"resourcelimit"`
  331. }
  332. type ResourceLimit struct {
  333. Account string `json:"account,omitempty"`
  334. Domain string `json:"domain,omitempty"`
  335. Domainid string `json:"domainid,omitempty"`
  336. Max int64 `json:"max,omitempty"`
  337. Project string `json:"project,omitempty"`
  338. Projectid string `json:"projectid,omitempty"`
  339. Resourcetype string `json:"resourcetype,omitempty"`
  340. }
  341. type GetApiLimitParams struct {
  342. p map[string]interface{}
  343. }
  344. func (p *GetApiLimitParams) toURLValues() url.Values {
  345. u := url.Values{}
  346. if p.p == nil {
  347. return u
  348. }
  349. return u
  350. }
  351. // You should always use this function to get a new GetApiLimitParams instance,
  352. // as then you are sure you have configured all required params
  353. func (s *LimitService) NewGetApiLimitParams() *GetApiLimitParams {
  354. p := &GetApiLimitParams{}
  355. p.p = make(map[string]interface{})
  356. return p
  357. }
  358. // Get API limit count for the caller
  359. func (s *LimitService) GetApiLimit(p *GetApiLimitParams) (*GetApiLimitResponse, error) {
  360. resp, err := s.cs.newRequest("getApiLimit", p.toURLValues())
  361. if err != nil {
  362. return nil, err
  363. }
  364. var r GetApiLimitResponse
  365. if err := json.Unmarshal(resp, &r); err != nil {
  366. return nil, err
  367. }
  368. return &r, nil
  369. }
  370. type GetApiLimitResponse struct {
  371. Account string `json:"account,omitempty"`
  372. Accountid string `json:"accountid,omitempty"`
  373. ApiAllowed int `json:"apiAllowed,omitempty"`
  374. ApiIssued int `json:"apiIssued,omitempty"`
  375. ExpireAfter int64 `json:"expireAfter,omitempty"`
  376. }
  377. type ResetApiLimitParams struct {
  378. p map[string]interface{}
  379. }
  380. func (p *ResetApiLimitParams) toURLValues() url.Values {
  381. u := url.Values{}
  382. if p.p == nil {
  383. return u
  384. }
  385. if v, found := p.p["account"]; found {
  386. u.Set("account", v.(string))
  387. }
  388. return u
  389. }
  390. func (p *ResetApiLimitParams) SetAccount(v string) {
  391. if p.p == nil {
  392. p.p = make(map[string]interface{})
  393. }
  394. p.p["account"] = v
  395. return
  396. }
  397. // You should always use this function to get a new ResetApiLimitParams instance,
  398. // as then you are sure you have configured all required params
  399. func (s *LimitService) NewResetApiLimitParams() *ResetApiLimitParams {
  400. p := &ResetApiLimitParams{}
  401. p.p = make(map[string]interface{})
  402. return p
  403. }
  404. // Reset api count
  405. func (s *LimitService) ResetApiLimit(p *ResetApiLimitParams) (*ResetApiLimitResponse, error) {
  406. resp, err := s.cs.newRequest("resetApiLimit", p.toURLValues())
  407. if err != nil {
  408. return nil, err
  409. }
  410. var r ResetApiLimitResponse
  411. if err := json.Unmarshal(resp, &r); err != nil {
  412. return nil, err
  413. }
  414. return &r, nil
  415. }
  416. type ResetApiLimitResponse struct {
  417. Account string `json:"account,omitempty"`
  418. Accountid string `json:"accountid,omitempty"`
  419. ApiAllowed int `json:"apiAllowed,omitempty"`
  420. ApiIssued int `json:"apiIssued,omitempty"`
  421. ExpireAfter int64 `json:"expireAfter,omitempty"`
  422. }