Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
itminedu
synnefo
Commits
e0eab033
Commit
e0eab033
authored
Mar 01, 2013
by
Giorgos Korfiatis
Browse files
wip Update astakos.im to simplified quotaholder policy
parent
6ef75321
Changes
3
Hide whitespace changes
Inline
Side-by-side
snf-astakos-app/astakos/im/endpoints/qh.py
View file @
e0eab033
...
...
@@ -99,10 +99,10 @@ def qh_get_holdings(users, resources):
def
quota_limits_per_user_from_get
(
lst
):
quotas
=
{}
for
holder
,
resource
,
q
,
c
,
il
,
el
,
imp
,
exp
,
ret
,
rel
,
flags
in
lst
:
for
holder
,
resource
,
q
,
c
,
imp
,
exp
,
ret
,
rel
,
flags
in
lst
:
userquotas
=
quotas
.
get
(
holder
,
{})
userquotas
[
resource
]
=
QuotaValues
(
quantity
=
q
,
capacity
=
c
,
import_limit
=
il
,
export_limit
=
el
)
)
quotas
[
holder
]
=
userquotas
return
quotas
...
...
@@ -110,10 +110,10 @@ def quota_limits_per_user_from_get(lst):
def
quotas_per_user_from_get
(
lst
):
limits
=
{}
counters
=
{}
for
holder
,
resource
,
q
,
c
,
il
,
el
,
imp
,
exp
,
ret
,
rel
,
flags
in
lst
:
for
holder
,
resource
,
q
,
c
,
imp
,
exp
,
ret
,
rel
,
flags
in
lst
:
userlimits
=
limits
.
get
(
holder
,
{})
userlimits
[
resource
]
=
QuotaValues
(
quantity
=
q
,
capacity
=
c
,
import_limit
=
il
,
export_limit
=
el
)
)
limits
[
holder
]
=
userlimits
usercounters
=
counters
.
get
(
holder
,
{})
...
...
@@ -154,15 +154,12 @@ SetQuotaPayload = namedtuple('SetQuotaPayload', ('holder',
'resource'
,
'quantity'
,
'capacity'
,
'import_limit'
,
'export_limit'
,
'flags'
))
QuotaLimits
=
namedtuple
(
'QuotaLimits'
,
(
'holder'
,
'resource'
,
'capacity'
,
'import_limit'
,
'export_limit'
))
))
QuotaCounters
=
namedtuple
(
'QuotaCounters'
,
(
'imported'
,
'exported'
,
...
...
@@ -172,12 +169,11 @@ QuotaCounters = namedtuple('QuotaCounters', ('imported',
class
QuotaValues
(
namedtuple
(
'QuotaValues'
,
(
'quantity'
,
'capacity'
,
'import_limit'
,
'export_limit'
))):
))):
__slots__
=
()
def
__dir__
(
self
):
return
[
'quantity'
,
'capacity'
,
'import_limit'
,
'export_limit'
]
return
[
'quantity'
,
'capacity'
]
def
__str__
(
self
):
return
'
\t
'
.
join
([
'%s=%s'
%
(
f
,
strbigdec
(
getattr
(
self
,
f
)))
...
...
@@ -188,8 +184,7 @@ def add_quota_values(q1, q2):
return
QuotaValues
(
quantity
=
q1
.
quantity
+
q2
.
quantity
,
capacity
=
q1
.
capacity
+
q2
.
capacity
,
import_limit
=
q1
.
import_limit
+
q2
.
import_limit
,
export_limit
=
q1
.
export_limit
+
q2
.
export_limit
)
)
def
register_quotas
(
quotas
):
...
...
@@ -205,8 +200,6 @@ def register_quotas(quotas):
resource
=
resource
,
quantity
=
q
.
quantity
,
capacity
=
q
.
capacity
,
import_limit
=
q
.
import_limit
,
export_limit
=
q
.
export_limit
,
flags
=
0
))
return
set_quota
(
payload
)
...
...
@@ -224,8 +217,6 @@ def send_quotas(userquotas):
resource
=
resource
,
quantity
=
q
.
quantity
,
capacity
=
q
.
capacity
,
import_limit
=
q
.
import_limit
,
export_limit
=
q
.
export_limit
,
flags
=
0
))
return
set_quota
(
payload
)
...
...
@@ -237,8 +228,6 @@ def register_resources(resources):
resource
=
resource
,
quantity
=
QH_PRACTICALLY_INFINITE
,
capacity
=
QH_PRACTICALLY_INFINITE
,
import_limit
=
QH_PRACTICALLY_INFINITE
,
export_limit
=
QH_PRACTICALLY_INFINITE
,
flags
=
0
)
for
resource
in
resources
)
return
set_quota
(
payload
)
...
...
@@ -254,12 +243,12 @@ def qh_add_quota(sub_list, add_list):
for
ql
in
sub_list
:
args
=
(
ql
.
holder
,
ql
.
resource
,
0
,
ql
.
capacity
,
ql
.
import_limit
,
ql
.
export_limit
)
0
,
ql
.
capacity
)
sub_append
(
args
)
for
ql
in
add_list
:
args
=
(
ql
.
holder
,
ql
.
resource
,
0
,
ql
.
capacity
,
ql
.
import_limit
,
ql
.
export_limit
)
0
,
ql
.
capacity
)
add_append
(
args
)
result
=
c
.
add_quota
(
context
=
context
,
...
...
snf-astakos-app/astakos/im/management/commands/user-set-initial-quota.py
View file @
e0eab033
...
...
@@ -47,8 +47,7 @@ from astakos.im.models import AstakosUser, AstakosUserQuota, Resource
AddResourceArgs
=
namedtuple
(
'AddQuotaArgs'
,
(
'resource'
,
'capacity'
,
'quantity'
,
'import_limit'
,
'export_limit'
))
))
class
Command
(
BaseCommand
):
help
=
"""Import user quota limits from file or set quota
...
...
@@ -57,15 +56,12 @@ for a single user from the command line
The file must contain non-empty lines, and each line must
contain a single-space-separated list of values:
<user> <resource name> <capacity> <quantity>
<import_limit> <export_limit>
<user> <resource name> <capacity> <quantity>
For example to grant the following user with 10 private networks
(independent of any he receives from projects):
6119a50b-cbc7-42c0-bafc-4b6570e3f6ac cyclades.network.private 10 0 1000000 1000000
The last two values are arbitrarily large to represent no
import/export limit at all.
6119a50b-cbc7-42c0-bafc-4b6570e3f6ac cyclades.network.private 10 0
When setting quota from the command line, specify only capacity.
Quantity and import/export limit will get default values. Example:
...
...
@@ -139,8 +135,6 @@ for a single user from the command line
args
=
AddResourceArgs
(
resource
=
resource
,
capacity
=
capacity
,
quantity
=
0
,
import_limit
=
QH_PRACTICALLY_INFINITE
,
export_limit
=
QH_PRACTICALLY_INFINITE
,
)
try
:
...
...
snf-astakos-app/astakos/im/models.py
View file @
e0eab033
...
...
@@ -259,8 +259,7 @@ def _quota_values(capacity):
return
QuotaValues
(
quantity
=
0
,
capacity
=
capacity
,
import_limit
=
QH_PRACTICALLY_INFINITE
,
export_limit
=
QH_PRACTICALLY_INFINITE
)
)
def
get_default_quota
():
_DEFAULT_QUOTA
=
{}
...
...
@@ -460,14 +459,12 @@ class AstakosUser(User):
p
.
setdefault
(
'resource'
,
''
)
p
.
setdefault
(
'capacity'
,
0
)
p
.
setdefault
(
'quantity'
,
0
)
p
.
setdefault
(
'import_limit'
,
0
)
p
.
setdefault
(
'export_limit'
,
0
)
p
.
setdefault
(
'update'
,
True
)
self
.
add_resource_policy
(
**
p
)
def
add_resource_policy
(
self
,
resource
,
capacity
,
quantity
,
import_limit
,
export_limit
,
update
=
True
):
self
,
resource
,
capacity
,
quantity
,
update
=
True
):
"""Raises ObjectDoesNotExist, IntegrityError"""
s
,
sep
,
r
=
resource
.
partition
(
RESOURCE_SEPARATOR
)
resource
=
Resource
.
objects
.
get
(
service__name
=
s
,
name
=
r
)
...
...
@@ -476,13 +473,12 @@ class AstakosUser(User):
user
=
self
,
resource
=
resource
,
defaults
=
{
'capacity'
:
capacity
,
'quantity'
:
quantity
,
'import_limit'
:
import_limit
,
'export_limit'
:
export_limit
})
})
else
:
q
=
self
.
astakosuserquota_set
q
.
create
(
resource
=
resource
,
capacity
=
capacity
,
quanity
=
quantity
,
import_limit
=
import_limit
,
export_limit
=
export_limit
)
)
def
get_resource_policy
(
self
,
resource
):
s
,
sep
,
r
=
resource
.
partition
(
RESOURCE_SEPARATOR
)
...
...
@@ -1066,8 +1062,7 @@ class AstakosUserQuota(models.Model):
return
QuotaValues
(
quantity
=
self
.
quantity
,
capacity
=
self
.
capacity
,
import_limit
=
self
.
import_limit
,
export_limit
=
self
.
export_limit
)
)
class
ApprovalTerms
(
models
.
Model
):
...
...
@@ -1792,8 +1787,7 @@ class ProjectResourceGrant(models.Model):
return
QuotaValues
(
quantity
=
0
,
capacity
=
self
.
member_capacity
,
import_limit
=
self
.
member_import_limit
,
export_limit
=
self
.
member_export_limit
)
)
def
display_member_capacity
(
self
):
if
self
.
member_capacity
:
...
...
@@ -2295,8 +2289,7 @@ class ProjectMembership(models.Model):
holder
=
holder
,
resource
=
str
(
grant
.
resource
),
capacity
=
grant
.
member_capacity
,
import_limit
=
grant
.
member_import_limit
,
export_limit
=
grant
.
member_export_limit
))
))
pending_application
=
self
.
pending_application
if
pending_application
is
not
None
:
...
...
@@ -2306,8 +2299,7 @@ class ProjectMembership(models.Model):
holder
=
holder
,
resource
=
str
(
new_grant
.
resource
),
capacity
=
new_grant
.
member_capacity
,
import_limit
=
new_grant
.
member_import_limit
,
export_limit
=
new_grant
.
member_export_limit
))
))
return
(
sub_list
,
add_list
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment