diff options
author | James Meyer <james.meyer@operamail.com> | 2009-06-21 23:59:31 (GMT) |
---|---|---|
committer | James Meyer <james.meyer@operamail.com> | 2009-06-21 23:59:31 (GMT) |
commit | c9d85b81497f3036db26d3d481108072ba2ac560 (patch) | |
tree | 11fd73c4c6e54d35945424c765381ff1c00a56ec /abs/core-testing/LinHES-config/mv_network.py | |
parent | 1baf8111524169f6d9349223e7764a43e2525a1a (diff) | |
download | linhes_pkgbuild-c9d85b81497f3036db26d3d481108072ba2ac560.zip linhes_pkgbuild-c9d85b81497f3036db26d3d481108072ba2ac560.tar.gz linhes_pkgbuild-c9d85b81497f3036db26d3d481108072ba2ac560.tar.bz2 |
LinHES-config: several minor fixes and finish some functions that slipped through the cracks.
introduce remove_file
fix slave and fe only
finish mysql_network_connection
finish mysql_network
fix ownership for .mythtv ir mv_ir
fix myth_ip to always report the ip even if dhcp is used
Diffstat (limited to 'abs/core-testing/LinHES-config/mv_network.py')
-rwxr-xr-x | abs/core-testing/LinHES-config/mv_network.py | 113 |
1 files changed, 91 insertions, 22 deletions
diff --git a/abs/core-testing/LinHES-config/mv_network.py b/abs/core-testing/LinHES-config/mv_network.py index ae3aaf7..ae7f861 100755 --- a/abs/core-testing/LinHES-config/mv_network.py +++ b/abs/core-testing/LinHES-config/mv_network.py @@ -2,20 +2,10 @@ import sys , os, commands , glob, time, re import logging import mv_common +import socket, fcntl, struct, array global etcnetdir etcnetdir = "/etc/net/ifaces" - -def setup_MYTH_IP(systemconfig): - default_interface = systemconfig["default_interface"] - try: - defaultip = systemconfig["Hostip"+default_interface] - except: - logging.debug(" Error occured finding the defaultip") - defaultip = "127.0.0.1" - logging.debug(" Using %s as default ip", defaultip) - return defaultip - def setup_MYTH_DHCP(systemconfig): default_interface = systemconfig["default_interface"] try: @@ -23,9 +13,56 @@ def setup_MYTH_DHCP(systemconfig): except: logging.critical(" *Error occured finding default dhcp") defaultdhcp = "0" - logging.debug(" Using %s as dhcp value for %s", default_interface, defaultdhcp) + logging.debug(" Using %s as dhcp value for %s", defaultdhcp, default_interface) return defaultdhcp +def all_interfaces(): + max_possible = 128 # arbitrary. raise if needed. + bytes = max_possible * 32 + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + names = array.array('B', '\0' * bytes) + outbytes = struct.unpack('iL', fcntl.ioctl( + s.fileno(), + 0x8912, # SIOCGIFCONF + struct.pack('iL', bytes, names.buffer_info()[0]) + ))[0] + namestr = names.tostring() + return [namestr[i:i+32].split('\0', 1)[0] for i in range(0, outbytes, 32)] + +def get_ip(ifname): + logging.debug(" Finding ip address for %s", ifname) + all_if = all_interfaces() + logging.debug(" found interfaces:%s", all_if) + if ifname in all_if : + logging.debug(" Found %s in all_interfaces", ifname) + else: + logging.critical("* Couldn't find %s in list", ifname) + ifname = all_if[0] + logging.critical("* Using %s for interface name", ifname) + + + s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + return socket.inet_ntoa(fcntl.ioctl( + s.fileno(), + 0x8915, # SIOCGIFADDR + struct.pack('256s', ifname[:15]) + )[20:24]) + +def setup_MYTH_IP(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") + defaultip = get_ip(default_interface) + else: + try: + defaultip = systemconfig["Hostip"+default_interface] + except: + logging.debug(" Error occured finding the defaultip") + defaultip = "127.0.0.1" + logging.debug(" Using %s as default ip", defaultip) + return defaultip + def flush(netdev): logging.debug(" Flushing %s",netdev) cmd = '''ip address flush dev %s''' %netdev @@ -44,7 +81,7 @@ def kill_dhcp(basedir): f.close cmd = "kill -9 %s" %pid mv_common.runcmd(cmd) - os.remove(FILE) + mv_common.remove_file(FILE) os.chdir(stddir) except: pass @@ -68,6 +105,8 @@ def setup_hostname(systemconfig): logging.info(" Using default value of me") hostname = "me" logging.info(" Setting the hostname to %s", hostname) + cmd = ''' echo %s > /etc/hostname ''' %hostname + mv_common.runcmd(cmd) cmd = "cat /etc/hosts | grep -v 127.0.0.1 | grep -v %s > /tmp/hosts" %hostname mv_common.runcmd(cmd) if systemconfig["mythdhcp"] == "1" : @@ -193,11 +232,12 @@ def setup_interface(netdev,systemconfig): logging.info(" Disabling wireless extensions") cmd = '''sed -i -e 's/^CONFIG_WIRLESS=.*$/CONFIG_WIRLESS=no/g' %s/%s/options''' %(etcnetdir, netdev) mv_common.runcmd(cmd) - try: - wpafile=etcnetdir+"/"+netdev+"/wpa_supplicant.conf" - os.remove(wpafile) - except: - logging.debug(" Couldn't remove %s",wpafile) + #try: + wpafile=etcnetdir+"/"+netdev+"/wpa_supplicant.conf" + #os.remove(wpafile) + mv_common.remove_file(wpafile) + #except: + #logging.debug(" Couldn't remove %s",wpafile) if netinfo["UseDHCP"] == "0" : logging.info(" Enabling DHCP support") @@ -256,10 +296,11 @@ def find_active(systemconfig): logging.debug(" _Start of find_active") if systemconfig["mythdhcp"] == "1": - try: - os.remove("/etc/resolv.conf") - except: - logging.debug(" couldn't remove /etc/resolv.conf") + mv_common.remove_file("/etc/resolv.conf") + #try: + #os.remove("/etc/resolv.conf") + #except: + #logging.debug(" couldn't remove /etc/resolv.conf") cmd = ''' echo search lan > /etc/resolv.conf ''' mv_common.runcmd(cmd) cmd = ''' echo nameserver 127.0.0.1 >> /etc/resolv.conf ''' @@ -329,15 +370,43 @@ def stop_network(): logging.info(" Will not stop network due to netboot/vnc") pass +def hostname_change_check(systemconfig): + restartfe = False + logging.debug(" _Start of hostname_change_check") + oldhostname = socket.gethostname() + #oldhostname = "crap" + newhostname = systemconfig["hostname"] + mv_root = systemconfig["MVROOT"] + logging.debug(" Old hostname: %s", oldhostname) + logging.debug(" New hostname: %s", newhostname) + if oldhostname != newhostname : + logging.info(" Changing hostname in database to match new hostname") + cmd ="%s/bin/restore_default_settings.sh -cuhostname -o -h%s" %(mv_root, oldhostname) + mv_common.runcmd(cmd) + logging.info(" Changing hostname to %s", newhostname) + cmd = "hostname %s" %newhostname + mv_common.runcmd(cmd) + if systemconfig["SystemType"] != "Frontend_only" : + logging.info(" Restarting backend") + mv_common.stop_service("mythbackend") + mv_common.start_service("mythbackend") + restartfe = True + else: + logging.debug(" old and new hostnames matched, leaving things along") + logging.debug(" __End of hostname_change_check") + return restartfe + def setup_network (systemconfig): logging.info("____Start of network____") logging.info(" Setting up the network") + restartfe = hostname_change_check(systemconfig) setup_hostname(systemconfig) find_active(systemconfig) start_network() logging.info("__End of network\n") + return restartfe |