summaryrefslogtreecommitdiff
path: root/saharaclient/api
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-07-20 22:28:39 +0000
committerGerrit Code Review <review@openstack.org>2015-07-20 22:28:39 +0000
commit9725500872ff72e7811b1c46d9d0b0655e27e3dc (patch)
tree024f1a949aaa11f3973700f8afe83cc4b9b4ac2e /saharaclient/api
parent57930d0f155b9536721bbb5bf6859d0a9bf8ee74 (diff)
parent7435a98a0cc8e9c1c8fb1158f553ef673812f0a8 (diff)
downloadpython-saharaclient-9725500872ff72e7811b1c46d9d0b0655e27e3dc.tar.gz
Merge "Adding interface argument for job template and job"
Diffstat (limited to 'saharaclient/api')
-rw-r--r--saharaclient/api/job_executions.py6
-rw-r--r--saharaclient/api/jobs.py6
-rw-r--r--saharaclient/api/shell.py53
3 files changed, 49 insertions, 16 deletions
diff --git a/saharaclient/api/job_executions.py b/saharaclient/api/job_executions.py
index c5af07e..37b2b06 100644
--- a/saharaclient/api/job_executions.py
+++ b/saharaclient/api/job_executions.py
@@ -33,11 +33,13 @@ class JobExecutionsManager(base.ResourceManager):
def delete(self, obj_id):
self._delete('/job-executions/%s' % obj_id)
- def create(self, job_id, cluster_id, input_id, output_id, configs):
+ def create(self, job_id, cluster_id, input_id,
+ output_id, configs, interface=None):
url = "/jobs/%s/execute" % job_id
data = {
"cluster_id": cluster_id,
- "job_configs": configs
+ "job_configs": configs,
+ "interface": interface or {}
}
# Leave these out if they are null. For Java job types they
diff --git a/saharaclient/api/jobs.py b/saharaclient/api/jobs.py
index 6e10ccd..44bdd3e 100644
--- a/saharaclient/api/jobs.py
+++ b/saharaclient/api/jobs.py
@@ -23,15 +23,15 @@ class Job(base.Resource):
class JobsManager(base.ResourceManager):
resource_class = Job
- def create(self, name, type, mains, libs, description):
+ def create(self, name, type, mains, libs, description, interface=None):
data = {
'name': name,
'type': type,
'description': description,
'mains': mains,
- 'libs': libs
+ 'libs': libs,
+ 'interface': interface or []
}
-
return self._create('/jobs', data, 'job')
def list(self, search_opts=None):
diff --git a/saharaclient/api/shell.py b/saharaclient/api/shell.py
index 1542381..188f76a 100644
--- a/saharaclient/api/shell.py
+++ b/saharaclient/api/shell.py
@@ -795,10 +795,8 @@ def do_job_template_show(cs, args):
@utils.arg('--name',
- required=True,
help='Name of the job template.')
@utils.arg('--type',
- required=True,
help='Type of the job template.')
@utils.arg('--main',
action='append',
@@ -811,11 +809,28 @@ def do_job_template_show(cs, args):
@utils.arg('--description',
default='',
help='Description of the job template.')
+@utils.arg('--json',
+ default=None,
+ type=argparse.FileType('r'),
+ help='JSON representation of job template.')
def do_job_template_create(cs, args):
"""Create a job template."""
- _show_job_template(cs.jobs.create(args.name, args.type,
- args.main, args.lib,
- args.description))
+ template = json.loads(args.json.read()) if args.json else {}
+ _filter_call_args(template, cs.jobs.create)
+ template = {
+ "name": args.name or template.get("name") or None,
+ "type": args.type or template.get("type") or None,
+ "mains": args.main or template.get("mains") or [],
+ "libs": args.lib or template.get("libs") or [],
+ "description": args.description or template.get("description") or '',
+ "interface": template.get("interface") or []
+ }
+ if not template["name"]:
+ raise Exception("name is required")
+ if not template["type"]:
+ raise Exception("type is required")
+
+ _show_job_template(cs.jobs.create(**template))
@utils.arg('--name',
@@ -869,7 +884,7 @@ def do_job_show(cs, args):
required=True,
help='ID of the job template to run.')
@utils.arg('--cluster',
- required=True,
+ required=False,
help='ID of the cluster to run the job in.')
@utils.arg('--input-data',
default=None,
@@ -891,14 +906,30 @@ def do_job_show(cs, args):
action='append',
default=[],
help='Config parameters to add to the job, repeatable.')
+@utils.arg('--json',
+ default=None,
+ type=argparse.FileType('r'),
+ help='JSON representation of the job.')
def do_job_create(cs, args):
"""Create a job."""
+ job = json.loads(args.json.read()) if args.json else {}
+ remap = {"job_configs": "configs"}
+ _filter_call_args(job, cs.job_executions.create, remap)
_convert = lambda ls: dict(map(lambda i: i.split('=', 1), ls))
- _show_job(cs.job_executions.create(args.job_template, args.cluster,
- args.input_data, args.output_data,
- {'params': _convert(args.param),
- 'args': args.arg,
- 'configs': _convert(args.config)}))
+ job = {
+ "cluster_id": args.cluster or job.get("cluster_id") or None,
+ "input_id": args.input_data or job.get("input_id") or None,
+ "output_id": args.output_data or job.get("output_id") or None,
+ "interface": job.get("interface") or [],
+ "configs": job.get("configs") or {}
+ }
+ if any((args.config, args.param, args.arg)):
+ job["configs"] = {"configs": _convert(args.config),
+ "args": args.arg,
+ "params": _convert(args.param)}
+ if not job["cluster_id"]:
+ raise Exception("cluster is required")
+ _show_job(cs.job_executions.create(args.job_template, **job))
@utils.arg('--id',