Commit 3605cf6a authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

astakos: Set and return commission names in API calls

Support issue_commission's `name' parameter for an optional description
of the commission. Include this field in the dict returned by
get_commission.

Change astakosclient accordingly.
parent 58863f91
......@@ -375,7 +375,7 @@ class AstakosClient():
raise AstakosClientException(m)
def issue_one_commission(self, token, holder, source, provisions,
force=False, auto_accept=False):
name="", force=False, auto_accept=False):
"""Issue one commission (with specific holder and source)
keyword arguments:
......@@ -383,6 +383,7 @@ class AstakosClient():
holder -- user's id (string)
source -- commission's source (ex system) (string)
provisions -- resources with their quantity (list of (string, int))
name -- description of the commission (string)
force -- force this commission (boolean)
auto_accept -- auto accept this commission (boolean)
......@@ -398,6 +399,7 @@ class AstakosClient():
request = {}
request["force"] = force
request["auto_accept"] = auto_accept
request["name"] = name
try:
request["provisions"] = []
for p in provisions:
......
......@@ -390,6 +390,7 @@ quotas = {
commission_request = {
"force": False,
"auto_accept": False,
"name": "my commission",
"provisions": [
{
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad",
......@@ -425,6 +426,7 @@ pending_commissions = [100, 200]
commission_description = {
"serial": 57,
"issue_time": "2013-04-08T10:19:15.0373",
"name": "a commission",
"provisions": [
{
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad",
......
......@@ -140,7 +140,7 @@ retry=0, use_pool=False, pool_size=8, logger=None\ **)**
In case of success return commission's id (int).
Otherwise raise an AstakosClientException exception.
**issue_one_commission(**\ token, holder, source, provisions, force=False, auto_accept=False\ **)**
**issue_one_commission(**\ token, holder, source, provisions, name="", force=False, auto_accept=False\ **)**
Given a service's authentication token issue a commission.
In this case we specify the holder, the source and the provisions
(a list of (string, int)) and astakosclient will create the
......
......@@ -183,6 +183,7 @@ Status Description
{
"force": false,
"auto_accept": false,
"name": "an optional description",
"provisions": [
{
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad",
......@@ -287,6 +288,7 @@ Status Description
{
"serial": 57,
"issue_time": "2013-04-08T10:19:15.0373",
"name": "an optional description",
"provisions": [
{
"holder": "c02f315b-7d84-45bc-a383-552a3f97d2ad",
......
......@@ -129,16 +129,26 @@ def issue_commission(request):
provisions = input_data.get('provisions')
if provisions is None:
raise BadRequest("Provisions are missing.")
if not isinstance (provisions, list):
if not isinstance(provisions, list):
raise BadRequest("Provisions should be a list.")
provisions = _provisions_to_list(provisions)
force = input_data.get('force', False)
if not isinstance(force, bool):
raise BadRequest('"force" option should be a boolean.')
auto_accept = input_data.get('auto_accept', False)
if not isinstance(auto_accept, bool):
raise BadRequest('"auto_accept" option should be a boolean.')
name = input_data.get('name', "")
if not isinstance(name, str):
raise BadRequest("Commission name should be a string.")
try:
result = _issue_commission(clientkey=client_key,
provisions=provisions,
name=name,
force=force,
accept=auto_accept)
data = {"serial": result}
......@@ -169,9 +179,10 @@ def issue_commission(request):
@commit_on_success_strict()
def _issue_commission(clientkey, provisions, force, accept):
def _issue_commission(clientkey, provisions, name, force, accept):
serial = qh.issue_commission(clientkey=clientkey,
provisions=provisions,
name=name,
force=force)
if accept:
done = qh.resolve_pending_commission(clientkey=clientkey,
......
......@@ -307,5 +307,6 @@ def get_commission(clientkey, serial):
response = {'serial': serial,
'provisions': ps,
'issue_time': commission.issue_time,
'name': commission.name,
}
return response
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment