quotas

package
v0.3.10-0-alpha.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 15, 2022 License: Apache-2.0 Imports: 27 Imported by: 17

Documentation

Index

Constants

View Source
const (
	QUOTA_ACTION_ADD     = "add"
	QUOTA_ACTION_SUB     = "sub"
	QUOTA_ACTION_RESET   = "reset"
	QUOTA_ACTION_REPLACE = "replace"
	QUOTA_ACTION_UPDATE  = "update"
	QUOTA_ACTION_DELETE  = "delete"
)
View Source
const (
	QuotaKeysContain = TQuotaKeysRelation("contain")
	QuotaKeysBelong  = TQuotaKeysRelation("belong")
	QuotaKeysEqual   = TQuotaKeysRelation("equal")
	QuotaKeysExclude = TQuotaKeysRelation("exclude")
)
View Source
const (
	APP_CONTEXT_KEY_PENDINGUSAGES = appctx.AppContextKey("pendingusages")
)
View Source
const (
	METADATA_KEY = "quota"
)

Variables

This section is empty.

Functions

func AddQuotaHandler

func AddQuotaHandler(manager *SQuotaBaseManager, prefix string, app *appsrv.Application)

func AddUsages

func AddUsages(ctx context.Context, userCred mcclient.TokenCredential, usages []db.IUsage)

func CancelPendingUsage

func CancelPendingUsage(ctx context.Context, userCred mcclient.TokenCredential, localUsage IQuota, cancelUsage IQuota, save bool) error

func CancelUsages

func CancelUsages(ctx context.Context, userCred mcclient.TokenCredential, usages []db.IUsage)

func CheckSetPendingQuota

func CheckSetPendingQuota(ctx context.Context, userCred mcclient.TokenCredential, quota IQuota) error

func Exceed

func Exceed(used, request, quota int) bool

func GetQuotaCount

func GetQuotaCount(ctx context.Context, request IQuota, pendingKeys IQuotaKeys) (int, error)

func IsBaseDomainQuotaKeys

func IsBaseDomainQuotaKeys(k IQuotaKeys) bool

func IsBaseProjectQuotaKeys

func IsBaseProjectQuotaKeys(k IQuotaKeys) bool

func KeyName

func KeyName(prefix, name string) string

func LockQuota

func LockQuota(ctx context.Context, manager IQuotaManager, quota IQuota)

func LockQuotaKeys

func LockQuotaKeys(ctx context.Context, manager IQuotaManager, keys IQuotaKeys)

func NonNegative

func NonNegative(val int) int

func QuotaKeyString

func QuotaKeyString(k IQuotaKeys) string

func QuotaKeyWeight

func QuotaKeyWeight(k IQuotaKeys) uint64

func Register

func Register(manager IQuotaManager)

func ReleaseQuota

func ReleaseQuota(ctx context.Context, manager IQuotaManager, quota IQuota)

func ReleaseQuotaKeys

func ReleaseQuotaKeys(ctx context.Context, manager IQuotaManager, keys IQuotaKeys)

Types

type IQuota

type IQuota interface {
	db.IUsage

	GetKeys() IQuotaKeys
	SetKeys(IQuotaKeys)

	FetchSystemQuota()
	// FetchUsage(ctx context.Context) error
	Update(quota IQuota)
	Add(quota IQuota)
	Sub(quota IQuota)
	Allocable(quota IQuota) int
	ResetNegative()
	Exceed(request IQuota, quota IQuota) error
	// IsEmpty() bool
	ToJSON(prefix string) jsonutils.JSONObject
}

type IQuotaKeys

type IQuotaKeys interface {
	Fields() []string
	Values() []string
	Compare(IQuotaKeys) int

	OwnerId() mcclient.IIdentityProvider

	Scope() rbacutils.TRbacScope
}

type IQuotaManager

type IQuotaManager interface {
	db.IResourceModelManager

	FetchIdNames(ctx context.Context, idMap map[string]map[string]string) (map[string]map[string]string, error)
	// contains filtered or unexported methods
}

type IQuotaStore

type IQuotaStore interface {
	object.IObject

	GetQuota(ctx context.Context, keys IQuotaKeys, quota IQuota) error
	GetChildrenQuotas(ctx context.Context, keys IQuotaKeys) ([]IQuota, error)
	GetParentQuotas(ctx context.Context, keys IQuotaKeys) ([]IQuota, error)

	SetQuota(ctx context.Context, userCred mcclient.TokenCredential, quota IQuota) error
	AddQuota(ctx context.Context, userCred mcclient.TokenCredential, diff IQuota) error
	SubQuota(ctx context.Context, userCred mcclient.TokenCredential, diff IQuota) error

	DeleteQuota(ctx context.Context, userCred mcclient.TokenCredential, keys IQuotaKeys) error
	DeleteAllQuotas(ctx context.Context, userCred mcclient.TokenCredential, keys IQuotaKeys) error
}

type SBaseDomainQuotaDetailKeys

type SBaseDomainQuotaDetailKeys struct {
	// 配额适用的项目的域名称
	Domain string `json:"domain"`
}

type SBaseDomainQuotaKeys

type SBaseDomainQuotaKeys struct {
	// 配额适用的域ID
	DomainId string `width:"64" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"domain_id"`
}

func OwnerIdDomainQuotaKeys

func OwnerIdDomainQuotaKeys(ownerId mcclient.IIdentityProvider) SBaseDomainQuotaKeys

func (SBaseDomainQuotaKeys) Compare

func (k1 SBaseDomainQuotaKeys) Compare(ik IQuotaKeys) int

func (SBaseDomainQuotaKeys) Fields

func (k SBaseDomainQuotaKeys) Fields() []string

func (SBaseDomainQuotaKeys) OwnerId

func (SBaseDomainQuotaKeys) Scope

func (SBaseDomainQuotaKeys) Values

func (k SBaseDomainQuotaKeys) Values() []string

type SBaseProjectQuotaDetailKeys

type SBaseProjectQuotaDetailKeys struct {
	SBaseDomainQuotaDetailKeys
	// 配额适用的项目名称
	Project string `json:"project"`
}

type SBaseProjectQuotaKeys

type SBaseProjectQuotaKeys struct {
	SBaseDomainQuotaKeys

	// 配额适用的项目ID
	ProjectId string `name:"tenant_id" width:"64" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"project_id"`
}

func (SBaseProjectQuotaKeys) Compare

func (k1 SBaseProjectQuotaKeys) Compare(ik IQuotaKeys) int

func (SBaseProjectQuotaKeys) Fields

func (k SBaseProjectQuotaKeys) Fields() []string

func (SBaseProjectQuotaKeys) OwnerId

func (SBaseProjectQuotaKeys) Scope

func (SBaseProjectQuotaKeys) Values

func (k SBaseProjectQuotaKeys) Values() []string

type SBaseQuotaQueryInput

type SBaseQuotaQueryInput struct {
	// 只列出主配额
	// require:false
	Primary bool `json:"primary"`
	// 强制刷新使用量
	// require:false
	Refresh bool `json:"refresh"`
}

type SBaseQuotaSetInput

type SBaseQuotaSetInput struct {
	// 设置配额操作
	//
	// | action  | 说明                                      |
	// |---------|-------------------------------------------|
	// | add     | 增量增加配额                              |
	// | sub     | 增量减少配额                              |
	// | reset   | 重置所有配额为0                           |
	// | replace | 替换所有配额,对于不存在的配额项,设置为0 |
	// | update  | 更新存在的配额                            |
	// | delete  | 删除配额                                  |
	//
	Action string `json:"action"`
}

type SCloudResourceBaseKeys

type SCloudResourceBaseKeys struct {
	// 配额适用的平台名称,参考List接口的平台列表
	Provider string `width:"32" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"provider"`
	// 配额适用的品牌名称,参考List接口的品牌列表
	Brand string `width:"32" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"brand"`
	// 配额适用的云环境,参考List接口的云环境列表
	CloudEnv string `width:"32" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"cloud_env"`
	// 配额适用的云账号ID
	AccountId string `width:"64" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"account_id"`
	// 配额适用的云订阅ID
	ManagerId string `width:"64" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"manager_id"`
}

func (SCloudResourceBaseKeys) Fields

func (k SCloudResourceBaseKeys) Fields() []string

func (SCloudResourceBaseKeys) Values

func (k SCloudResourceBaseKeys) Values() []string

type SCloudResourceDetailBaseKeys

type SCloudResourceDetailBaseKeys struct {
	// 配额适用的云账号名称
	Account string `json:"account"`
	// 配额适用的云订阅名称
	Manager string `json:"manager"`
}

type SCloudResourceKeys

type SCloudResourceKeys struct {
	SBaseProjectQuotaKeys
	SCloudResourceBaseKeys
}

func (SCloudResourceKeys) Compare

func (k1 SCloudResourceKeys) Compare(ik IQuotaKeys) int

func (SCloudResourceKeys) Fields

func (k SCloudResourceKeys) Fields() []string

func (SCloudResourceKeys) Values

func (k SCloudResourceKeys) Values() []string

type SDBQuotaStore

type SDBQuotaStore struct {
}

func (*SDBQuotaStore) GetQuota

func (store *SDBQuotaStore) GetQuota(ctx context.Context, scope rbacutils.TRbacScope, ownerId mcclient.IIdentityProvider, quota IQuota) error

type SDomainRegionalCloudResourceKeys

type SDomainRegionalCloudResourceKeys struct {
	SBaseDomainQuotaKeys
	SCloudResourceBaseKeys
	SRegionalBaseKeys
}

func (SDomainRegionalCloudResourceKeys) Compare

func (SDomainRegionalCloudResourceKeys) Fields

func (SDomainRegionalCloudResourceKeys) Values

type SOutOfQuotaError

type SOutOfQuotaError struct {
	// contains filtered or unexported fields
}

func (*SOutOfQuotaError) Cause

func (e *SOutOfQuotaError) Cause() error

func (*SOutOfQuotaError) Error

func (e *SOutOfQuotaError) Error() string

type SOutOfQuotaErrors

type SOutOfQuotaErrors struct {
	// contains filtered or unexported fields
}

func NewOutOfQuotaError

func NewOutOfQuotaError() *SOutOfQuotaErrors

func (*SOutOfQuotaErrors) Add

func (es *SOutOfQuotaErrors) Add(quota IQuota, name string, limit int, used int, request int)

func (*SOutOfQuotaErrors) Cause

func (es *SOutOfQuotaErrors) Cause() error

func (*SOutOfQuotaErrors) Error

func (es *SOutOfQuotaErrors) Error() string

func (*SOutOfQuotaErrors) IsError

func (es *SOutOfQuotaErrors) IsError() bool

type SQuotaBase

type SQuotaBase struct {
	db.SResourceBase
}

type SQuotaBaseManager

type SQuotaBaseManager struct {
	db.SResourceBaseManager
	// contains filtered or unexported fields
}

func NewQuotaBaseManager

func NewQuotaBaseManager(model interface{}, scope rbacutils.TRbacScope, tableName string, pendingStore IQuotaStore, usageStore IQuotaStore, keyword, keywordPlural string) SQuotaBaseManager

func NewQuotaUsageManager

func NewQuotaUsageManager(model interface{}, scope rbacutils.TRbacScope, tableName string, keyword, keywordPlural string) SQuotaBaseManager

func (*SQuotaBaseManager) AddQuota

func (manager *SQuotaBaseManager) AddQuota(ctx context.Context, userCred mcclient.TokenCredential, diff IQuota) error

func (*SQuotaBaseManager) CalculateQuotaUsages

func (manager *SQuotaBaseManager) CalculateQuotaUsages(ctx context.Context, userCred mcclient.TokenCredential, isStart bool)

func (*SQuotaBaseManager) DeleteAllQuotas

func (manager *SQuotaBaseManager) DeleteAllQuotas(ctx context.Context, userCred mcclient.TokenCredential, keys IQuotaKeys) error

func (*SQuotaBaseManager) DeleteQuota

func (manager *SQuotaBaseManager) DeleteQuota(ctx context.Context, userCred mcclient.TokenCredential, keys IQuotaKeys) error

func (*SQuotaBaseManager) FetchIdNames

func (manager *SQuotaBaseManager) FetchIdNames(ctx context.Context, idMap map[string]map[string]string) (map[string]map[string]string, error)

func (*SQuotaBaseManager) FetchOwnerId

func (*SQuotaBaseManager) GetChildrenQuotas

func (manager *SQuotaBaseManager) GetChildrenQuotas(ctx context.Context, keys IQuotaKeys) ([]IQuota, error)

func (*SQuotaBaseManager) GetIQuotaManager

func (manager *SQuotaBaseManager) GetIQuotaManager() IQuotaManager

func (*SQuotaBaseManager) GetParentQuotas

func (manager *SQuotaBaseManager) GetParentQuotas(ctx context.Context, keys IQuotaKeys) ([]IQuota, error)

func (*SQuotaBaseManager) GetPendingUsages

func (manager *SQuotaBaseManager) GetPendingUsages(ctx context.Context, keys IQuotaKeys) ([]IQuota, error)

func (*SQuotaBaseManager) GetQuota

func (manager *SQuotaBaseManager) GetQuota(ctx context.Context, keys IQuotaKeys, quota IQuota) error

func (*SQuotaBaseManager) InitializeData

func (manager *SQuotaBaseManager) InitializeData() error

func (*SQuotaBaseManager) PostUsageJob

func (manager *SQuotaBaseManager) PostUsageJob(keys IQuotaKeys, usageChan chan IQuota, realTime bool)

func (*SQuotaBaseManager) ResourceScope

func (manager *SQuotaBaseManager) ResourceScope() rbacutils.TRbacScope

func (*SQuotaBaseManager) SetQuota

func (manager *SQuotaBaseManager) SetQuota(ctx context.Context, userCred mcclient.TokenCredential, quota IQuota) error

func (*SQuotaBaseManager) SubQuota

func (manager *SQuotaBaseManager) SubQuota(ctx context.Context, userCred mcclient.TokenCredential, diff IQuota) error

type SRegionalBaseKeys

type SRegionalBaseKeys struct {
	// 配额适用的区域ID
	RegionId string `width:"64" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"region_id"`
}

type SRegionalCloudResourceDetailBaseKeys

type SRegionalCloudResourceDetailBaseKeys struct {
	// 配额适用的区域名称
	Region string `json:"region"`
}

type SRegionalCloudResourceKeys

type SRegionalCloudResourceKeys struct {
	SCloudResourceKeys
	SRegionalBaseKeys
}

func (SRegionalCloudResourceKeys) Compare

func (k1 SRegionalCloudResourceKeys) Compare(ik IQuotaKeys) int

func (SRegionalCloudResourceKeys) Fields

func (k SRegionalCloudResourceKeys) Fields() []string

func (SRegionalCloudResourceKeys) Values

func (k SRegionalCloudResourceKeys) Values() []string

type SZonalCloudResourceDetailKeys

type SZonalCloudResourceDetailKeys struct {
	SRegionalCloudResourceDetailKeys

	// 配额适用的可用区名称
	Zone string `json:"zone"`
}

type SZonalCloudResourceKeys

type SZonalCloudResourceKeys struct {
	SRegionalCloudResourceKeys
	// 配额适用的可用区ID
	ZoneId string `width:"64" charset:"ascii" nullable:"false" primary:"true" list:"user" json:"zone_id"`
}

func (SZonalCloudResourceKeys) Compare

func (k1 SZonalCloudResourceKeys) Compare(ik IQuotaKeys) int

func (SZonalCloudResourceKeys) Fields

func (k SZonalCloudResourceKeys) Fields() []string

func (SZonalCloudResourceKeys) Values

func (k SZonalCloudResourceKeys) Values() []string

type TQuotaKeysRelation

type TQuotaKeysRelation string

type TQuotaList

type TQuotaList []IQuota

func (TQuotaList) Len

func (a TQuotaList) Len() int

func (TQuotaList) Less

func (a TQuotaList) Less(i, j int) bool

func (TQuotaList) Swap

func (a TQuotaList) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL