aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lava_scheduler_tool/commands.py42
-rw-r--r--lava_tool/authtoken.py14
2 files changed, 38 insertions, 18 deletions
diff --git a/lava_scheduler_tool/commands.py b/lava_scheduler_tool/commands.py
index 0042f01..d5a820f 100644
--- a/lava_scheduler_tool/commands.py
+++ b/lava_scheduler_tool/commands.py
@@ -33,6 +33,7 @@ import zmq
from lava_tool.authtoken import (
split_xmlrpc_url,
+ get_server_url,
AuthenticatingServerProxy,
KeyringAuthBackend
)
@@ -90,8 +91,9 @@ class submit_job(Command):
help="Blocks until the job gets executed. Deprecated. This option adds unnecessary load on the server. Please use wait-job-events command instead.")
def invoke(self):
+ auth_backend = KeyringAuthBackend()
server = AuthenticatingServerProxy(
- self.args.SERVER, auth_backend=KeyringAuthBackend())
+ self.args.SERVER, auth_backend=auth_backend)
if not os.path.exists(self.args.JSON_FILE):
raise CommandError("No such file: %s" % self.args.JSON_FILE)
with open(self.args.JSON_FILE, 'rb') as stream:
@@ -102,12 +104,17 @@ class submit_job(Command):
except xmlrpclib.Fault, e:
raise CommandError(str(e))
else:
+ # Need to get the host in case of shortcuts usage.
+ host = get_server_url(auth_backend, self.args.SERVER)
if isinstance(job_ids, list):
- print "submitted as job ids:"
+ print "submitted as jobs:"
for job_id in job_ids:
- print " -", job_id
+ job = server.scheduler.job_details(job_id)
+ print urlparse.urljoin(host, job["absolute_url"])
else:
- print "submitted as job id:", job_ids
+ job = server.scheduler.job_details(job_ids)
+ print "submitted as job:", urlparse.urljoin(
+ host, job["absolute_url"])
job_ids = [job_ids]
if self.args.block:
@@ -140,14 +147,20 @@ class resubmit_job(Command):
parser.add_argument("JOB_ID")
def invoke(self):
+ auth_backend = KeyringAuthBackend()
server = AuthenticatingServerProxy(
- self.args.SERVER, auth_backend=KeyringAuthBackend())
+ self.args.SERVER, auth_backend=auth_backend)
try:
job_id = server.scheduler.resubmit_job(self.args.JOB_ID)
+ # Need to get the host in case of shortcuts usage.
+ host = get_server_url(auth_backend, self.args.SERVER)
+
except xmlrpclib.Fault, e:
raise CommandError(str(e))
else:
- print "resubmitted as job id:", job_id
+ job = server.scheduler.job_details(job_id)
+ print "resubmitted as job:", urlparse.urljoin(
+ host, job["absolute_url"])
class cancel_job(Command):
@@ -636,6 +649,11 @@ class wait_job_events(Command):
server = AuthenticatingServerProxy(
self.args.SERVER, auth_backend=auth_backend)
+ # Need to get the host in case of shortcuts usage.
+ parsed_host = urlparse.urlparse(
+ get_server_url(auth_backend, self.args.SERVER))
+ host = parsed_host.netloc
+
if self.args.job_id:
job_ids = [self.args.job_id]
try:
@@ -669,18 +687,6 @@ class wait_job_events(Command):
except xmlrpclib.Fault, e:
raise CommandError(str(e))
- # Need to get the host in case of shortcuts usage.
- user, token, host = split_xmlrpc_url(self.args.SERVER)
- try:
- host, _ = auth_backend.resolve_shortcuts(host, user)
- except EndpointNotFoundError as e:
- raise LavaCommandError(e)
- except UsernameNotFoundError as e:
- raise LavaCommandError(e)
-
- parsed_host = urlparse.urlparse(host)
- host = parsed_host.netloc
-
port = self.args.port if self.args.port else self.PUBLISHER_PORT
event_socket = "%s%s:%s" % (self.PUBLISHER_PROTOCOL, host, port)
diff --git a/lava_tool/authtoken.py b/lava_tool/authtoken.py
index c6d0258..a2abd6a 100644
--- a/lava_tool/authtoken.py
+++ b/lava_tool/authtoken.py
@@ -119,6 +119,20 @@ def split_xmlrpc_url(url):
return username, token, userless_uri
+def get_server_url(auth_backend, server):
+ # Get resolved url of the server based on authentication backend.
+
+ user, token, host = split_xmlrpc_url(server)
+ try:
+ host, _ = auth_backend.resolve_shortcuts(host, user)
+ except EndpointNotFoundError as e:
+ raise LavaCommandError(e)
+ except UsernameNotFoundError as e:
+ raise LavaCommandError(e)
+
+ return host
+
+
class AuthBackend(object):
def add_token(self, username, endpoint_url, token, user_shortcut=None,