Commit 8e849273 authored by Luis Araujo's avatar Luis Araujo

Add options to resubmit and cancel jobs

- Added option to resubmit list of job ids (-r/--resubmit-job)
- Added option to cancel list of job ids (-C/--cancel-job)
- Version bump to 20150117.0
parent b5372b45
......@@ -92,9 +92,12 @@ class Cli(object):
help="receive the 'field:value[@field:value...]' "
"template variables/values")
parser.add_argument('--log-file', type=str, help="set the log file")
parser.add_argument('-r', '--resubmit-job', nargs='+', type=str,
help='resubmit job id list')
parser.add_argument('-C', '--cancel-job', nargs='+', type=str,
help='cancel job id list')
parser.add_argument('-f', '--fetch-result', nargs='+', type=str,
help='fetch job id results', dest="job_id")
help='fetch job id list results', dest="job_id")
self.args = parser.parse_args()
self.command = Lava(self.args)
......@@ -111,6 +114,14 @@ class Lava(object):
self.settings = Settings(self, LAVA_CONFIG)
self.server = self.open_connection()
def open_connection(self):
# Open connection with the server.
return ServerProxy("https://%s:%s@%s/RPC2" %
(self.settings.config['user'],
self.settings.config['auth-token'],
self.settings.config['server']),
use_datetime=True)
def run(self):
"""Run lava command.
......@@ -133,6 +144,15 @@ class Lava(object):
def _run(self, profile={}):
variables = profile.get('variables', {})
# Resubmit job
if self.args.resubmit_job:
self.resubmit_job()
# Cancel job
if self.args.cancel_job:
self.cancel_job()
# Fetch results
if self.args.job_id:
self.fetch_result()
......@@ -188,13 +208,40 @@ class Lava(object):
self.settings.logger.error(e)
continue
def open_connection(self):
# Open connection with the server.
return ServerProxy("https://%s:%s@%s/RPC2" %
(self.settings.config['user'],
self.settings.config['auth-token'],
self.settings.config['server']),
use_datetime=True)
def resubmit_job(self):
"""Resubmit job id"""
rjob_id = None
for job_id in self.args.resubmit_job:
try:
rjob_id = self.server.scheduler.resubmit_job(job_id)
except Fault as e:
self.settings.logger.error(
"resubmit_job {}: '{}'".format(job_id, e))
except EnvironmentError as e:
self.settings.logger.error(e)
exit(1)
if rjob_id:
self.settings.logger.info(
"Resubmitted job id '{}' with new id '{}'"
.format(job_id, rjob_id))
def cancel_job(self):
"""Cancel job id"""
res = None
for job_id in self.args.cancel_job:
try:
res = self.server.scheduler.cancel_job(job_id)
except Fault as e:
self.settings.logger.error("cancel_job {}: '{}'".format(job_id, e))
except EnvironmentError as e:
self.settings.logger.error(e)
exit(1)
if res:
self.settings.logger.info("Job '{}' canceled".format(job_id))
def fetch_result(self):
"""Fetch the result for job id list"""
......
# Version variable
__version__='20150114.0'
__version__='20150117.0'
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