Ejemplo n.º 1
0
def sshKeysDeploy():
    """ Deploy key ssh """

    (listnodes, nodes) = instanceListAll()

    os.system("eval `ssh-agent -s`")
    os.system("ssh-add")

    # prepare authentification forwarding
    os.system("eval `ssh-agent`")
    os.system("ssh-add ~/.ssh/google_compute_engine")

    allnodes = listnodes['all']

    listP = []

    for nodename in allnodes:

        utils.print_header('Generating SSH Keys for ' + nodename)

        # get node info
        node = nodes[nodename]

        externalIp = node['externalIp']

        listCommand = []
        listCommand.append("rm -rf .ssh/id_rsa*")
        listCommand.append("ssh-keygen -q -t rsa -N \"\" -f ~/.ssh/id_rsa")
        listCommand.append("cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys")
        listCommand.append("chmod 0600 ~/.ssh/authorized_keys")

        listCommand.append("echo \"StrictHostKeyChecking no\" >> .ssh/config")
        listCommand.append("chmod 600  .ssh/config")

        if nodename == 'cluster-data-master' or True:
            for nameother in allnodes:

                if nameother == nodename:
                    pass
                else:
                    localCommand = "ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa {0}@{1}".format(
                        username, nameother)

                    listCommand.append(localCommand)
        else:

            nameother = 'cluster-data-master'
            localCommand = "ssh-copy-id -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa {0}@{1}".format(
                username, nameother)

            listCommand.append(localCommand)

        command = ';'.join(listCommand)

        # Execute command
        P = utils.sshAsync(externalIp, command)
        listP.append(P)

    utils.waitTermination(listP)
Ejemplo n.º 2
0
def runOnAllNodesAsync(command):
    """
    Run a command on all nodes
    """

    listnodes, nodes = instanceListAll()

    allnodes = listnodes['all']

    listP = []

    for nodename in allnodes:

        utils.print_header('ON [' + nodename + '] running: ' + command)
        node = nodes[nodename]
        externalIp = node['externalIp']
        P = utils.sshAsync(externalIp, command)
        listP.append(P)

    utils.waitTermination(listP)