def do_version(self, args, arguments): """ Usage: version [--format=FORMAT] [--check=CHECK] Options: --format=FORMAT the format to print the versions in [default: table] --check=CHECK boolean tp conduct an additional check [default: True] Description: Prints out the version number """ python_version, pip_version = get_python() versions = { "cloudmesh_base": { "name": "cloudmesh_base", "version": str(cloudmesh_base.version) }, "python": { "name": "python", "version": str(python_version) }, "pip": { "name": "pip", "version": str(pip_version) } } print (dict_printer(versions, output=arguments["--format"] ,order=["name", "version"])) if arguments["--check"] in ["True"]: check_python()
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 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 test_table3(self): HEADING() print(dict_printer(self.data)) assert True