interface.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 quotas
  15. import (
  16. "context"
  17. "yunion.io/x/jsonutils"
  18. "yunion.io/x/pkg/object"
  19. "yunion.io/x/pkg/util/rbacscope"
  20. "yunion.io/x/onecloud/pkg/cloudcommon/db"
  21. "yunion.io/x/onecloud/pkg/mcclient"
  22. )
  23. type IQuotaKeys interface {
  24. Fields() []string
  25. Values() []string
  26. Compare(IQuotaKeys) int
  27. OwnerId() mcclient.IIdentityProvider
  28. Scope() rbacscope.TRbacScope
  29. }
  30. type IQuota interface {
  31. db.IUsage
  32. GetKeys() IQuotaKeys
  33. SetKeys(IQuotaKeys)
  34. FetchSystemQuota()
  35. // FetchUsage(ctx context.Context) error
  36. Update(quota IQuota)
  37. Add(quota IQuota)
  38. Sub(quota IQuota)
  39. Allocable(quota IQuota) int
  40. ResetNegative()
  41. Exceed(request IQuota, quota IQuota) error
  42. // IsEmpty() bool
  43. ToJSON(prefix string) jsonutils.JSONObject
  44. }
  45. type IQuotaStore interface {
  46. object.IObject
  47. GetQuota(ctx context.Context, keys IQuotaKeys, quota IQuota) error
  48. GetChildrenQuotas(ctx context.Context, keys IQuotaKeys) ([]IQuota, error)
  49. GetParentQuotas(ctx context.Context, keys IQuotaKeys) ([]IQuota, error)
  50. SetQuota(ctx context.Context, userCred mcclient.TokenCredential, quota IQuota) error
  51. AddQuota(ctx context.Context, userCred mcclient.TokenCredential, diff IQuota) error
  52. SubQuota(ctx context.Context, userCred mcclient.TokenCredential, diff IQuota) error
  53. DeleteQuota(ctx context.Context, userCred mcclient.TokenCredential, keys IQuotaKeys) error
  54. DeleteAllQuotas(ctx context.Context, userCred mcclient.TokenCredential, keys IQuotaKeys) error
  55. }
  56. type IQuotaManager interface {
  57. db.IResourceModelManager
  58. checkSetPendingQuota(ctx context.Context, userCred mcclient.TokenCredential, quota IQuota) error
  59. cancelPendingUsage(ctx context.Context, userCred mcclient.TokenCredential, localUsage IQuota, cancelUsage IQuota, save bool) error
  60. cancelUsage(ctx context.Context, userCred mcclient.TokenCredential, usage IQuota) error
  61. addUsage(ctx context.Context, userCred mcclient.TokenCredential, usage IQuota) error
  62. getQuotaCount(ctx context.Context, request IQuota, pendingKey IQuotaKeys) (int, error)
  63. FetchIdNames(ctx context.Context, idMap map[string]map[string]string) (map[string]map[string]string, error)
  64. }