Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
synnefo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
itminedu
synnefo
Commits
7bdec18f
Commit
7bdec18f
authored
Dec 13, 2012
by
Giorgos Korfiatis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add_quota API call
parent
c8d9e13c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
0 deletions
+114
-0
snf-common/synnefo/lib/quotaholder/api/quotaholder.py
snf-common/synnefo/lib/quotaholder/api/quotaholder.py
+14
-0
snf-quotaholder-app/quotaholder_django/quotaholder_app/callpoint.py
...older-app/quotaholder_django/quotaholder_app/callpoint.py
+66
-0
snf-quotaholder-app/quotaholder_django/test/simpletests.py
snf-quotaholder-app/quotaholder_django/test/simpletests.py
+34
-0
No files found.
snf-common/synnefo/lib/quotaholder/api/quotaholder.py
View file @
7bdec18f
...
...
@@ -76,6 +76,10 @@ Quantity = Integer(classname='Quantity', null=True)
Capacity
=
Nonnegative
(
classname
=
'Capacity'
,
null
=
True
)
ImportLimit
=
Nonnegative
(
classname
=
'ImportLimit'
,
null
=
True
)
ExportLimit
=
Nonnegative
(
classname
=
'ExportLimit'
,
null
=
True
)
QuantityDelta
=
Integer
(
classname
=
'QuantityDelta'
,
null
=
True
)
CapacityDelta
=
Integer
(
classname
=
'CapacityDelta'
,
null
=
True
)
ImportLimitDelta
=
Integer
(
classname
=
'ImportLimitDelta'
,
null
=
True
)
ExportLimitDelta
=
Integer
(
classname
=
'ExportLimitDelta'
,
null
=
True
)
Imported
=
Nonnegative
(
classname
=
'Imported'
)
Exported
=
Nonnegative
(
classname
=
'Exported'
)
Returned
=
Nonnegative
(
classname
=
'Returned'
)
...
...
@@ -230,6 +234,16 @@ class QuotaholderAPI(Specificator):
rejected
=
ListOf
(
Entity
,
Resource
)
return
rejected
def
add_quota
(
self
,
context
=
Context
,
add_quota
=
ListOf
(
Entity
,
Resource
,
Key
,
QuantityDelta
,
CapacityDelta
,
ImportLimitDelta
,
ExportLimitDelta
)
):
rejected
=
ListOf
(
Entity
,
Resource
)
return
rejected
def
issue_commission
(
self
,
context
=
Context
,
...
...
snf-quotaholder-app/quotaholder_django/quotaholder_app/callpoint.py
View file @
7bdec18f
...
...
@@ -506,6 +506,59 @@ class QuotaholderDjangoDBCallpoint(Callpoint):
raise
ReturnButFail
(
rejected
)
return
rejected
def
add_quota
(
self
,
context
=
{},
add_quota
=
()):
rejected
=
[]
append
=
rejected
.
append
for
(
entity
,
resource
,
key
,
quantity
,
capacity
,
import_limit
,
export_limit
)
in
add_quota
:
try
:
e
=
Entity
.
objects
.
get
(
entity
=
entity
,
key
=
key
)
except
Entity
.
DoesNotExist
:
append
((
entity
,
resource
))
continue
try
:
h
=
db_get_holding
(
entity
=
entity
,
resource
=
resource
,
for_update
=
True
)
p
=
h
.
policy
except
Holding
.
DoesNotExist
:
h
=
Holding
(
entity
=
e
,
resource
=
resource
,
flags
=
0
)
p
=
None
policy
=
newname
(
'policy_'
)
newp
=
Policy
(
policy
=
policy
)
newp
.
quantity
=
_add
(
p
.
quantity
if
p
else
0
,
quantity
)
newp
.
capacity
=
_add
(
p
.
capacity
if
p
else
0
,
capacity
)
newp
.
import_limit
=
_add
(
p
.
import_limit
if
p
else
0
,
import_limit
)
newp
.
export_limit
=
_add
(
p
.
export_limit
if
p
else
0
,
export_limit
)
new_values
=
[
newp
.
capacity
,
newp
.
import_limit
,
newp
.
export_limit
]
if
any
(
map
(
_isneg
,
new_values
)):
append
((
entity
,
resource
))
continue
h
.
policy
=
newp
# the order is intentionally reversed so that it
# would break if we are not within a transaction.
# Has helped before.
h
.
save
()
newp
.
save
()
if
p
is
not
None
and
p
.
holding_set
.
count
()
==
0
:
p
.
delete
()
if
rejected
:
raise
ReturnButFail
(
rejected
)
return
rejected
def
issue_commission
(
self
,
context
=
{},
clientkey
=
None
,
target
=
None
,
...
...
@@ -864,6 +917,19 @@ class QuotaholderDjangoDBCallpoint(Callpoint):
return
timeline
def
_add
(
x
,
y
):
if
x
is
None
or
y
is
None
:
return
None
return
x
+
y
def
_update
(
dest
,
source
,
attr
,
delta
):
dest_attr
=
getattr
(
dest
,
attr
)
dest_attr
=
_add
(
getattr
(
source
,
attr
,
0
),
delta
)
def
_isneg
(
x
):
if
x
is
None
:
return
False
return
x
<
0
API_Callpoint
=
QuotaholderDjangoDBCallpoint
snf-quotaholder-app/quotaholder_django/test/simpletests.py
View file @
7bdec18f
...
...
@@ -223,6 +223,40 @@ class QHAPITest(QHTestCase):
self
.
assertEqual
(
r
,
[])
return
limits
def
test_0081_add_quota
(
self
):
e0
,
k0
=
self
.
new_entity
()
e1
,
k1
=
self
.
new_entity
()
resource0
=
self
.
rand_resource
()
resource1
=
self
.
rand_resource
()
r
=
self
.
qh
.
set_quota
(
set_quota
=
[(
e0
,
resource0
,
k0
)
+
(
5
,
5
,
5
,
5
)
+
(
0
,),
(
e1
,
resource0
,
k1
)
+
(
5
,
5
,
5
,
5
)
+
(
0
,)])
self
.
assertEqual
(
r
,
[])
r
=
self
.
qh
.
add_quota
(
add_quota
=
[(
e0
,
resource0
,
k0
,
0
,
(
-
2
),
None
,
0
),
(
e0
,
resource1
,
k0
,
0
,
None
,
5
,
5
)])
self
.
assertEqual
(
r
,
[])
r
=
self
.
qh
.
get_quota
(
get_quota
=
[(
e0
,
resource0
,
k0
),
(
e0
,
resource1
,
k0
)])
self
.
assertEqual
(
r
,
[(
e0
,
resource0
,
5
,
5
-
2
,
None
,
5
)
+
DEFAULT_HOLDING
+
(
0
,),
(
e0
,
resource1
,
0
,
None
,
5
,
5
)
+
DEFAULT_HOLDING
+
(
0
,)])
# none is committed
r
=
self
.
qh
.
add_quota
(
add_quota
=
[(
e1
,
resource0
,
k1
,
0
,
(
-
10
),
None
,
0
),
(
e0
,
resource1
,
k0
,
1
,
0
,
0
,
0
)])
self
.
assertEqual
(
r
,
[(
e1
,
resource0
)])
r
=
self
.
qh
.
get_quota
(
get_quota
=
[(
e1
,
resource0
,
k1
),
(
e0
,
resource1
,
k0
)])
self
.
assertEqual
(
r
,
[(
e1
,
resource0
,
5
,
5
,
5
,
5
)
+
DEFAULT_HOLDING
+
(
0
,),
(
e0
,
resource1
,
0
,
None
,
5
,
5
)
+
DEFAULT_HOLDING
+
(
0
,)])
def
test_009_commissions
(
self
):
e0
,
k0
=
self
.
new_entity
()
e1
,
k1
=
self
.
new_entity
()
...
...
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