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