regionquota.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package models
  15. import (
  16. "context"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/errors"
  19. "yunion.io/x/pkg/util/rbacscope"
  20. identityapi "yunion.io/x/onecloud/pkg/apis/identity"
  21. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  22. "yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
  23. commonOptions "yunion.io/x/onecloud/pkg/cloudcommon/options"
  24. "yunion.io/x/onecloud/pkg/compute/options"
  25. "yunion.io/x/onecloud/pkg/mcclient/auth"
  26. "yunion.io/x/onecloud/pkg/util/rbacutils"
  27. )
  28. var (
  29. RegionQuota SRegionQuota
  30. RegionQuotaManager *SQuotaManager
  31. RegionUsageManager *SQuotaManager
  32. RegionPendingUsageManager *SQuotaManager
  33. )
  34. func init() {
  35. RegionQuota = SRegionQuota{}
  36. RegionUsageManager = &SQuotaManager{
  37. SQuotaBaseManager: quotas.NewQuotaUsageManager(RegionQuota,
  38. rbacscope.ScopeProject,
  39. "region_quota_usage_tbl",
  40. "region_quota_usage",
  41. "region_quota_usages",
  42. ),
  43. }
  44. RegionPendingUsageManager = &SQuotaManager{
  45. SQuotaBaseManager: quotas.NewQuotaUsageManager(RegionQuota,
  46. rbacscope.ScopeProject,
  47. "region_quota_pending_usage_tbl",
  48. "region_quota_pending_usage",
  49. "region_quota_pending_usages",
  50. ),
  51. }
  52. RegionQuotaManager = &SQuotaManager{
  53. SQuotaBaseManager: quotas.NewQuotaBaseManager(RegionQuota,
  54. rbacscope.ScopeProject,
  55. "region_quota_tbl",
  56. RegionPendingUsageManager,
  57. RegionUsageManager,
  58. "region_quota",
  59. "region_quotas",
  60. ),
  61. }
  62. quotas.Register(RegionQuotaManager)
  63. }
  64. type SRegionQuota struct {
  65. quotas.SQuotaBase
  66. quotas.SRegionalCloudResourceKeys
  67. Eip int `default:"-1" allow_zero:"true" json:"eip"`
  68. Port int `default:"-1" allow_zero:"true" json:"port"`
  69. Eport int `default:"-1" allow_zero:"true" json:"eport"`
  70. // Bw int `default:"-1" allow_zero:"true"`
  71. // Ebw int `default:"-1" allow_zero:"true"`
  72. Snapshot int `default:"-1" allow_zero:"true" json:"snapshot"`
  73. InstanceSnapshot int `default:"-1" allow_zero:"true" json:"instance_snapshot"`
  74. Bucket int `default:"-1" allow_zero:"true" json:"bucket"`
  75. ObjectGB int `default:"-1" allow_zero:"true" json:"object_gb"`
  76. ObjectCnt int `default:"-1" allow_zero:"true" json:"object_cnt"`
  77. Rds int `default:"-1" allow_zero:"true" json:"rds"`
  78. Cache int `default:"-1" allow_zero:"true" json:"cache"`
  79. Mongodb int `default:"-1" allow_zero:"true" json:"mongodb"`
  80. Loadbalancer int `default:"-1" allow_zero:"true" json:"loadbalancer"`
  81. }
  82. func (self *SRegionQuota) GetKeys() quotas.IQuotaKeys {
  83. return self.SRegionalCloudResourceKeys
  84. }
  85. func (self *SRegionQuota) SetKeys(keys quotas.IQuotaKeys) {
  86. self.SRegionalCloudResourceKeys = keys.(quotas.SRegionalCloudResourceKeys)
  87. }
  88. func (self *SRegionQuota) FetchSystemQuota() {
  89. keys := self.SRegionalCloudResourceKeys
  90. base := 0
  91. switch options.Options.DefaultQuotaValue {
  92. case commonOptions.DefaultQuotaUnlimit:
  93. base = -1
  94. case commonOptions.DefaultQuotaZero:
  95. base = 0
  96. if keys.Scope() == rbacscope.ScopeDomain { // domain level quota
  97. base = 10
  98. } else if keys.DomainId == identityapi.DEFAULT_DOMAIN_ID && keys.ProjectId == auth.AdminCredential().GetProjectId() {
  99. base = 1
  100. }
  101. case commonOptions.DefaultQuotaDefault:
  102. base = 1
  103. if keys.Scope() == rbacscope.ScopeDomain {
  104. base = 10
  105. }
  106. }
  107. defaultValue := func(def int) int {
  108. if base < 0 {
  109. return -1
  110. } else {
  111. return def * base
  112. }
  113. }
  114. self.Eip = defaultValue(options.Options.DefaultEipQuota)
  115. self.Port = defaultValue(options.Options.DefaultPortQuota)
  116. self.Eport = defaultValue(options.Options.DefaultEportQuota)
  117. // self.Bw = defaultValue(options.Options.DefaultBwQuota)
  118. // self.Ebw = defaultValue(options.Options.DefaultEbwQuota)
  119. self.Snapshot = defaultValue(options.Options.DefaultSnapshotQuota)
  120. self.InstanceSnapshot = defaultValue(options.Options.DefaultInstanceSnapshotQuota)
  121. self.Bucket = defaultValue(options.Options.DefaultBucketQuota)
  122. self.ObjectGB = defaultValue(options.Options.DefaultObjectGBQuota)
  123. self.ObjectCnt = defaultValue(options.Options.DefaultObjectCntQuota)
  124. self.Rds = defaultValue(options.Options.DefaultRdsQuota)
  125. self.Cache = defaultValue(options.Options.DefaultCacheQuota)
  126. self.Mongodb = defaultValue(options.Options.DefaultMongodbQuota)
  127. self.Loadbalancer = defaultValue(options.Options.DefaultLoadbalancerQuota)
  128. }
  129. func (self *SRegionQuota) FetchUsage(ctx context.Context) error {
  130. regionKeys := self.SRegionalCloudResourceKeys
  131. scope := regionKeys.Scope()
  132. ownerId := regionKeys.OwnerId()
  133. var rangeObjs []db.IStandaloneModel
  134. if len(regionKeys.RegionId) > 0 {
  135. obj, err := CloudregionManager.FetchById(regionKeys.RegionId)
  136. if err != nil {
  137. return errors.Wrap(err, "CloudregionManager.FetchById")
  138. }
  139. rangeObjs = append(rangeObjs, obj.(db.IStandaloneModel))
  140. }
  141. if len(regionKeys.ManagerId) > 0 {
  142. obj, err := CloudproviderManager.FetchById(regionKeys.ManagerId)
  143. if err != nil {
  144. return errors.Wrap(err, "CloudproviderManager.FetchById")
  145. }
  146. rangeObjs = append(rangeObjs, obj.(db.IStandaloneModel))
  147. } else if len(regionKeys.AccountId) > 0 {
  148. obj, err := CloudaccountManager.FetchById(regionKeys.AccountId)
  149. if err != nil {
  150. return errors.Wrap(err, "CloudaccountManager.FetchById")
  151. }
  152. rangeObjs = append(rangeObjs, obj.(db.IStandaloneModel))
  153. }
  154. var providers []string
  155. if len(regionKeys.Provider) > 0 {
  156. providers = []string{regionKeys.Provider}
  157. }
  158. var brands []string
  159. if len(regionKeys.Brand) > 0 {
  160. brands = []string{regionKeys.Brand}
  161. }
  162. net := totalGuestNicCount(scope, ownerId, rangeObjs, false, providers, brands, regionKeys.CloudEnv)
  163. lbnic, _ := totalLBNicCount(scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv)
  164. eipUsage := ElasticipManager.TotalCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  165. self.Eip = eipUsage.Total()
  166. self.Port = net.InternalNicCount + net.InternalVirtualNicCount + lbnic
  167. self.Eport = net.ExternalNicCount + net.ExternalVirtualNicCount
  168. // self.Bw = net.InternalBandwidth
  169. // self.Ebw = net.ExternalBandwidth
  170. snapshotCount, _ := TotalSnapshotCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  171. self.Snapshot = snapshotCount
  172. instanceSnapshotCount, _ := TotalInstanceSnapshotCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  173. self.InstanceSnapshot = instanceSnapshotCount
  174. bucketUsage := BucketManager.TotalCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  175. self.Bucket = bucketUsage.Buckets
  176. self.ObjectGB = int(bucketUsage.Bytes / 1000 / 1000 / 1000)
  177. self.ObjectCnt = bucketUsage.Objects
  178. rdsUsage, _ := DBInstanceManager.TotalCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  179. self.Rds = rdsUsage.TotalRdsCount
  180. self.Cache, _ = ElasticcacheManager.TotalCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  181. mongodbUsage, _ := MongoDBManager.TotalCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  182. self.Mongodb = mongodbUsage.TotalMongodbCount
  183. self.Loadbalancer, _ = LoadbalancerManager.TotalCount(ctx, scope, ownerId, rangeObjs, providers, brands, regionKeys.CloudEnv, rbacutils.SPolicyResult{})
  184. return nil
  185. }
  186. func (self *SRegionQuota) ResetNegative() {
  187. if self.Port < 0 {
  188. self.Port = 0
  189. }
  190. if self.Eip < 0 {
  191. self.Eip = 0
  192. }
  193. if self.Eport < 0 {
  194. self.Eport = 0
  195. }
  196. // if self.Bw < 0 {
  197. // self.Bw = 0
  198. // }
  199. // if self.Ebw < 0 {
  200. // self.Ebw = 0
  201. // }
  202. if self.Snapshot < 0 {
  203. self.Snapshot = 0
  204. }
  205. if self.InstanceSnapshot < 0 {
  206. self.InstanceSnapshot = 0
  207. }
  208. if self.Bucket < 0 {
  209. self.Bucket = 0
  210. }
  211. if self.ObjectGB < 0 {
  212. self.ObjectGB = 0
  213. }
  214. if self.ObjectCnt < 0 {
  215. self.ObjectCnt = 0
  216. }
  217. if self.Rds < 0 {
  218. self.Rds = 0
  219. }
  220. if self.Cache < 0 {
  221. self.Cache = 0
  222. }
  223. if self.Mongodb < 0 {
  224. self.Mongodb = 0
  225. }
  226. if self.Loadbalancer < 0 {
  227. self.Loadbalancer = 0
  228. }
  229. }
  230. func (self *SRegionQuota) IsEmpty() bool {
  231. if self.Port > 0 {
  232. return false
  233. }
  234. if self.Eip > 0 {
  235. return false
  236. }
  237. if self.Eport > 0 {
  238. return false
  239. }
  240. // if self.Bw > 0 {
  241. // return false
  242. // }
  243. // if self.Ebw > 0 {
  244. // return false
  245. // }
  246. if self.Snapshot > 0 {
  247. return false
  248. }
  249. if self.InstanceSnapshot > 0 {
  250. return false
  251. }
  252. if self.Bucket > 0 {
  253. return false
  254. }
  255. if self.ObjectGB > 0 {
  256. return false
  257. }
  258. if self.ObjectCnt > 0 {
  259. return false
  260. }
  261. if self.Rds > 0 {
  262. return false
  263. }
  264. if self.Cache > 0 {
  265. return false
  266. }
  267. if self.Mongodb > 0 {
  268. return false
  269. }
  270. if self.Loadbalancer > 0 {
  271. return false
  272. }
  273. return true
  274. }
  275. func (self *SRegionQuota) Add(quota quotas.IQuota) {
  276. squota := quota.(*SRegionQuota)
  277. self.Port = self.Port + quotas.NonNegative(squota.Port)
  278. self.Eip = self.Eip + quotas.NonNegative(squota.Eip)
  279. self.Eport = self.Eport + quotas.NonNegative(squota.Eport)
  280. // self.Bw = self.Bw + quotas.NonNegative(squota.Bw)
  281. // self.Ebw = self.Ebw + quotas.NonNegative(squota.Ebw)
  282. self.Snapshot = self.Snapshot + quotas.NonNegative(squota.Snapshot)
  283. self.InstanceSnapshot = self.InstanceSnapshot + quotas.NonNegative(squota.InstanceSnapshot)
  284. self.Bucket = self.Bucket + quotas.NonNegative(squota.Bucket)
  285. self.ObjectGB = self.ObjectGB + quotas.NonNegative(squota.ObjectGB)
  286. self.ObjectCnt = self.ObjectCnt + quotas.NonNegative(squota.ObjectCnt)
  287. self.Rds = self.Rds + quotas.NonNegative(squota.Rds)
  288. self.Cache = self.Cache + quotas.NonNegative(squota.Cache)
  289. self.Mongodb = self.Mongodb + quotas.NonNegative(squota.Mongodb)
  290. self.Loadbalancer = self.Loadbalancer + quotas.NonNegative(squota.Loadbalancer)
  291. }
  292. func (self *SRegionQuota) Sub(quota quotas.IQuota) {
  293. squota := quota.(*SRegionQuota)
  294. self.Port = nonNegative(self.Port - squota.Port)
  295. self.Eip = nonNegative(self.Eip - squota.Eip)
  296. self.Eport = nonNegative(self.Eport - squota.Eport)
  297. // self.Bw = nonNegative(self.Bw - squota.Bw)
  298. // self.Ebw = nonNegative(self.Ebw - squota.Ebw)
  299. self.Snapshot = nonNegative(self.Snapshot - squota.Snapshot)
  300. self.InstanceSnapshot = nonNegative(self.InstanceSnapshot - squota.InstanceSnapshot)
  301. self.Bucket = nonNegative(self.Bucket - squota.Bucket)
  302. self.ObjectGB = nonNegative(self.ObjectGB - squota.ObjectGB)
  303. self.ObjectCnt = nonNegative(self.ObjectCnt - squota.ObjectCnt)
  304. self.Rds = nonNegative(self.Rds - squota.Rds)
  305. self.Cache = nonNegative(self.Cache - squota.Cache)
  306. self.Mongodb = nonNegative(self.Mongodb - squota.Mongodb)
  307. self.Loadbalancer = nonNegative(self.Loadbalancer - squota.Loadbalancer)
  308. }
  309. func (self *SRegionQuota) Allocable(request quotas.IQuota) int {
  310. squota := request.(*SRegionQuota)
  311. cnt := -1
  312. if self.Port >= 0 && squota.Port > 0 && (cnt < 0 || cnt > self.Port/squota.Port) {
  313. cnt = self.Port / squota.Port
  314. }
  315. if self.Eip >= 0 && squota.Eip > 0 && (cnt < 0 || cnt > self.Eip/squota.Eip) {
  316. cnt = self.Eip / squota.Eip
  317. }
  318. if self.Eport >= 0 && squota.Eport > 0 && (cnt < 0 || cnt > self.Eport/squota.Eport) {
  319. cnt = self.Eport / squota.Eport
  320. }
  321. //if self.Bw >= 0 && squota.Bw > 0 && (cnt < 0 || cnt > self.Bw/squota.Bw) {
  322. // cnt = self.Bw / squota.Bw
  323. //}
  324. //if self.Ebw >= 0 && squota.Ebw > 0 && (cnt < 0 || cnt > self.Ebw/squota.Ebw) {
  325. // cnt = self.Ebw / squota.Ebw
  326. //}
  327. if self.Snapshot >= 0 && squota.Snapshot > 0 && (cnt < 0 || cnt > self.Snapshot/squota.Snapshot) {
  328. cnt = self.Snapshot / squota.Snapshot
  329. }
  330. if self.InstanceSnapshot >= 0 && squota.InstanceSnapshot > 0 && (cnt < 0 || cnt > self.InstanceSnapshot/squota.InstanceSnapshot) {
  331. cnt = self.InstanceSnapshot / squota.InstanceSnapshot
  332. }
  333. if self.Bucket >= 0 && squota.Bucket > 0 && (cnt < 0 || cnt > self.Bucket/squota.Bucket) {
  334. cnt = self.Bucket / squota.Bucket
  335. }
  336. if self.ObjectGB >= 0 && squota.ObjectGB > 0 && (cnt < 0 || cnt > self.ObjectGB/squota.ObjectGB) {
  337. cnt = self.ObjectGB / squota.ObjectGB
  338. }
  339. if self.ObjectCnt >= 0 && squota.ObjectCnt > 0 && (cnt < 0 || cnt > self.ObjectCnt/squota.ObjectCnt) {
  340. cnt = self.ObjectCnt / squota.ObjectCnt
  341. }
  342. if self.Rds >= 0 && squota.Rds > 0 && (cnt < 0 || cnt > self.Rds/squota.Rds) {
  343. cnt = self.Rds / squota.Rds
  344. }
  345. if self.Cache >= 0 && squota.Cache > 0 && (cnt < 0 || cnt > self.Cache/squota.Cache) {
  346. cnt = self.Cache / squota.Cache
  347. }
  348. if self.Mongodb >= 0 && squota.Mongodb > 0 && (cnt < 0 || cnt > self.Mongodb/squota.Mongodb) {
  349. cnt = self.Mongodb / squota.Mongodb
  350. }
  351. if self.Loadbalancer >= 0 && squota.Loadbalancer > 0 && (cnt < 0 || cnt > self.Loadbalancer/squota.Loadbalancer) {
  352. cnt = self.Loadbalancer / squota.Loadbalancer
  353. }
  354. return cnt
  355. }
  356. func (self *SRegionQuota) Update(quota quotas.IQuota) {
  357. squota := quota.(*SRegionQuota)
  358. if squota.Port > 0 {
  359. self.Port = squota.Port
  360. }
  361. if squota.Eip > 0 {
  362. self.Eip = squota.Eip
  363. }
  364. if squota.Eport > 0 {
  365. self.Eport = squota.Eport
  366. }
  367. //if squota.Bw > 0 {
  368. // self.Bw = squota.Bw
  369. //}
  370. //if squota.Ebw > 0 {
  371. // self.Ebw = squota.Ebw
  372. //}
  373. if squota.Snapshot > 0 {
  374. self.Snapshot = squota.Snapshot
  375. }
  376. if squota.InstanceSnapshot > 0 {
  377. self.InstanceSnapshot = squota.InstanceSnapshot
  378. }
  379. if squota.Bucket > 0 {
  380. self.Bucket = squota.Bucket
  381. }
  382. if squota.ObjectGB > 0 {
  383. self.ObjectGB = squota.ObjectGB
  384. }
  385. if squota.ObjectCnt > 0 {
  386. self.ObjectCnt = squota.ObjectCnt
  387. }
  388. if squota.Rds > 0 {
  389. self.Rds = squota.Rds
  390. }
  391. if squota.Cache > 0 {
  392. self.Cache = squota.Cache
  393. }
  394. if squota.Mongodb > 0 {
  395. self.Mongodb = squota.Mongodb
  396. }
  397. if squota.Loadbalancer > 0 {
  398. self.Loadbalancer = squota.Loadbalancer
  399. }
  400. }
  401. func (used *SRegionQuota) Exceed(request quotas.IQuota, quota quotas.IQuota) error {
  402. err := quotas.NewOutOfQuotaError()
  403. sreq := request.(*SRegionQuota)
  404. squota := quota.(*SRegionQuota)
  405. if quotas.Exceed(used.Port, sreq.Port, squota.Port) {
  406. err.Add(used, "port", squota.Port, used.Port, sreq.Port)
  407. }
  408. if quotas.Exceed(used.Eip, sreq.Eip, squota.Eip) {
  409. err.Add(used, "eip", squota.Eip, used.Eip, sreq.Eip)
  410. }
  411. if quotas.Exceed(used.Eport, sreq.Eport, squota.Eport) {
  412. err.Add(used, "eport", squota.Eport, used.Eport, sreq.Eport)
  413. }
  414. //if quotas.Exceed(used.Bw, sreq.Bw, squota.Bw) {
  415. // err.Add(used, "bw", squota.Bw, used.Bw, sreq.Bw)
  416. //}
  417. //if quotas.Exceed(used.Bw, sreq.Ebw, squota.Ebw) {
  418. // err.Add(used, "ebw", squota.Ebw, used.Ebw, sreq.Ebw)
  419. //}
  420. if quotas.Exceed(used.Snapshot, sreq.Snapshot, squota.Snapshot) {
  421. err.Add(used, "snapshot", squota.Snapshot, used.Snapshot, sreq.Snapshot)
  422. }
  423. if quotas.Exceed(used.InstanceSnapshot, sreq.InstanceSnapshot, squota.InstanceSnapshot) {
  424. err.Add(used, "instance_snapshot", squota.InstanceSnapshot, used.InstanceSnapshot, sreq.InstanceSnapshot)
  425. }
  426. if quotas.Exceed(used.Bucket, sreq.Bucket, squota.Bucket) {
  427. err.Add(used, "bucket", squota.Bucket, used.Bucket, sreq.Bucket)
  428. }
  429. if quotas.Exceed(used.ObjectGB, sreq.ObjectGB, squota.ObjectGB) {
  430. err.Add(used, "object_gb", squota.ObjectGB, used.ObjectGB, sreq.ObjectGB)
  431. }
  432. if quotas.Exceed(used.ObjectCnt, sreq.ObjectCnt, squota.ObjectCnt) {
  433. err.Add(used, "object_cnt", squota.ObjectCnt, used.ObjectCnt, sreq.ObjectCnt)
  434. }
  435. if quotas.Exceed(used.Rds, sreq.Rds, squota.Rds) {
  436. err.Add(used, "rds", squota.Rds, used.Rds, sreq.Rds)
  437. }
  438. if quotas.Exceed(used.Cache, sreq.Cache, squota.Cache) {
  439. err.Add(used, "cache", squota.Cache, used.Cache, sreq.Cache)
  440. }
  441. if quotas.Exceed(used.Mongodb, sreq.Mongodb, squota.Mongodb) {
  442. err.Add(used, "mongodb", squota.Mongodb, used.Mongodb, sreq.Mongodb)
  443. }
  444. if quotas.Exceed(used.Loadbalancer, sreq.Loadbalancer, squota.Loadbalancer) {
  445. err.Add(used, "loadbalancer", squota.Loadbalancer, used.Loadbalancer, sreq.Loadbalancer)
  446. }
  447. if err.IsError() {
  448. return err
  449. } else {
  450. return nil
  451. }
  452. }
  453. func (self *SRegionQuota) ToJSON(prefix string) jsonutils.JSONObject {
  454. ret := jsonutils.NewDict()
  455. ret.Add(jsonutils.NewInt(int64(self.Port)), keyName(prefix, "port"))
  456. ret.Add(jsonutils.NewInt(int64(self.Eip)), keyName(prefix, "eip"))
  457. ret.Add(jsonutils.NewInt(int64(self.Eport)), keyName(prefix, "eport"))
  458. //ret.Add(jsonutils.NewInt(int64(self.Bw)), keyName(prefix, "bw"))
  459. //ret.Add(jsonutils.NewInt(int64(self.Ebw)), keyName(prefix, "ebw"))
  460. ret.Add(jsonutils.NewInt(int64(self.Snapshot)), keyName(prefix, "snapshot"))
  461. ret.Add(jsonutils.NewInt(int64(self.InstanceSnapshot)), keyName(prefix, "instance_snapshot"))
  462. ret.Add(jsonutils.NewInt(int64(self.Bucket)), keyName(prefix, "bucket"))
  463. ret.Add(jsonutils.NewInt(int64(self.ObjectGB)), keyName(prefix, "object_gb"))
  464. ret.Add(jsonutils.NewInt(int64(self.ObjectCnt)), keyName(prefix, "object_cnt"))
  465. ret.Add(jsonutils.NewInt(int64(self.Rds)), keyName(prefix, "rds"))
  466. ret.Add(jsonutils.NewInt(int64(self.Cache)), keyName(prefix, "cache"))
  467. ret.Add(jsonutils.NewInt(int64(self.Mongodb)), keyName(prefix, "mongodb"))
  468. ret.Add(jsonutils.NewInt(int64(self.Loadbalancer)), keyName(prefix, "loadbalancer"))
  469. return ret
  470. }