summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/LinHES-config/mv_network.py
diff options
context:
space:
mode:
authorJames Meyer <james.meyer@operamail.com>2009-07-07 02:28:18 (GMT)
committerJames Meyer <james.meyer@operamail.com>2009-07-07 02:28:18 (GMT)
commitb5cfd91270e2d8fe458b020d115cd6720c2aa9dd (patch)
tree2a2afe4c5edac53cc2d9b40741bb569dcba84043 /abs/core-testing/LinHES-config/mv_network.py
parent7302f47f1619232391cbefcf92c536777d17edb4 (diff)
downloadlinhes_pkgbuild-b5cfd91270e2d8fe458b020d115cd6720c2aa9dd.zip
linhes_pkgbuild-b5cfd91270e2d8fe458b020d115cd6720c2aa9dd.tar.gz
linhes_pkgbuild-b5cfd91270e2d8fe458b020d115cd6720c2aa9dd.tar.bz2
LinHES-config: write udev rules for network interfaces based on mac address.
Only done during install.
Diffstat (limited to 'abs/core-testing/LinHES-config/mv_network.py')
-rwxr-xr-xabs/core-testing/LinHES-config/mv_network.py44
1 files changed, 36 insertions, 8 deletions
diff --git a/abs/core-testing/LinHES-config/mv_network.py b/abs/core-testing/LinHES-config/mv_network.py
index ae7f861..526faae 100755
--- a/abs/core-testing/LinHES-config/mv_network.py
+++ b/abs/core-testing/LinHES-config/mv_network.py
@@ -1,8 +1,9 @@
-# -*- coding: utf-8 -*-
+ # -*- coding: utf-8 -*-
import sys , os, commands , glob, time, re
import logging
import mv_common
import socket, fcntl, struct, array
+import netifaces
global etcnetdir
etcnetdir = "/etc/net/ifaces"
@@ -291,22 +292,49 @@ def devcheck(netdev):
else:
return False
-def find_active(systemconfig):
+def udev_rules(netdev):
+ filename = "/etc/udev/rules.d/net.rules"
+ if devcheck(netdev):
+ logging.info(" Finding macaddress for %s",netdev)
+ try:
+ macaddress = netifaces.ifaddresses(netdev)[netifaces.AF_LINK][0]['addr']
+ logging.debug(" Macaddress: %s",macaddress)
+ except:
+ logging.debug(" Couldn't find mac address for %s",netdev)
+ return
+ try:
+ f = open(filename,'a')
+ except:
+ logging.debug(" Couldn't open %s for writing", filename)
+ return
+ if netdev.startswith('eth'):
+ line = '''KERNEL=="eth*", SYSFS{address}=="%s", NAME="%s"''' % ( macaddress , netdev)
+ elif netdev.startswith('wlan'):
+ line = '''KERNEL=="wlan*", SYSFS{address}=="%s", NAME="%s"'''% ( macaddress , netdev)
+ elif netdev.startswith('ath'):
+ line = '''KERNEL=="ath*", SYSFS{address}=="%s", NAME="%s"''' % ( macaddress , netdev)
+ logging.debug(" adding to net.rules ")
+ logging.debug(" %s",line)
+ f.write(line)
+ f.write("\n")
+ f.close()
+
+
+
+def find_active(systemconfig,this_is_install):
interfacelist=('eth0', 'eth1', 'wlan0', 'wlan1', 'ath0')
logging.debug(" _Start of find_active")
if systemconfig["mythdhcp"] == "1":
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 '''
mv_common.runcmd(cmd)
for netdev in interfacelist:
+ if this_is_install:
+ udev_rules(netdev)
currentnet = "HostActive" + netdev
try:
systemconfig[currentnet]
@@ -398,12 +426,12 @@ def hostname_change_check(systemconfig):
-def setup_network (systemconfig):
+def setup_network (systemconfig,this_is_install):
logging.info("____Start of network____")
logging.info(" Setting up the network")
restartfe = hostname_change_check(systemconfig)
setup_hostname(systemconfig)
- find_active(systemconfig)
+ find_active(systemconfig,this_is_install)
start_network()
logging.info("__End of network\n")
return restartfe