def entry(cls, name): banner("Register {}".format(name)) name = str(name) etc_config = ConfigDict("cloudmesh.yaml", etc=True) config = ConfigDict("cloudmesh.yaml") clouds = config["cloudmesh.clouds"] clusters = config["cloudmesh.hpc.clusters"] if name in clouds: name = "cloudmesh.clouds.{}.credentials".format(name) elif name in clusters: name = "cloudmesh.hpc.clusters.{}.credentials".format(name) elif not name.startswith("cloudmesh."): name = "cloudmesh." + name try: etc = etc_config[name] yaml = config[name] # walk yaml for key in etc: if etc[key] == "TBD": result = input("Enter {:} ({:}): ".format(key, yaml[key])) if result != '': yaml[key] = result config.save() except Exception as e: Console.error("Could not find {} in the yaml file".format(name), traceflag=False)
def test_003(self): HEADING("reading the keys from github") self.cm.clean() config = ConfigDict("cloudmesh.yaml") git_username = config['cloudmesh']['github']['username'] banner("git hub") Key.get_from_git(git_username) mykeys = Key.all(output="dict") count1 = len(mykeys) banner("all") key = Key.get(git_username, output="dict") print(key) mykeys = Key.all(output="dict") count2 = len(mykeys) print(mykeys) Key.delete(name='github-0') mykeys = Key.all(output="table") print(mykeys) assert count1 > 0 and count2 > 0
def test_002(self): HEADING("reading the keys from ~/.ssh") banner("ssh keys") Key.get_from_dir("~/.ssh") mykeys = Key.all(output="dict") assert len(mykeys) > 0
def test_003(self): HEADING("testing cm list") banner("cm list --cloud={wrong_cloud} --user={user} vm") result = self.run("cm list --cloud={wrong_cloud} --user={user} vm") assert "No" in result return
def test_009(self): HEADING("testing cm group remove ") banner("cm group remove {prefix}-002 --group={group}") result = self.run("cm group remove {prefix}-002 --group={group} ") print(result) assert "ok" in result result = self.run("cm group list {group}") assert "test-002" not in result
def run(self, command): command = command.format(**self.data) banner(command, c="-") print(command) parameter = command.split(" ") shell_command = parameter[0] args = parameter[1:] result = Shell.execute(shell_command, args) print(result) return result
def run(self, command): command = command.format(**self.data) banner(command, c="-") print(command) parameter = command.split(" ") shell_command = parameter[0] args = parameter[1:] result = Shell.execute(shell_command, args) print(result) return str(result)
def run(self): banner("Install readline") commands = None this_platform = platform.system().lower() if this_platform in ['darwin']: commands = """ easy_install readline """ elif this_platform in ['windows']: commands = """ pip install pyreadline """ if commands: os_execute(commands) banner("Install Cloudmesh_portal {:}".format(__version__)) install.run(self)
def info(self): banner("Configuration") Console.ok('Object Attibutes: {:}'.format(', '.join(self.order))) Console.ok('Objects: {:}'.format(len(self.data))) Console.ok('Configuration File: {:}'.format(self.config_filename)) Console.ok('Configuration:') print(self.config) try: config = ConfigDict(filename=self.config_filename) except Exception as e: Console.error("Problem reading the yaml file {:}".format( self.config_filename), traceflag=False) Console.error("Please check if the file exists or is empty", traceflag=False) Console.error(e.message) banner("")
def test_002(self): HEADING("VM DB test") self.cm.clean() print("ADD TO OS ") d = { 'user': "******", 'category': self.data.cloud } for index in range(1, 6): name = "vm_" + str(index).zfill(3) banner(name) print("ADD", name) try: d['name'] = name d['uuid'] = "uuid_" + str(index) vm = VM_OPENSTACK(**d) pprint(vm.__dict__) except Exception as e: Console.error("issue adding vm", traceflag=True) self.cm.add(vm) print("VM added. ok") print("ADD TO LIBCLOUD ") for index in range(6, 11): name = "vm_" + str(index).zfill(3) banner(name) print("ADD", name) d['name'] = name d['uuid'] = "uuid_" + str(index) vm = VM_LIBCLOUD(**d) print("VM", vm.__dict__) self.cm.add(vm) self.cm.save() result = self.run("cm refresh off") print(result) vms = self.cm.find(kind="vm", scope="all", output='dict') pprint(vms) print (len(vms)) assert len(vms) == 10
def test_008(self): HEADING("testing cm group add with default cloud") banner("cm group add --name=groupX --id=albert-00x", c='-') result = self.run("cm default cloud") print("UUUU", result) pprint(self.data.cloud) print(type(result), type(self.data.cloud)) assert self.data.cloud in result result = self.run("cm default type=vm") assert "ok." in result result = self.run("cm group add albert-00x --group=groupX ") # print ("RRR", result) # assert "albert-00x" in result result = self.run("cm group list groupX") print("DDDDD", result) assert "groupX" in result
def cloudmesh_images(request, cloud=None): banner("images") if cloud is None: cloud = Default.cloud # TODO: make the cloudname a parameter data = Image.list(cloud, format='dict') print (json.dumps(data, indent=4)) # TODO set proper columns order = [ 'cm_id', 'name', 'category', 'minDisk', 'minRam', 'os_image_size', 'progress', 'project', 'status', ] return (dict_table(request, title="Cloudmesh Images {}".format(cloud), data=data, order=order))
# limitations under the License. # # ------------------------------------------------------------------------# from __future__ import print_function from setuptools import setup, find_packages # noinspection PyPep8Naming from setuptools.command.test import test as TestCommand from setuptools.command.install import install import sys import platform import os from cloudmesh_client.common.util import banner from cloudmesh_client.setup import os_execute from cloudmesh_portal.version import __version__ banner("Installing Cloudmesh_portal {:}".format(__version__)) requirements = [ "cloudmesh_client", "cloudmesh_workflow", "jinja2schema", "django-rest-swagger", "django-bootstrap3", "django-admin-bootstrapped", "django-bootstrap-themes", "django-jinja", "djangorestframework", "markdown", "django-filter", "aldjemy", "nwdiag",
def test_power_nodes(action='on'): banner("TEST: power on/off a list of nodes") banner("Authenticating...") # always logon first comet = Comet() Comet.tunnelled = True token = comet.logon() authheader = {'content-type': 'application/json', "Authorization": 'Token %s' % token} url = "https://localhost:8443/nucleus/v1/" vcname = "vc2" vmnames = ["vm-vc2-0", "vm-vc2-1"] vmhosts = { vmnames[0]: "comet-01-05", vmnames[1]: "comet-01-06" } data = {"computes": [{"name": vm, "host": vmhosts[vm]} for vm in vmnames], "cluster": "%s" % vcname} if 'on' == action: banner("Issuing request to poweron nodes...") posturl = "{}/computeset/".format(url) # posturl = "%s%s/compute/poweron" % (url, vcname) r = Comet.http(posturl, action="post", headers=authheader, data=data) banner("RETURNED RESULTS:") print(r) elif 'off' == action: computesetid = 33 banner("Issuing request to poweroff nodes...") puturl = "%s/computeset/%s/poweroff" % (url, computesetid) # posturl = "%s%s/compute/poweron" % (url, vcname) r = Comet.http(puturl, action="put", headers=authheader) banner("RETURNED RESULTS:") print(r) else: print("The Specified Power Action NOT Supported!")
def test_001(self): HEADING("check the model") self.cm.clean() d = self.d banner("VM Data", c='-') pprint(d.__dict__) assert d['extra__imageId'] == 'abcd' banner("Add VM", c='-') name = "vm1" uuid = d.id vm = VM_OPENSTACK(name=name, user="******", category=self.data.cloud, **d) print(vm) banner("VM added", c='-') self.cm.add(vm) banner("Add VM", c='-') name = "vm2" uuid = d.id vm = VM_OPENSTACK(name=name, user="******", category=self.data.cloud, **d) print(vm) banner("VM added", c='-') # pprint(vm.__dict__) # vm.bla = "bla" self.cm.add(vm) # self.cm.save() banner("Get VM from Database", c='-') vms = self.cm.find(kind="vm", name=name, output='dict') pprint(vms) assert len(vms) == 1 assert vms[0]["name"] == name
Console.error( "cloudmesh.profile.user not set for delta access. Please edit the cloudmesh.yaml file." ) pprint(data) workers = ['d006'] manager = ['d005'] if arguments['start']: manager, workers = get_layout(data.ID, data.user) print(manager, workers) for w in workers + manager: banner("HOST: " + w) data['worker'] = w start_docker(w) elif arguments['info']: for w in workers + manager: banner("HOST: " + w) data['worker'] = w info_docker(w) elif arguments['init']: for w in manager:
def test_get_cluster_list(): token = '' banner("TEST 1: Get without logon") authheader = {'content-type': 'application/json', "Authorization": 'Token %s' % token} geturl = "https://localhost:8443/nucleus/v1/cluster/" r = requests.get(geturl, headers=authheader, verify=False) # pprint (r) pprint(r.json()) banner("TEST 2: Auth and then get cluster list") # authurl = "https://localhost:8443/nucleus/rest-auth" # auth = Authenticator(authurl) # change user, password to proper value as set in django # in shell, we may ask user input comet = Comet() Comet.tunnelled = True token = comet.logon() # construct a header with auth token after login # for all the following calls before log out authheader = {'content-type': 'application/json', "Authorization": 'Token %s' % token} geturl = "https://localhost:8443/nucleus/v1/" geturl1 = "{}cluster/".format(geturl) r = Comet.get(geturl1, headers=authheader) pprint(r) # as of 2:40pm ET Oct 15, this is changed to 'not implemented' # as of 5:30pm ET this is now fixed and working # Getting only cluster details for those owned by the caller. banner("TEST 3a: Get cluster 'OSG'") geturl1 = "%scluster/%s" % (geturl, "osg/") r1 = Comet.get(geturl1, headers=authheader) pprint(r1) banner("\nTEST 3b: Get cluster 'vc2' via tunnel") geturl1 = "%scluster/%s" % (geturl, "vc2/") r1 = Comet.get(geturl1, headers=authheader) pprint(r1) banner("\nTEST 3c: Get cluster 'vc2' directly") Comet.tunnelled = False geturl1 = Comet.url("cluster/vc2/") r1 = Comet.get(geturl1, headers=authheader) pprint(r1) banner("TEST 4: Get compute nodes sets") Comet.tunnelled = True r1 = Comet.get_computeset() pprint(r1) banner("TEST 4a: Get compute nodes set with id") r1 = Comet.get_computeset(46) pprint(r1) banner("TEST 10: logoff and get cluster list again") comet.logoff() authheader = {'content-type': 'application/json', "Authorization": 'Token %s' % token} geturl = "https://localhost:8443/nucleus/v1/cluster/" r = requests.get(geturl, headers=authheader, verify=False) pprint(r.json())
def makefile(tag, **kwargs): script = "\n".join(yaml.load(make)[tag]) commands = "\n".join(yaml.load(make)[tag]).format(**kwargs) banner("RUNNING") os_execute(commands)
msg = "Unknown host" try: msg = Shell.ping("-c", "1", host) except: pass if "1 packets transmitted, 1 packets received" in msg: return True elif "Unknown host" in msg: return False else: return False if __name__ == "__main__": i = Inventory() banner("Info") i.info() banner("changing values") i.add(host="i1", cluster="kilo", label="india") i.add(host="i2", cluster="kilo", label="gregor") i.add(host="d[1-4]", cluster="kilo", label="delta") banner("saving") i.save() for output in ['dict', 'yaml', 'csv', 'table']: banner(output) print(i.list(format=output)) banner("reading")
def do_ssh(self, args, arguments): """ :: Usage: ssh table ssh list [--format=FORMAT] ssh cat ssh register NAME PARAMETERS ssh ARGUMENTS conducts a ssh login on a machine while using a set of registered machines specified in ~/.ssh/config Arguments: NAME Name or ip of the machine to log in list Lists the machines that are registered and the commands to login to them PARAMETERS Register te resource and add the given parameters to the ssh config file. if the resoource exists, it will be overwritten. The information will be written in /.ssh/config Options: -v verbose mode --format=FORMAT the format in which this list is given formats incluse table, json, yaml, dict [default: table] --user=USER overwrites the username that is specified in ~/.ssh/config --key=KEY The keyname as defined in the key list or a location that contains a pblic key Description: ssh list lists the hostsnames that are present in the ~/.ssh/config file ssh cat prints the ~/.ssh/config file ssh table prints contents of the ~/.ssh/config file in table format ssh register NAME PARAMETERS registers a host i ~/.ssh/config file Parameters are attribute=value pairs Note: Note yet implemented ssh ARGUMENTS executes the ssh command with the given arguments Example: ssh myhost conducts an ssh login to myhost if it is defined in ~/.ssh/config file """ # pprint(arguments) def read(filename=None): if filename is None: filename = "~/.ssh/config" with open(path_expand("~/.ssh/config"), "r") as f: content = f.readlines() return "".join(content) if arguments["list"]: output_format = arguments["--format"] banner('List SSH config hosts') hosts = ssh_config() for host in hosts.list(): print(host) elif arguments["table"]: content = read(filename="~/.ssh/config").split("\n") entries = [ ] def empty(): return { "host": None, "hostname": None, "user": None, "proxycommand": None, "serveraliveinterval": None, "localforward": None, "forwardx11": None } entry = empty() for line in content: line = line.strip() if line.startswith("#"): pass elif line.strip() == "": pass elif "Host " in line: hostname = line.strip().split("Host")[1] entry["host"] = hostname.strip() if entry is not None: entries.append(entry) entry = empty() else: attribute, value = line.strip().split(" ", 1) entry[attribute.lower()] = value.strip() pprint(entries) order = ["host", "hostname", "user", "proxycommand", "serveraliveinterval", "localforward", "forwardx11"] print(Printer.list(entries, order=order)) elif arguments["cat"]: print(read(filename="~/.ssh/config")) elif arguments["register"]: name = arguments["NAME"] parameters = arguments["PARAMETERS"] Console.ok('register {} {}'.format(name, parameters)) TODO.implement("Not implemented") else: # ssh ARGUMENTS... args = arguments["ARGUMENTS"] os.system("ssh {}".format(args)) return "" return ""
def do_ssh(self, args, arguments): """ :: Usage: ssh table ssh list [--format=FORMAT] ssh cat ssh register NAME PARAMETERS ssh ARGUMENTS conducts a ssh login on a machine while using a set of registered machines specified in ~/.ssh/config Arguments: NAME Name or ip of the machine to log in list Lists the machines that are registered and the commands to login to them PARAMETERS Register te resource and add the given parameters to the ssh config file. if the resoource exists, it will be overwritten. The information will be written in /.ssh/config Options: -v verbose mode --format=FORMAT the format in which this list is given formats incluse table, json, yaml, dict [default: table] --user=USER overwrites the username that is specified in ~/.ssh/config --key=KEY The keyname as defined in the key list or a location that contains a pblic key Description: ssh list lists the hostsnames that are present in the ~/.ssh/config file ssh cat prints the ~/.ssh/config file ssh table prints contents of the ~/.ssh/config file in table format ssh register NAME PARAMETERS registers a host i ~/.ssh/config file Parameters are attribute=value pairs Note: Note yet implemented ssh ARGUMENTS executes the ssh command with the given arguments Example: ssh myhost conducts an ssh login to myhost if it is defined in ~/.ssh/config file """ # pprint(arguments) def read(filename=None): if filename is None: filename = "~/.ssh/config" with open(path_expand("~/.ssh/config"), "r") as f: content = f.readlines() return "".join(content) def print_ssh_table(output): content = read(filename="~/.ssh/config").split("\n") entries = [ ] def empty(): return { "host": None, "hostname": None, "user": None, "proxycommand": None, "serveraliveinterval": None, "localforward": None, "forwardx11": None } entry = empty() for line in content: line = line.strip() if line.startswith("#"): pass elif line.strip() == "": pass elif "Host " in line: hostname = line.strip().split("Host")[1] entry["host"] = hostname.strip() if entry is not None: entries.append(entry) entry = empty() else: attribute, value = line.strip().split(" ", 1) entry[attribute.lower()] = value.strip() # pprint(entries) order = ["host", "hostname", "user", "proxycommand", "serveraliveinterval", "localforward", "forwardx11"] print(Printer.list(entries, order=order)) if arguments["list"]: output_format = arguments["--format"] if output_format is None: banner('List SSH config hosts') hosts = ssh_config() for host in hosts.list(): print(host) else: print_ssh_table(output_format) return "" elif arguments["table"]: print_ssh_table() return "" elif arguments["cat"]: print(read(filename="~/.ssh/config")) elif arguments["register"]: name = arguments["NAME"] parameters = arguments["PARAMETERS"] Console.ok('register {} {}'.format(name, parameters)) TODO.implement("Not implemented") else: # ssh ARGUMENTS... args = arguments["ARGUMENTS"] os.system("ssh {}".format(args)) return "" return ""
def run(command): command = command.format(**data) banner(command, c="-") parameter = command.split(" ") os.system(command)
from __future__ import print_function from pprint import pprint import requests from cloudmesh_client.common.util import banner r = requests.get('https://api.github.com/repos/cloudmesh/client/issues') issues = r.json() pprint(issues) for issue in issues: banner(issue["title"]) if issue["milestone"] is not None: print(issue["milestone"]["title"]) if issue["assignee"] is not None: print(issue["assignee"]["login"]) for attribute in ["number", "state", "title", "body"]: if issue[attribute]: print(attribute, ":", issue[attribute])
} return stats def print_authors(): gitinfo = GitInfo() print(gitinfo.authors()) if __name__ == "__main__": gitinfo = GitInfo() # print gitinfo.version() banner("a") print(gitinfo.authors()) banner("b") pprint(gitinfo.authors("dict")) banner("c") pprint(gitinfo.emails()) banner("d") pprint(gitinfo.emails("dict")) banner("e") pprint(gitinfo.info()) banner("f")