diff options
author | kaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk> | 2003-11-21 12:05:32 +0000 |
---|---|---|
committer | kaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk> | 2003-11-21 12:05:32 +0000 |
commit | 2e0a75d057ccfd7efb8f7c6c143d24f904bfdd3a (patch) | |
tree | beb0986e5f59c8a74363184495d013f5c7b0949b /tools/xc/py | |
parent | a2764176c13af0f3acdba921fe5cb87409285df9 (diff) | |
download | xen-2e0a75d057ccfd7efb8f7c6c143d24f904bfdd3a.tar.gz xen-2e0a75d057ccfd7efb8f7c6c143d24f904bfdd3a.tar.bz2 xen-2e0a75d057ccfd7efb8f7c6c143d24f904bfdd3a.zip |
bitkeeper revision 1.624 (3fbdff8cjOXXJYub36D6Ko7MDfqOsA)
XenoUtil.py:
More XenoUtil funcs.
Diffstat (limited to 'tools/xc/py')
-rw-r--r-- | tools/xc/py/XenoUtil.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/tools/xc/py/XenoUtil.py b/tools/xc/py/XenoUtil.py index f9b8728290..1a135bfdff 100644 --- a/tools/xc/py/XenoUtil.py +++ b/tools/xc/py/XenoUtil.py @@ -64,3 +64,67 @@ def lookup_blkdev_partn_info(partition): string.atol(m.group(2)), m.group(3) ) return None + + +def get_current_ipaddr(dev='eth0'): + """Return a string containing the primary IP address for the given + network interface (default 'eth0'). + """ + fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) + lines = fd.readlines() + for line in lines: + m = re.search( '^\s+inet addr:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', + line ) + if m: + return m.group(1) + return None + +def get_current_ipmask(dev='eth0'): + """Return a string containing the primary IP netmask for the given + network interface (default 'eth0'). + """ + fd = os.popen( '/sbin/ifconfig ' + dev + ' 2>/dev/null' ) + lines = fd.readlines() + for line in lines: + m = re.search( '^.+Mask:([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*', + line ) + if m: + return m.group(1) + return None + +def get_current_ipgw(dev='eth0'): + """Return a string containing the IP gateway for the given + network interface (default 'eth0'). + """ + fd = os.popen( '/sbin/route -n' ) + lines = fd.readlines() + for line in lines: + m = re.search( '^\S+\s+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)' + + '\s+\S+\s+\S*G.*' + dev + '.*', line ) + if m: + return m.group(1) + return None + +def setup_vfr_rules_for_vif(dom,vif,addr): + """Takes a tuple ( domain-id, vif-id, ip-addr ), where the ip-addr + is expressed as a textual dotted quad, and set up appropriate routing + rules in Xen. No return value. + """ + fd = os.open( '/proc/xeno/vfr', os.O_WRONLY ) + if ( re.search( '169\.254', addr) ): + os.write( fd, 'ADD ACCEPT srcaddr=' + addr + + ' srcaddrmask=255.255.255.255' + + ' srcdom=' + str(dom) + ' srcidx=' + str(vif) + + ' dstdom=0 dstidx=0 proto=any\n' ) + else: + os.write( fd, 'ADD ACCEPT srcaddr=' + addr + + ' srcaddrmask=255.255.255.255' + + ' srcdom=' + str(dom) + ' srcidx=' + str(vif) + + ' dst=PHYS proto=any\n' ) + os.write( fd, 'ADD ACCEPT dstaddr=' + addr + + ' dstaddrmask=255.255.255.255' + + ' src=ANY' + + ' dstdom=' + str(dom) + ' dstidx=' + str(vif) + + ' proto=any\n' ) + os.close( fd ) + return None |