bitkeeper revision 1.624 (3fbdff8cjOXXJYub36D6Ko7MDfqOsA)

XenoUtil.py:
  More XenoUtil funcs.
This commit is contained in:
kaf24@scramble.cl.cam.ac.uk committed 2003-11-21 12:05:32 +00:00
1 parent a2764176c1
commit 2e0a75d057
1 file changed
+64
+64
View File
@@ -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
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.