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
def setup(self): # HEADING() self.pbs = OpenPBS(deploy=True) self.manager = self.pbs.manager(self.host)
class TestPBSubmit: filename = "pbs.db" host = "india" script = """ uname -a """ def setup(self): # HEADING() self.pbs = OpenPBS(deploy=True) self.manager = self.pbs.manager(self.host) def teardown(self): # HEADING() pass # def test_clear(self): # HEADING() # assert not os.path.isfile(self.filename) def test_generate_script(self): HEADING() banner("Create Dir") xmkdir(self.manager, "~/scripts/test") assert self.pbs.data.get("cloudmesh.pbs.{0}.manager".format(self.host)) script_template = self.pbs.read_script("etc/job.pbs") jobname = "job-" + self.pbs.jobid job_script = self.pbs.create_script(jobname, self.script, script_template) print(job_script) assert "uname" in job_script def test_job_submit(self): HEADING() xmkdir(self.manager, "~/scripts/test") self.pbs.jobid_incr() banner('qsub') jobname = "job-" + self.pbs.jobid + ".pbs" print(jobname) print (self.host) script_template = self.pbs.read_script("etc/job.pbs") r = self.pbs.qsub(jobname, self.host, 'echo "Hello"', template=script_template) pprint(r) #banner('variable list') #pprint(self.pbs.variable_list(r)) assert len(r.keys()) == 1 banner('status') jobid = self.pbs.getid(r) print (jobid) r = self.pbs.jobstatus(self.host, jobid) print(r) #pprint (pbs.data) # banner("table") # print(pbs.db.list(attributes, output="table")) #banner("yaml") #print(pbs.db.list(attributes, output="yaml")) #banner("dict") #print(pbs.db.list(attributes, output="dict")) #r = self.pbs.qstat("india") #banner("RESULT") #pprint(r) """
def __init__(self, filename=None): self.pbs = OpenPBS(deploy=True) self.open()
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)
qsub = False db = DbPBS() db.clear() db.info() db.update(host="india", user=False) print(db.list(output="table")) print(db.list(output="csv")) print(db.list(output="dict")) print(db.list(output="yaml")) banner("user") db.clear() db.update(host="india") print(db.list(output="table")) if qsub: banner('qsub') pbs = OpenPBS() jobname = "job-" + pbs.jobid + ".pbs" host = "india" script_template = pbs.read_script("etc/job.pbs") print(script_template) r = db.qsub(jobname, host, 'echo "Hello"', template=script_template) pprint(r) banner('variable list') pprint(OpenPBS.variable_list(r))
class TestPBSubmit: filename = "pbs.db" host = "india" script = """ uname -a """ def setup(self): # HEADING() self.pbs = OpenPBS(deploy=True) self.manager = self.pbs.manager(self.host) def teardown(self): # HEADING() pass # def test_clear(self): # HEADING() # assert not os.path.isfile(self.filename) def test_generate_script(self): HEADING() banner("Create Dir") xmkdir(self.manager, "~/scripts/test") assert self.pbs.data.get("cloudmesh.pbs.{0}.manager".format(self.host)) script_template = self.pbs.read_script("etc/job.pbs") jobname = "job-" + self.pbs.jobid job_script = self.pbs.create_script(jobname, self.script, script_template) print(job_script) assert "uname" in job_script def test_job_submit(self): HEADING() xmkdir(self.manager, "~/scripts/test") self.pbs.jobid_incr() banner('qsub') jobname = "job-" + self.pbs.jobid + ".pbs" print(jobname) print(self.host) script_template = self.pbs.read_script("etc/job.pbs") r = self.pbs.qsub(jobname, self.host, 'echo "Hello"', template=script_template) pprint(r) #banner('variable list') #pprint(self.pbs.variable_list(r)) assert len(r.keys()) == 1 banner('status') jobid = self.pbs.getid(r) print(jobid) r = self.pbs.jobstatus(self.host, jobid) print(r) #pprint (pbs.data) # banner("table") # print(pbs.db.list(attributes, output="table")) #banner("yaml") #print(pbs.db.list(attributes, output="yaml")) #banner("dict") #print(pbs.db.list(attributes, output="dict")) #r = self.pbs.qstat("india") #banner("RESULT") #pprint(r) """