parse input augtool strings to oper,key,value --- scripts/network.py | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-) diff --git a/scripts/network.py b/scripts/network.py index f51ee7c..65b551c 100644 --- a/scripts/network.py +++ b/scripts/network.py @@ -165,11 +165,11 @@ class Network: ntpconf = ntpconf.split("\n") for line in ntpconf: try: - oper, file, value = line.split() + oper, key, value = line.split() + augtool(oper, key, value) except: - oper, file = line.split() - - augtool(oper, line, "") + oper, key = line.split() + augtool(oper, key, "") if OVIRT_VARS.has_key("OVIRT_NTP"): offset=1 @@ -201,33 +201,33 @@ class Network: for line in self.IF_CONFIG: log(line) try: - oper, file, value = line.split() - augtool(oper, file, value) + oper, key, value = line.split() + augtool(oper, key, value) except: - oper, file = line.split() - augtool(oper, line, "") + oper, key = line.split() + augtool(oper, key, "") for line in self.BR_CONFIG: log(line) try: - oper, file, value = line.split() - augtool(oper, file, value) + oper, key, value = line.split() + augtool(oper, key, value) except: try: - oper, file = line.split() - augtool(oper, line, "") + oper, key = line.split() + augtool(oper, key, "") except: pass for line in self.VL_CONFIG.split("\n"): log(line) try: - oper, file, value = line.split() - augtool(oper, file, value) + oper, key, value = line.split() + augtool(oper, key, value) except: try: - oper, file = line.split() - augtool(oper, line, "") + oper, key = line.split() + augtool(oper, key, "") except: pass -- 1.7.3.4
Alan Pevec
2011-Aug-11 00:02 UTC
[Ovirt-devel] [PATCH] persist only configured network configs
blind ifcfg-* persists too much also add mac/nic mapping missing in network.py rhbz#725392 Signed-off-by: Alan Pevec <apevec at redhat.com> --- scripts/network.py | 48 +++++++++++++++++++++++++++----------- scripts/ovirt-config-networking | 22 +++++++++++------ scripts/ovirt-functions | 1 - scripts/ovirtfunctions.py | 13 ---------- 4 files changed, 48 insertions(+), 36 deletions(-) diff --git a/scripts/network.py b/scripts/network.py index 65b551c..50d4624 100644 --- a/scripts/network.py +++ b/scripts/network.py @@ -17,6 +17,7 @@ # MA 02110-1301, USA. A copy of the GNU General Public License is # also available at http://www.gnu.org/copyleft/gpl.html. from ovirtnode.ovirtfunctions import * +from glob import glob import tempfile import sys @@ -25,12 +26,12 @@ class Network: def __init__(self): OVIRT_VARS = parse_defaults() self.WORKDIR=tempfile.mkdtemp() - self.IFSCRIPTS_PATH ="/etc/sysconfig/network-scripts/" - self.IFCONFIG_FILE_ROOT="/files/etc/sysconfig/network-scripts/ifcfg" - self.NTPCONF_FILE_ROOT="/files/etc/ntp" + self.IFSCRIPTS_PATH ="/etc/sysconfig/network-scripts/ifcfg-" + self.IFCONFIG_FILE_ROOT="/files%s" % self.IFSCRIPTS_PATH self.NTP_CONFIG_FILE="/etc/ntp.conf" self.NTPSERVERS="" - self.CONFIGURED_NIC= "" + self.CONFIGURED_NIC = "" + self.CONFIGURED_NICS = [] self.IF_CONFIG = "" self.BR_CONFIG = "" self.VL_CONFIG = "" @@ -62,13 +63,15 @@ class Network: nic_hwaddr = n_address.readline().strip("\n") n_address.close() BRIDGE = "br" + self.CONFIGURED_NIC + self.CONFIGURED_NICS.append(self.CONFIGURED_NIC) + self.CONFIGURED_NICS.append(BRIDGE) IF_FILENAME = self.WORKDIR + "/augtool-" + self.CONFIGURED_NIC BR_FILENAME = self.WORKDIR + "/augtool-" + BRIDGE log("\nConfigure $BRIDGE for use by $NIC..\n\n") - IF_ROOT = "%s-%s" % (self.IFCONFIG_FILE_ROOT, self.CONFIGURED_NIC) + IF_ROOT = "%s%s" % (self.IFCONFIG_FILE_ROOT, self.CONFIGURED_NIC) self.IF_CONFIG += "rm %s\nset %s/DEVICE %s\n" % (IF_ROOT, IF_ROOT, self.CONFIGURED_NIC) self.IF_CONFIG += "set %s/HWADDR %s\n" % (IF_ROOT, nic_hwaddr) - BR_ROOT = "%s-%s" % (self.IFCONFIG_FILE_ROOT, BRIDGE) + BR_ROOT = "%s%s" % (self.IFCONFIG_FILE_ROOT, BRIDGE) self.BR_CONFIG += "rm %s\nset %s/DEVICE %s\n" % (BR_ROOT, BR_ROOT, BRIDGE) self.BR_CONFIG += "set %s/TYPE Bridge\n" % BR_ROOT self.BR_CONFIG += "set %s/PEERNTP yes\n" % BR_ROOT @@ -96,6 +99,7 @@ class Network: if OVIRT_VARS.has_key("OVIRT_VLAN"): + self.CONFIGURED_NICS.append("%s.%s" % (self.CONFIGURED_NIC, VLAN_ID)) VLAN_ID=OVIRT_VARS["OVIRT_VLAN"] VL_ROOT = "%s.%s" % (IF_ROOT, VLAN_ID) self.VL_CONFIG += "rm %s\n" % VL_ROOT @@ -187,16 +191,17 @@ class Network: log("Configuring network") os.system("ifdown br" + self.CONFIGURED_NIC) for vlan in os.listdir("/proc/net/vlan/"): + # XXX wrong match e.g. eth10.1 with eth1 if self.CONFIGURED_NIC in vlan: os.system("vconfig rem " + vlan + "&> /dev/null") ovirt_safe_delete_config(self.IFSCRIPTS_PATH + vlan) os.system("rm -rf " + self.IFSCRIPTS_PATH + vlan) - for script in os.listdir(self.IFSCRIPTS_PATH): - if self.CONFIGURED_NIC in script: - log("Removing Script: " + script) - ovirt_safe_delete_config("/etc/sysconfig/network-scripts/" + script) - augtool("rm", "/files/etc/sysconfig/network-scripts/ifcfg-br"+self.CONFIGURED_NIC, "") + for script in glob("%s%s*" % (self.IFSCRIPTS_PATH, self.CONFIGURED_NIC)): + # XXX wrong match e.g. eth10 with eth1* (need * to cover VLANs) + log("Removing Script: " + script) + ovirt_safe_delete_config(script) + augtool("rm", self.IFCONFIG_FILE_ROOT+"br"+self.CONFIGURED_NIC, "") for line in self.IF_CONFIG: log(line) @@ -231,15 +236,30 @@ class Network: except: pass + # preserve current MAC mappings for *all physical* network interfaces + for nicdev in glob('/sys/class/net/*/device'): + nic=nicdev.split('/')[4] + if nic != self.CONFIGURED_NIC: + f=open('/sys/class/net/%s/address' % nic) + mac=f.read().strip() + f.close() + if len(mac) > 0: + self.CONFIGURED_NICS.append(nic) + nicroot = "%s%s" % (self.IFCONFIG_FILE_ROOT, nic) + # XXX augtool does save every time! + augtool("set", "%s/DEVICE" % nicroot, nic) + augtool("set", "%s/HWADDR" % nicroot, mac) + augtool("set", "%s/ONBOOT" % nicroot, "no") + net_configured=1 - for i in os.listdir("/etc/sysconfig/network-scripts/"): - if "ifcfg" in i: - ovirt_store_config("/etc/sysconfig/network-scripts/" + i) + for nic in self.CONFIGURED_NICS: + ovirt_store_config("%s%s" % (self.IFSCRIPTS_PATH, nic) ) ovirt_store_config(self.NTP_CONFIG_FILE) log("Network configured successfully") if net_configured == 1: log("\nStopping Network service") os.system("service network stop &> /dev/null") + # XXX eth assumed in breth brctl_cmd = "brctl show|grep breth|awk '{print $1}'" brctl = subprocess.Popen(brctl_cmd, shell=True, stdout=PIPE, stderr=STDOUT) brctl_output = brctl.stdout.read() diff --git a/scripts/ovirt-config-networking b/scripts/ovirt-config-networking index 6ddd805..30c8d2d 100755 --- a/scripts/ovirt-config-networking +++ b/scripts/ovirt-config-networking @@ -21,6 +21,7 @@ NTPCONF_FILE_ROOT="/files/etc/ntp" NTP_CONFIG_FILE="/etc/ntp.conf" NTPSERVERS="" CONFIGURED_NIC="" +CONFIGURED_NICS="" VLAN_ID="" VL_ROOT="" @@ -561,12 +562,14 @@ if ls "$WORKDIR"/augtool-* > /dev/null 2>&1 ; then config="$WORKDIR"/config-augtool cat "$WORKDIR"/augtool-* > $config - # must preserve current eth/MAC mapping for *all* network interfaces, + CONFIGURED_NICS="$CONFIGURED_NIC br$CONFIGURED_NIC" + if [ -n "${VLAN_ID}" ]; then + CONFIGURED_NICS="$CONFIGURED_NICS $CONFIGURED_NIC.$VLAN_ID" + fi + # preserve current MAC mappings for *all physical* network interfaces # to avoid dev$RANDOM rhbz#489927 - # TODO use udev rules to persist network interfaces - for eth in $(ls -d /sys/class/net/eth*|grep -v '\.') ; do - nic=$(basename $eth) - mac=$(cat $eth/address) + for nic in $(ls -d /sys/class/net/*/device|cut -d/ -f5) ; do + mac=$(cat /sys/class/net/$nic/address) if [ -n "$nic" -a -n "$mac" ]; then if_root="$IFCONFIG_FILE_ROOT-$nic" printf "\nset $if_root/DEVICE $nic" >> $config @@ -578,6 +581,7 @@ if ls "$WORKDIR"/augtool-* > /dev/null 2>&1 ; then fi if [ ${CONFIGURED_NIC} != $nic ]; then printf "\nset $if_root/ONBOOT no" >> $config + CONFIGURED_NICS="$CONFIGURED_NICS $nic" fi printf "\nset $if_root/HWADDR $mac" >> $config printf "\n" >> $config @@ -588,9 +592,10 @@ if ls "$WORKDIR"/augtool-* > /dev/null 2>&1 ; then if [ $? = 0 ]; then log "Network configured successfully" net_configured=1 - ovirt_store_config \ - /etc/sysconfig/network-scripts/ifcfg* \ - $NTP_CONFIG_FILE + for nic in $CONFIGURED_NICS; do + ovirt_store_config /etc/sysconfig/network-scripts/ifcfg-$nic + done + ovirt_store_config $NTP_CONFIG_FILE else log "Error configuring network, see $OVIRT_LOGFILE" stop_log @@ -601,6 +606,7 @@ stop_log if [ "$net_configured" = 1 ]; then service network stop > /dev/null 2>&1 + # XXX eth assumed in breth for i in `brctl show | grep breth | awk '{print $1}'` do ifconfig $i down diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions index 6ee3736..fd99bdf 100644 --- a/scripts/ovirt-functions +++ b/scripts/ovirt-functions @@ -23,7 +23,6 @@ OVIRT_BACKUP_DIR=/var/lib/ovirt-backup MANAGEMENT_SCRIPTS_DIR=/etc/node.d OVIRT_CONFIG_FILES="\ - /etc/sysconfig/network-scripts/ifcfg-* \ /etc/rsyslog.conf \ /etc/libvirt/libvirtd.conf \ /etc/sasl2/libvirt.conf \ diff --git a/scripts/ovirtfunctions.py b/scripts/ovirtfunctions.py index ae3c013..0c94363 100644 --- a/scripts/ovirtfunctions.py +++ b/scripts/ovirtfunctions.py @@ -100,19 +100,6 @@ OVIRT_BACKUP_DIR="/var/lib/ovirt-backup" MANAGEMENT_SCRIPTS_DIR="/etc/node.d" -OVIRT_CONFIG_FILES = ["/etc/sysconfig/network-scripts/ifcfg-*", \ - "/etc/rsyslog.conf", \ - "/etc/libvirt/libvirtd.conf", \ - "/etc/sasl2/libvirt.conf", \ - "/etc/libvirt/passwd.db", \ - "/etc/passwd", \ - "/etc/shadow", \ - "/etc/ssh/ssh_host*_key*", \ - "/etc/default/ovirt", \ - "/etc/sysconfig/network", \ - "/etc/collectd.conf", \ - "/etc/logrotate.d/ovirt-logrotate.conf" ] - def log(log_entry): if is_firstboot(): log_file = open(OVIRT_TMP_LOGFILE, "a") -- 1.7.3.4
Seemingly Similar Threads
- [PATCH node] Rerunning network config resets all network config. bz#507393
- Obsoletes previous patch
- [PATCH node] add network.py script
- [PATCH node] REPOST Joey's and Darryl's ovirt-config-* patches
- [PATCH node] Adds vlan support to auto-installations for the node. bz#511056