def addIptablePolicy(outlet, brName): sp.call(['sysctl', 'net.ipv4.ip_forward=1']) sp.call(['iptables', '-t', 'nat', '-A', 'POSTROUTING', '-o', outlet, '-j', 'MASQUERADE']) sp.call(['iptables', '-I', 'FORWARD', '1', '-i', brName, '-j', 'ACCEPT']) sp.call(['iptables', '-I', 'FORWARD', '1', '-o', brName, '-m', 'state', '--state', 'RELATED,ESTABLISHED', '-j', 'ACCEPT']) return; def bootQEMU(qemuCommand): sp.Popen(qemuCommand); return; tapPrefix = '_tap' VMInfo = getVMInfo() basePath = VMInfo['hdaimg']['path'] if basePath[-1] is not '/': basePath += '/' baseName = VMInfo['hdaimg']['base'] baseCommand = ['qemu-system-x86_64'] for key, value in VMInfo['vmconfig'].iteritems(): baseCommand.append(key) if value is not None: baseCommand.append(value) topoInfo = getTopoInfo() if topoInfo == {}: for machine in sys.argv[1:]: topoInfo[machine] = ['br0']
__author__ = "Yigong Wang" __license__ = "GPL" __email__ = "*****@*****.**" import subprocess as sp import sys from module.getConf import getVMInfo, getTopoInfo, getExisitingTopo def callCMD(cmd, user, ipAddr): sp.call(['ssh', user + '@' + ipAddr, cmd]) return ipbase = getVMInfo()['vmnet']['ipbase'] existingTopo = getExisitingTopo(); def sendCMD(cmd): for machineNo in existingTopo: print "running " + cmd + " on machine No:" + machineNo callCMD(cmd, 'root', ipbase + machineNo) return cmd = ' '.join(sys.argv[1:]) print cmd sendCMD(cmd)