Beispiel #1
0
def createInstances(basedir, clusterid, num, anyInterface = False):
        try:
                os.mkdir(basedir)
        except OSError:
                pass
	ports = [create.Port(
		2000 + 1000 * clusterid + 10*i,
		anyInterface and "0.0.0.0" or ("127.%d.%d.1"%(clusterid, i)))
		for i in range(1, num + 1)]
	dirs = ["%s/%d"%(basedir, i) for i in range(num)]
	allNodes = [p for p in ports]
	for thisdir, thisport in zip(dirs, ports):
		create.setupDirectory(thisdir, thisport, allNodes)

        create.setupDirectory(
            "%s/cli"%(basedir,),
            create.Port(2000 + 1000 * clusterid,
                anyInterface and "0.0.0.0" or ("127.%d.%d.1"%(clusterid, 0))),
            allNodes,
            isCli=True)

	restartAllScript = "%s/restartall.sh"%(basedir, )
	with open(restartAllScript, 'w') as script:
		script.write("""#!/bin/bash -x
for dir in {0..%d}; do
	%s/$dir/restart.sh
done
"""%(num-1, basedir))
	os.chmod(restartAllScript, 0755)
	startAllScript = "%s/startall.sh"%(basedir, )
	with open(startAllScript, 'w') as script:
		script.write("""#!/bin/bash -x
for dir in {0..%d}; do
	%s/$dir/startup.sh
done
"""%(num-1, basedir))
	os.chmod(startAllScript, 0755)
	stopAllScript = "%s/stopall.sh"%(basedir, )
	with open(stopAllScript, 'w') as script:
		script.write("""#!/bin/bash -x
for dir in {0..%d}; do
	%s/$dir/stop.sh
done
"""%(num-1, basedir))
	os.chmod(stopAllScript, 0755)
Beispiel #2
0
def createInstances(basedir, instInfo, certfile):
    try:
        os.mkdir(basedir)
    except OSError:
        pass
    sshHosts = ["%s@%s" % (node["user"], node["extip"]) for node in instInfo.values()]
    allNodes = ["%s" % (node["extip"]) for node in instInfo.values()]
    for node, sshHost in zip(allNodes, sshHosts):
        args = [
            "ssh",
            "ssh",
            "-i",
            certfile,
            sshHost,
            "cd poseidon && git fetch origin && git pull origin master && ant && python scripts/create.py --btport 6881 -n "
            + (",".join(allNodes))
            + " -d ~/"
            + basedir
            + " --hostip "
            + node,
        ]
        print args
        os.spawnlp(os.P_WAIT, *args)

    create.setupDirectory(
        os.path.join(os.getcwd(), basedir, "cli"),
        create.Port(8000, "0.0.0.0", "", create.BT_PORT),
        [create.Port(create.DEFAULT_PORT, n, n, create.BT_PORT) for n in allNodes],
        isCli=True,
    )

    restartAllScript = "%s/restartall.sh" % (basedir,)
    with open(restartAllScript, "w") as script:
        script.write(
            """#!/bin/bash
for sshHost in %s; do
    echo $sshHost
    ssh -i %s $sshHost '%s/restart.sh'" $*"
done
"""
            % (" ".join(sshHosts), certfile, basedir)
        )
    os.chmod(restartAllScript, 0755)
    startAllScript = "%s/startall.sh" % (basedir,)
    with open(startAllScript, "w") as script:
        script.write(
            """#!/bin/bash
for sshHost in %s; do
    echo $sshHost
    ssh -i %s $sshHost '%s/startup.sh'" $*"
done
"""
            % (" ".join(sshHosts), certfile, basedir)
        )
    os.chmod(startAllScript, 0755)
    stopAllScript = "%s/stopall.sh" % (basedir,)
    with open(stopAllScript, "w") as script:
        script.write(
            """#!/bin/bash
for sshHost in %s; do
    echo $sshHost
    ssh -i %s $sshHost '%s/stop.sh'" $*"
done
"""
            % (" ".join(sshHosts), certfile, basedir)
        )
    os.chmod(stopAllScript, 0755)
    stopAllScript = "%s/commandonall.sh" % (basedir,)
    with open(stopAllScript, "w") as script:
        script.write(
            """#!/bin/bash
for sshHost in %s; do
    echo $sshHost
    ssh -i %s $sshHost "$1"
done
"""
            % (" ".join(sshHosts), certfile)
        )
    os.chmod(stopAllScript, 0755)
    stopAllScript = "%s/rsyncall.sh" % (basedir,)
    with open(stopAllScript, "w") as script:
        script.write(
            """#!/bin/bash
for sshHost in %s; do
    echo $sshHost
    rsync -av -e "ssh -i %s" $1 "${sshHost}:$2"
done
"""
            % (" ".join(sshHosts), certfile)
        )
    os.chmod(stopAllScript, 0755)