# HG changeset patch # User igor # Date 1190379664 -10800 # Node ID 6bb2a29e91bef3eeb5aebb7a0fe3869f136a7de3 # Parent c4a092e32ee114d43fb3be0051e3011eb618b3e9 interfaces connection and disconnection diff -r c4a092e32ee1 -r 6bb2a29e91be xentaur.py --- a/xentaur.py Fri Sep 21 13:16:28 2007 +0300 +++ b/xentaur.py Fri Sep 21 16:01:04 2007 +0300 @@ -25,6 +25,12 @@ #run(cmds[0],*cmds[1:]) run("/bin/sh", "-c", line) +def run_command_return_stdout(line): + p = os.popen(line) + output = p.read() + p.close() + return output + def create_bridges_script(): unbound_bridges=bridges create_unbound_bridges="\n".join(map(lambda x: "sudo /usr/sbin/brctl show | awk '{print $1}' | grep -q "+x+" || sudo /usr/sbin/brctl addbr "+x, unbound_bridges)) @@ -175,6 +181,12 @@ xentaur {start|stop|start-bridges|start-domains|stop-domains|screen|graph} """ +#----------------------------------------------------------------------- +# DOMAINS + +def get_domain_id(domain): + return run_command_return_stdout("sudo xm list | awk '{if ($1 == \"'%s'\") print $2}'" % domain).rstrip("\n") + #----------------------------------------------------------------------- # BRIDGES and IFACES @@ -197,6 +209,34 @@ """ run_command("sudo ip link show %s" % bridge) + +def int_disconnect(domain, int_number): + """ + Disconnect the interface with the number + of the domain from the bridge to which + it is connected + """ + dom_id=get_domain_id(domain) + bridge=vbridges_table[domain][int_number] + if not bridge: + print "Interface %s of the %s domain is not connected" % (int_number, domain) + return 1 + run_command("sudo brctl delif %s vif%s.%s" % (bridge, dom_id, int_number)) + vbridges_table[domain][int_number]='' + +def int_connect(domain, int_number, bridge): + """ + Connect the interface with the number + of the domain the the bridge + """ + dom_id=get_domain_id(domain) + + if vbridges_table[domain][int_number]: + print "Interface %s of the %s domain is connected already to the %s bridge" % (int_number, domain, vbridges_table[domain][int_number]) + return 1 + run_command("sudo brctl addif %s vif%s.%s" % (bridge, dom_id, int_number)) + vbridges_table[domain][int_number]=bridge + #-----------------------------------------------------------------------