Commit b2c2c615 authored by jurges's avatar jurges

Add API for aborted items, rescheduling depending on status

parent 9bd20b44
# This is the Stager API wrapper module for the Lofar LTA staging service.
#
# It uses an xmlrpc proxy to talk and authenticate to the remote service. Your account credentials will be read from
# the awlofar catalog Environment.cfg, if present or can be provided in a .stagingrc file in your home directory.
# the awlofar catalog Environment.cfg, if present or can be provided in a .stagingrc file in your home directory.
#
# !! Please do not talk directly to the xmlrpc interface, but use this module to access the provided functionality.
# !! This is to ensure that when we change the remote interface, your scripts don't break and you will only have to
# !! Please do not talk directly to the xmlrpc interface, but use this module to access the provided functionality.
# !! This is to ensure that when we change the remote interface, your scripts don't break and you will only have to
# !! upgrade this module.
__version__ = "1.1"
__version__ = "1.2"
import xmlrpclib
import datetime
......@@ -36,14 +36,16 @@ except IOError:
passw = line.split('=', 1)[1].strip()
print datetime.datetime.now(), "stager_access: Creating proxy"
proxy = xmlrpclib.ServerProxy("https://"+user+':'+passw+"@webportal.astron.nl/service-public/xmlrpc")
proxy = xmlrpclib.ServerProxy("https://"+user+':'+passw+"@webportal.astron.nl/service-public/xmlrpc")
LtaStager = proxy.LtaStager
# ---
def stage(surls):
""" Stage list of SURLs """
if isinstance(surls, str):
surls = [surls]
stageid = proxy.LtaStager.add_getid(surls)
stageid = proxy.LtaStager .add_getid(surls)
return stageid
def get_status(stageid):
......@@ -66,9 +68,35 @@ def reschedule(stageid):
""" Reschedule a request with a given ID, e.g. after it was put on hold due to maintenance """
return proxy.LtaStager.reschedule(stageid)
def get_progress():
""" Get a detailed list of all running requests and their current progress. As a normal user, this only returns your own requests. """
return proxy.LtaStager.getprogress()
def get_progress(status=None, exclude=False):
""" Get a detailed list of all running requests and their current progress.
As a normal user, this only returns your own requests.
:param status: If set to a valid status then only requests with that
status are returned.
:param exclude: If set to True then the requests with status 'status' are
excluded.
"""
all_requests = proxy.LtaStager.getprogress()
if status is not None and isinstance(status, basestring):
if exclude is False:
requests = {key: value for key, value in all_requests.iteritems() if value["Status"] == status}
else:
requests = {key: value for key, value in all_requests.iteritems() if value["Status"] != status}
else:
requests = all_requests
return requests
def reschedule_on_status(status=None):
""" Reschedule requests that have a status "on hold" or "aborted".
:param status: The status that a request has to have in order to be
rescheduled.
"""
if status is not None and isinstance(status, basestring) and (status == "on hold" or status == "aborted"):
requests = get_progress(status)
for key in requests.keys():
reschedule(int(key))
else:
print("The parameter status is either None, not a string neither of \"on hold\" nor \"aborted\".")
def get_storage_info():
""" Get storage information of the different LTA sites, e.g. to check available disk pool space. Requires support role permissions. """
......@@ -87,39 +115,31 @@ def prettyprint(dictionary, indent=""):
else:
print "stager_access: This prettyprint takes a dict only!"
def get_progress_on_hold():
""" Get a detailed list of all running requests that have a status 'on hold' and
their current progress. As a normal user, this only returns your own requests.
"""
requests = get_progress()
requests_on_hold = {key: value for key, value in requests.iteritems() if value["Status"] == "on hold"}
return requests_on_hold
def reschedule_on_hold():
""" Get a detailed list of all running requests that have a status other than 'success' and
their current progress. As a normal user, this only returns your own requests.
""" Reschedule requests that are on hold.
"""
requests_on_hold = get_progress_on_hold()
for key in requests_on_hold.keys():
reschedule(int(key))
reschedule_on_status("on hold")
def print_on_hold():
"""Print a list of all requests that are on hold.
"""
requests_on_hold = get_progress_on_hold()
prettyprint(requests_on_hold)
requests = get_progress("on hold")
prettyprint(requests)
def reschedule_aborted():
""" Reschedule requests that were aborted.
"""
reschedule_on_status("aborted")
def get_running():
"""Return a list of requests that are currently executed and do not have a
status of "success".
def print_aborted():
"""Print a list of all requests that were aborted.
"""
requests = get_progress()
requests_running = {key: value for key, value in requests.iteritems() if value["Status"] != "success"}
return requests_running
requests = get_progress("aborted")
prettyprint(requests)
def print_running():
"""Print a list of requests that are currently executed and do not have a
status of "success"
"""
requests_running = get_running()
prettyprint(requests_running)
requests = get_progress("success", True)
prettyprint(requests)
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