diff options
Diffstat (limited to 'abs/core-testing/LinHES-config/mv_network.py')
-rwxr-xr-x | abs/core-testing/LinHES-config/mv_network.py | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/abs/core-testing/LinHES-config/mv_network.py b/abs/core-testing/LinHES-config/mv_network.py index 855940f..3f8de3b 100755 --- a/abs/core-testing/LinHES-config/mv_network.py +++ b/abs/core-testing/LinHES-config/mv_network.py @@ -3,7 +3,7 @@ import sys , os, commands , glob, time, re import logging import mv_common import socket, fcntl, struct, array -import netifaces +import netifaces, iplib global etcnetdir etcnetdir = "/etc/net/ifaces" @@ -49,6 +49,25 @@ def get_ip(ifname): struct.pack('256s', ifname[:15]) )[20:24]) +def get_default_route(iface): + rcroute = "127.0.0.1" + f = open ('/proc/net/route', 'r') + for line in f: + words = string.split (line) + netiface = words[0] + route = words[2] + flags = words[3] + try: + if ( netiface == iface ) and ( flags == "0003") : + route = iplib.IPv4Address(route, notation="hex") + t = str(route.get_dot()) + s = t.split(".") + rcroute = s[3] + "." + s[2] + "." + s[1] + "." + s[0] + break + except ValueError: + pass + return rcroute + def setup_MYTH_IP(systemconfig): default_interface = systemconfig["default_interface"] #check for dhcp in use @@ -64,6 +83,41 @@ def setup_MYTH_IP(systemconfig): logging.debug(" Using %s as default ip", defaultip) return defaultip + +def setup_MYTH_GW(systemconfig): + default_interface = systemconfig["default_interface"] + #check for dhcp in use + if setup_MYTH_DHCP(systemconfig) == "0": + logging.debug(" dhcp is in use, finding dhcp ip") + defaultgw = get_default_route(default_interface) + else: + try: + defaultgw = systemconfig["Hostgw"+default_interface] + except: + logging.debug(" Error occured finding the defaultgw") + defaultgw = "127.0.0.1" + logging.debug(" Using %s as default gw", defaultgw) + return defaultgw + + +def setup_MTYH_DNS(): + returndns = "127.0.0.1" + try: + f = open ('/etc/resolv.conf', 'r') + for line in f: + if line.startswith("nameserver"): + print line + returndns = line.split()[1] + break + except: + logging.debug(" Couldn't open /etc/resolv.conf for myth_dns") + logging.debug(" using %s for myth_dns", returndns) + return returndns + + + + + def flush(netdev): logging.debug(" Flushing %s",netdev) cmd = '''ip address flush dev %s''' %netdev |