xentaur
changeset 23:6bb2a29e91be
interfaces connection and disconnection
author | igor |
---|---|
date | Fri Sep 21 16:01:04 2007 +0300 (2007-09-21) |
parents | c4a092e32ee1 |
children | fcd08a4f3216 |
files | xentaur.py |
line diff
1.1 --- a/xentaur.py Fri Sep 21 13:16:28 2007 +0300 1.2 +++ b/xentaur.py Fri Sep 21 16:01:04 2007 +0300 1.3 @@ -25,6 +25,12 @@ 1.4 #run(cmds[0],*cmds[1:]) 1.5 run("/bin/sh", "-c", line) 1.6 1.7 +def run_command_return_stdout(line): 1.8 + p = os.popen(line) 1.9 + output = p.read() 1.10 + p.close() 1.11 + return output 1.12 + 1.13 def create_bridges_script(): 1.14 unbound_bridges=bridges 1.15 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)) 1.16 @@ -175,6 +181,12 @@ 1.17 xentaur {start|stop|start-bridges|start-domains|stop-domains|screen|graph} 1.18 """ 1.19 1.20 +#----------------------------------------------------------------------- 1.21 +# DOMAINS 1.22 + 1.23 +def get_domain_id(domain): 1.24 + return run_command_return_stdout("sudo xm list | awk '{if ($1 == \"'%s'\") print $2}'" % domain).rstrip("\n") 1.25 + 1.26 1.27 #----------------------------------------------------------------------- 1.28 # BRIDGES and IFACES 1.29 @@ -197,6 +209,34 @@ 1.30 """ 1.31 run_command("sudo ip link show %s" % bridge) 1.32 1.33 + 1.34 +def int_disconnect(domain, int_number): 1.35 + """ 1.36 + Disconnect the interface with the number <int_number> 1.37 + of the domain <domain> from the bridge to which 1.38 + it is connected 1.39 + """ 1.40 + dom_id=get_domain_id(domain) 1.41 + bridge=vbridges_table[domain][int_number] 1.42 + if not bridge: 1.43 + print "Interface %s of the %s domain is not connected" % (int_number, domain) 1.44 + return 1 1.45 + run_command("sudo brctl delif %s vif%s.%s" % (bridge, dom_id, int_number)) 1.46 + vbridges_table[domain][int_number]='' 1.47 + 1.48 +def int_connect(domain, int_number, bridge): 1.49 + """ 1.50 + Connect the interface with the number <int_number> 1.51 + of the domain <domain> the the bridge <bridge> 1.52 + """ 1.53 + dom_id=get_domain_id(domain) 1.54 + 1.55 + if vbridges_table[domain][int_number]: 1.56 + print "Interface %s of the %s domain is connected already to the %s bridge" % (int_number, domain, vbridges_table[domain][int_number]) 1.57 + return 1 1.58 + run_command("sudo brctl addif %s vif%s.%s" % (bridge, dom_id, int_number)) 1.59 + vbridges_table[domain][int_number]=bridge 1.60 + 1.61 #----------------------------------------------------------------------- 1.62 1.63