def do_qstat(self, args, arguments): """ :: Usage: qstat HOST [-a] [(--view VIEW | ATTRIBUTES...)] [--output=(dict|table)] tests via ping if the host ith the give NAME is reacahble Arguments: VIEW the name of the view [default: default]. HOST Name of the machine to test Options: -v verbose mode """ if arguments["HOST"]: host = arguments["HOST"] Console.info("trying to reach {0}".format(host)) if len(arguments['ATTRIBUTES']) == 0 and not arguments['--view']: arguments['--view'] = True arguments['VIEW'] = 'default' # pprint(arguments) r = {} try: pbs = OpenPBS(deploy=True) if arguments["-a"]: r = pbs.qstat(host, user=False) else: r = pbs.qstat(host) Console.info("machine " + host + " has been found. ok.") if len(arguments['ATTRIBUTES'] ) != 0 and not arguments['--view']: r = OpenPBS.list(r, arguments['ATTRIBUTES']) elif arguments['--view']: view = arguments['VIEW'] attributes = pbs.data.get( "cloudmesh.pbsview.{0}".format(view)) r = OpenPBS.list(r, attributes) except Exception, e: Console.error("machine " + host + " not reachable. error.") print(e) if len(r.keys()) == 0: Console.info("No jobs found") else: if arguments['--output'] == 'dict' or None: pprint(r) else: print(dict_printer(r))
def do_qstat(self, args, arguments): """ :: Usage: qstat HOST [-a] [(--view VIEW | ATTRIBUTES...)] [--output=(dict|table)] tests via ping if the host ith the give NAME is reacahble Arguments: VIEW the name of the view [default: default]. HOST Name of the machine to test Options: -v verbose mode """ if arguments["HOST"]: host = arguments["HOST"] Console.info("trying to reach {0}".format(host)) if len(arguments['ATTRIBUTES']) == 0 and not arguments['--view']: arguments['--view'] = True arguments['VIEW'] = 'default' # pprint(arguments) r = {} try: pbs = OpenPBS(deploy=True) if arguments["-a"]: r = pbs.qstat(host, user=False) else: r = pbs.qstat(host) Console.info("machine " + host + " has been found. ok.") if len(arguments['ATTRIBUTES']) != 0 and not arguments['--view']: r = OpenPBS.list(r, arguments['ATTRIBUTES']) elif arguments['--view']: view = arguments['VIEW'] attributes = pbs.data.get("cloudmesh.pbsview.{0}".format(view)) r = OpenPBS.list(r, attributes) except Exception, e: Console.error("machine " + host + " not reachable. error.") print(e) if len(r.keys()) == 0: Console.info("No jobs found") else: if arguments['--output'] == 'dict' or None: pprint(r) else: print(dict_printer(r))
def get(self, host): """gets all jobs""" pbs = OpenPBS(deploy=True) manager = pbs.manager(host) r = pbs.qstat(host, user=False, format="dict") return r
class DbPBS(pbs_db_interface): def __init__(self, filename=None): self.pbs = OpenPBS(deploy=True) self.open() def open(self, filename=None): if filename is not None: self.filename = filename else: self.filename = path_expand(self.pbs.database_filename()) path = os.path.dirname(self.filename) Shell.mkdir(path) self.load() def clear(self): for id in self.db: del self.db[id] self.save() def load(self): """load the cloudmesh_job""" print('loading', self.filename) # remove db ending so that shelve automatically adds it self.filename = self.filename.replace(".db", "") self.db = shelve.open(self.filename, writeback=True) def save(self): self.db.sync() def get(self, id): return self.db[id] def status(self, id): return self.get(id)["job_state"] def set(self, id, value): self.db[id] = value self.save() def keys(self): self.data().keys() def delete(self, id): del self.db[id] def close(self): self.db.close() def update(self, host=None, user=True): if host is None: print("host is none is not supported yet") raise print("QSTAT") r = dict(self.pbs.qstat(host, user=user, format='dict')) pprint(r) if r is not {}: for jobid in r: self.db[jobid] = r[jobid] self.save() else: print("no jobs found after query") print("update completed") def info(self): print("Filename:", self.filename) def list(self, attributes=None, output="table"): if self.db is None or len(self.db) == 0: print("No jobs found") return None columns = attributes if columns is None: columns = ["cm_jobid", "cm_host", "cm_user", "Job_Name", "job_state", "exit_status"] # prepare the dict d = {} for jobid in self.db: content = {} for attribute in columns: try: content[attribute] = self.db[jobid][attribute] except: content[attribute] = "None" d[jobid] = content # print the dict if output in ["csv", "table", "dict", "yaml"]: return dict_printer(d, order=columns, output=output) return None def qsub(self, name, host, script, template=None, kind="dict"): r = self.pbs.qsub(name, host, script, template=template, kind=kind) pprint(r) return dict(r)