Example #1
0
def run(command):
    banner(command, c='-')
    parameter = command.split(" ")
    shell_command = parameter[0]
    args = parameter[1:]
    result = Shell.execute(shell_command, args)
    print(result)
    return result
Example #2
0
    def test_006(self):
        """testing cm group list --category=kilo --format json groupA"""
        HEADING()
        banner("cm group list --category=kilo --format=json groupA")

        result = run("cm group list --category=kilo  --format=json groupA")
        assert "groupA" in result
        return
Example #3
0
def run(command):
    banner(command, c='-')
    parameter = command.split(" ")
    shell_command = parameter[0]
    args = parameter[1:]
    result = Shell.execute(shell_command, args)
    print(result)
    return result
Example #4
0
 def run(self, command):
     command = command.format(**self.data)
     banner(command)
     parameter = command.split(" ")
     shell_command = parameter[0]
     args = parameter[1:]
     result = Shell.execute(shell_command, args)
     return result
Example #5
0
    def test_004(self):
        """testing cm group merge groupA groupB groupC"""
        HEADING()
        banner("cm group merge groupA groupB groupC")

        result = run("cm group merge groupA groupB groupC")
        assert "ok." in result
        return
Example #6
0
    def test_004(self):
        """testing cm group merge groupA groupB groupC"""
        HEADING()
        banner("cm group merge groupA groupB groupC")

        result = run("cm group merge groupA groupB groupC")
        assert "ok." in result
        return
Example #7
0
    def test_006(self):
        """testing cm group list --category=kilo --format json groupA"""
        HEADING()
        banner("cm group list --category=kilo --format=json groupA")

        result = run("cm group list --category=kilo  --format=json groupA")
        assert "groupA" in result
        return
Example #8
0
    def test_003(self):
        """testing cm group copy groupA groupB"""
        HEADING()
        banner("cm group copy groupA groupB")

        result = run("cm group copy groupA groupB")
        assert "[groupB]" in result

        return
Example #9
0
    def test_003(self):
        """testing cm list --cloud trial --user fake default"""
        HEADING()
        banner("cm list --cloud=trial --user=fake default")

        result = self.run("cm list --cloud=trial --user=fake default")
        assert "No" in result

        return
Example #10
0
    def test_003(self):
        """testing cm list --cloud trial --user fake default"""
        HEADING()
        banner("cm list --cloud=trial --user=fake default")

        result = self.run("cm list --cloud=trial --user=fake default")
        assert "No" in result

        return
Example #11
0
 def run(self, command):
     command = command.format(**self.data)
     banner(command, c='-')
     parameter = command.split(" ")
     shell_command = parameter[0]
     args = parameter[1:]
     result = Shell.execute(shell_command, args)
     print(result)
     return str(result)
Example #12
0
    def test_003(self):
        """testing cm group copy groupA groupB"""
        HEADING()
        banner("cm group copy groupA groupB")

        result = run("cm group copy groupA groupB")
        assert "[groupB]" in result

        return
Example #13
0
    def test_001(self):
        HEADING()
        d = self.d

        banner("VM Data")
        pprint(d.__dict__)

        banner("Add VM")
        cm = CloudmeshDatabase()

        name = "vm1"
        uuid = d.id

        vm = VM(name=name,
                uuid=uuid,
                user="******",
                type="VM",
                category="mycloud",
                **d)
        banner("VM added")

        pprint(vm.__dict__)
        vm.bla = "bla"
        cm.add(vm)
        cm.save()

        banner("Get VM from Database")

        o = cm.find(VM, name=name)
        #o = cm.find_by_name(VM, name)
        pprint(o)

        assert True
Example #14
0
    def test_009(self):
        """testing cm group remove --category=kilo --name=groupA --id=test-002"""
        HEADING()
        banner("cm group remove --category=kilo --name=groupA --id=test-002")

        result1 = run("cm group remove --category=kilo --name=groupA --id="
                      "test-002")
        print(result1)
        assert "Successfully removed ID" in result1

        result2 = run("cm group list groupA")
        assert "test-002" not in result2

        return
Example #15
0
    def test_009(self):
        """testing cm group remove --category=kilo --name=groupA --id=test-002"""
        HEADING()
        banner("cm group remove --category=kilo --name=groupA --id=test-002")

        result1 = run("cm group remove --category=kilo --name=groupA --id="
                      "test-002")
        print(result1)
        assert "Successfully removed ID" in result1

        result2 = run("cm group list groupA")
        assert "test-002" not in result2

        return
Example #16
0
    def test_001(self):
        HEADING()
        d = self.d

        banner("VM Data")
        pprint(d.__dict__)

        banner("Add VM")
        cm = CloudmeshDatabase()

        name = "vm1"
        uuid = d.id

        vm = VM(name=name,
                uuid=uuid,
                user="******",
                type="VM",
                category="mycloud",
                **d)
        banner("VM added")

        pprint (vm.__dict__)
        vm.bla = "bla"
        cm.add(vm)
        cm.save()


        banner("Get VM from Database")

        o = cm.find(VM, name=name)
        #o = cm.find_by_name(VM, name)
        pprint (o)


        assert True
Example #17
0
    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))
            Console.error("Please check if the file exists or is empty")
            print (e)

        banner("")
Example #18
0
    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))
            Console.error("Please check if the file exists or is empty")
            print(e)

        banner("")
Example #19
0
    def test_008(self):
        """testing cm group add --name=groupX --id albert-00x [WITH DEFAULT CLOUD=kilo, TYPE=VM]"""
        HEADING()
        banner("cm group add --name=groupX --id=albert-00x")

        result1 = run("cm default category=kilo")
        assert "kilo" in result1
        assert "category" in result1
        assert "ok" in result1

        result1 = run("cm default type=vm")
        assert "ok." in result1

        result2 = run("cm group add groupX --id=albert-00x")
        assert "albert-00x" in result2

        result3 = run("cm group list --category=kilo groupX")
        assert "kilo" in result3
        assert "vm" in result3

        return
Example #20
0
    def test_008(self):
        """testing cm group add --name=groupX --id albert-00x [WITH DEFAULT CLOUD=kilo, TYPE=VM]"""
        HEADING()
        banner("cm group add --name=groupX --id=albert-00x")

        result1 = run("cm default category=kilo")
        assert "kilo" in result1
        assert "category" in result1
        assert "ok" in result1

        result1 = run("cm default type=vm")
        assert "ok." in result1

        result2 = run("cm group add groupX --id=albert-00x")
        assert "albert-00x" in result2

        result3 = run("cm group list --category=kilo groupX")
        assert "kilo" in result3
        assert "vm" in result3

        return
Example #21
0
    def test_010(self):
        """testing cm group delete groupA --category=kilo"""
        HEADING()
        """
        banner("cm group delete groupA --category=kilo")
        result = run("cm group delete groupA --category=kilo")
        print(result)
        assert "ok." in result
        """

        banner("cm group delete groupB --category=kilo")
        result = run("cm group delete groupB --category=kilo")
        assert "ok." in result

        banner("cm group delete groupC --category=kilo")
        result = run("cm group delete groupC --category=kilo")
        assert "ok." in result

        banner("cm group delete groupX")
        result = run("cm group delete groupX")
        assert "ok." in result

        # Cleanup defaults
        run("cm default delete category")
        run("cm default delete type")

        return
Example #22
0
    def test_010(self):
        """testing cm group delete groupA --category=kilo"""
        HEADING()
        """
        banner("cm group delete groupA --category=kilo")
        result = run("cm group delete groupA --category=kilo")
        print(result)
        assert "ok." in result
        """

        banner("cm group delete groupB --category=kilo")
        result = run("cm group delete groupB --category=kilo")
        assert "ok." in result

        banner("cm group delete groupC --category=kilo")
        result = run("cm group delete groupC --category=kilo")
        assert "ok." in result

        banner("cm group delete groupX")
        result = run("cm group delete groupX")
        assert "ok." in result

        # Cleanup defaults
        run("cm default delete category")
        run("cm default delete type")

        return
Example #23
0
def cloudmesh_images(request, cloud=None):
    banner("images")
    if cloud is None:
        cloud = Default.get_cloud()
    # TODO: make the cloudname a parameter
    data = Image.list(cloud, format='dict')
    print json.dumps(data, indent=4)
    # TODO set proper columns
    order = [
        'id',
        'name',
        'cloud',
        'minDisk',
        'minRam',
        'os_image_size',
        'progress',
        'project',
        'status',
    ]
    return (dict_table(request,
                       title="Cloudmesh Images {}".format(cloud),
                       data=data,
                       order=order))
Example #24
0
def cloudmesh_images(request, cloud=None):
    banner("images")
    if cloud is None:
        cloud = Default.get_cloud()
    # TODO: make the cloudname a parameter
    data = Image.list(cloud, format='dict')
    print json.dumps(data, indent=4)
    # TODO set proper columns
    order = [
        'id',
        'name',
        'cloud',
        'minDisk',
        'minRam',
        'os_image_size',
        'progress',
        'project',
        'status',
    ]
    return (dict_table(request,
                       title="Cloudmesh Images {}".format(cloud),
                       data=data,
                       order=order))
Example #25
0
    def info(self, what=None, kind=None):
        """
        prints information about the database
        """
        count_result = {}
        if kind is None:
            kinds = tablenames()
        else:
            kinds = Parameter.expand(kind)
        if what is None:
            infos = "table,count"
        else:
            infos = Parameter.expand(what)

        banner("Databse table information", c="-")
        inspector = inspect(self.db.engine)

        if "table" in infos:
            for table_name in inspector.get_table_names():
                if table_name in kinds:
                    print(table_name + ":")
                    for column in inspector.get_columns(table_name):
                        print("  ", column['name'], column['type'])

        counter = 0
        if "count" in infos:
            for table_name in inspector.get_table_names():
                if table_name in kinds:
                    t = table(table_name)
                    rows = self.session.query(t).count()
                    count_result[table_name] = rows
                    print("Count {:}: {:}".format(table_name, rows))
                    counter = counter + rows
            count_result['sum'] = counter

        return count_result
Example #26
0
    def info(self, what=None, kind=None):
        """
        prints information about the database
        """
        count_result = {}
        if kind is None:
            kinds = tablenames()
        else:
            kinds = Parameter.expand(kind)
        if what is None:
            infos = "table,count"
        else:
            infos = Parameter.expand(what)

        banner("Databse table information", c="-")
        inspector = inspect(self.db.engine)

        if "table" in infos:
            for table_name in inspector.get_table_names():
                if table_name in kinds:
                    print(table_name + ":")
                    for column in inspector.get_columns(table_name):
                        print("  ", column['name'], column['type'])

        counter = 0
        if "count" in infos:
            for table_name in inspector.get_table_names():
                if table_name in kinds:
                    t = table(table_name)
                    rows = self.session.query(t).count()
                    count_result[table_name] = rows
                    print("Count {:}: {:}".format(table_name, rows))
                    counter = counter + rows
            count_result['sum'] = counter

        return count_result
Example #27
0
                delete_on_cloud = self.delete_on_cloud

            for map in list(keymap.values()):
                if delete_on_cloud:
                    self.delete_key_on_cloud(map["cloud_name"], map["key_name_on_cloud"])
            sshdb.delete_key_cloud_map_entry(key["name"])

        sshdb.delete(keyname)


if __name__ == "__main__":
    print ("HALLO")
    from cloudmesh_client.util import banner

    mykeys = SSHKeyManager()
    mykeys.get_all("laszewsk")

    banner("ssh keys")

    print(mykeys)
    print(mykeys.keys())

    print("GIT")
    mykeys = SSHKeyManager()
    mykeys.get_from_git("laszewsk")
    print(mykeys)
    print(mykeys.keys())

    #    print(mykeys['id_rsa.pub'])
#    print (len(mykeys))
Example #28
0
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!")
Example #29
0
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())
Example #30
0
 def sh(self, command):
     banner(command)
     run(command)
Example #31
0
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)
Example #32
0
    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(list_printer(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 ""
Example #33
0
from pprint import pprint
from __future__ import print_function

import requests
from cloudmesh_client.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])
Example #34
0
        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")
Example #35
0
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())
Example #36
0
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!")
Example #37
0
 def sh(self, command):
     banner(command)
     run(command)
Example #38
0
        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")
Example #39
0
    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(list_printer(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 ""
Example #40
0
from pprint import pprint
from __future__ import print_function

import requests
from cloudmesh_client.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])