Joey Boggs
2011-Jul-20 20:20 UTC
[Ovirt-devel] [PATCH] fix ipv4 static/dhcp/disabled networking changes
This fixes networking changes when switching from dhcp/static to disabled. Before the ifcfg scripts would contain old values from the previous configuration. Support for disabled devices is now added and some useless remnant bash->python coding cleaned up --- scripts/network.py | 45 +++++++++++++++++++--------------------- scripts/ovirt-config-setup.py | 34 +++++++++++++++++------------- scripts/ovirtfunctions.py | 2 +- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/scripts/network.py b/scripts/network.py index 8159283..8956d00 100644 --- a/scripts/network.py +++ b/scripts/network.py @@ -42,27 +42,21 @@ class Network: def configure_interface(self): log("Configuring Interface") + self.disabled_nic = 0 if OVIRT_VARS.has_key("OVIRT_IP_ADDRESS"): IPADDR = OVIRT_VARS["OVIRT_IP_ADDRESS"] NETMASK = OVIRT_VARS["OVIRT_IP_NETMASK"] GATEWAY = OVIRT_VARS["OVIRT_IP_GATEWAY"] - if OVIRT_VARS.has_key("OVIRT_BOOTIF"): - self.CONFIGURED_NIC = OVIRT_VARS["OVIRT_BOOTIF"] - if not self.CONFIGURED_NIC is None: - log("\nDeleting existing network configuration...\n") - os.system("cp -a /etc/sysconfig/network-scripts/ifcfg-lo /etc/sysconfig/network-scripts/backup.lo") - for file in os.listdir("/etc/sysconfig/network-scripts/"): - if "ifcfg-" in file: - remove_config("/etc/sysconfig/network-scripts/" + file) - os.system("rm -rf /etc/sysconfig/network-scripts/ifcfg-* &>/dev/null") - os.system("cp -a /etc/sysconfig/network-scripts/backup.lo /etc/sysconfig/network-scripts/ifcfg-lo") - else: + if self.CONFIGURED_NIC is None: log("\nAborting...\n") return False - for file in os.listdir(self.WORKDIR): - os.system("rm -rf %s/%s") % (self.WORKDIR, file) + if OVIRT_VARS.has_key("OVIRT_BOOTIF"): + if OVIRT_VARS["OVIRT_BOOTIF"].endswith("-DISABLED"): + self.disabled_nic = 1 + self.CONFIGURED_NIC = OVIRT_VARS["OVIRT_BOOTIF"].strip("-DISABLED") + n_address = open("/sys/class/net/" + self.CONFIGURED_NIC + "/address") nic_hwaddr = n_address.readline().strip("\n") n_address.close() @@ -112,10 +106,14 @@ class Network: if not OVIRT_VARS.has_key("OVIRT_IP_ADDRESS"): - if not self.VL_CONFIG: - self.IF_CONFIG += "set %s/BRIDGE %s\n" % (IF_ROOT, BRIDGE) - self.BR_CONFIG += "set %s/BOOTPROTO dhcp\n" % BR_ROOT - else: + if OVIRT_VARS.has_key("OVIRT_BOOTIF") and self.disabled_nic == 0: + if not self.VL_CONFIG: + self.IF_CONFIG += "set %s/BRIDGE %s\n" % (IF_ROOT, BRIDGE) + self.BR_CONFIG += "set %s/BOOTPROTO dhcp\n" % BR_ROOT + elif self.disabled_nic == 1: + self.BR_CONFIG += "set %s/BOOTPROTO none\n" % BR_ROOT + + elif OVIRT_VARS.has_key("OVIRT_IP_ADDRESS"): if OVIRT_VARS.has_key("OVIRT_IP_ADDRESS") and OVIRT_VARS["OVIRT_IP_ADDRESS"] != "off": self.BR_CONFIG += "set %s/BOOTPROTO static\n" % (BR_ROOT) if self.VL_CONFIG == "": @@ -134,7 +132,6 @@ class Network: self.VL_CONFIG = self_VL_CONFIG.split("\n") except: pass - log("VL_CONFIG: " + self.VL_CONFIG) return True def configure_dns(self): @@ -194,13 +191,12 @@ class Network: # except: # pass # -# for script in os.listdir("/etc/sysconfig/network-scripts/"): -# if "ifcfg" in script: -# if not "ifcfg-lo" in script: -# ovirt_safe_delete_config(script) + for script in os.listdir("/etc/sysconfig/network-scripts/"): + 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, "") - config = self.WORKDIR + "/config-augtool" - for line in self.IF_CONFIG: log(line) try: @@ -209,6 +205,7 @@ class Network: except: oper, file = line.split() augtool(oper, line, "") + for line in self.BR_CONFIG: log(line) try: diff --git a/scripts/ovirt-config-setup.py b/scripts/ovirt-config-setup.py index 6ac09dc..582fad1 100755 --- a/scripts/ovirt-config-setup.py +++ b/scripts/ovirt-config-setup.py @@ -1140,7 +1140,10 @@ class NodeConfigScreen(): def process_nic_config(self): augtool("rm", "/files/" + OVIRT_DEFAULTS + "/OVIRT_BOOTIF", "") - augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_BOOTIF", '"' + self.nic_lb.current() + '"') + if self.disabled_ipv4_nic_proto.value() == 1: + augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_BOOTIF", '"' + self.nic_lb.current() + '-DISABLED"') + else: + augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_BOOTIF", '"' + self.nic_lb.current() + '"') augtool("rm", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_ADDRESS", "") augtool("rm", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_NETMASK", "") augtool("rm", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_GATEWAY", "") @@ -1155,26 +1158,27 @@ class NodeConfigScreen(): msg = " - IPv4 Address\n" if self.ipv4_netdevmask.value() == "": msg += " - IPv4 Netmask Address\n" - if self.ipv6_netdevip.value() == "": - msg = " - IPv6 Address\n" + if self.ipv4_netdevgateway.value() == "": + msg = " - IPv4 Gateway Address\n" + augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_ADDRESS", '"' + self.ipv4_netdevip.value() + '"') + augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_NETMASK", '"' + self.ipv4_netdevmask.value() + '"') + augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_GATEWAY", '"' + self.ipv4_netdevgateway.value() + '"') + if self.static_ipv6_nic_proto.value() == 1: if self.ipv6_netdevmask.value() == "": msg += " - IPv6 Netmask Address\n" if self.ipv6_netdevgateway.value() == "": msg += " - IPv6 Gateway Address\n" # left out gateway check to prevent multiple ones - if msg != "": - msg = "Please Input:\n" + msg - warn = ButtonChoiceWindow(self.screen, "Network Settings", msg, buttons = ['Ok']) - self.__nic_config_failed = 1 - self.ipv4_current_netdevip = self.ipv4_netdevip.value() - self.ipv4_current_netdevmask = self.ipv4_netdevmask.value() - self.ipv4_current_netdevgateway = self.ipv4_netdevgateway.value() - self.reset_screen_colors() - return - augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_ADDRESS", '"' + self.ipv4_netdevip.value() + '"') - augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_NETMASK", '"' + self.ipv4_netdevmask.value() + '"') - augtool("set", "/files/" + OVIRT_DEFAULTS + "/OVIRT_IP_GATEWAY", '"' + self.ipv4_netdevgateway.value() + '"') + if msg != "": + msg = "Please Input:\n" + msg + warn = ButtonChoiceWindow(self.screen, "Network Settings", msg, buttons = ['Ok']) + self.__nic_config_failed = 1 + self.ipv4_current_netdevip = self.ipv4_netdevip.value() + self.ipv4_current_netdevmask = self.ipv4_netdevmask.value() + self.ipv4_current_netdevgateway = self.ipv4_netdevgateway.value() + self.reset_screen_colors() + return else: # if exists remove static keys from dictionary if OVIRT_VARS.has_key("OVIRT_IP_ADDRESS"): diff --git a/scripts/ovirtfunctions.py b/scripts/ovirtfunctions.py index 37aabe7..cdf4b56 100644 --- a/scripts/ovirtfunctions.py +++ b/scripts/ovirtfunctions.py @@ -604,7 +604,7 @@ def remove_config(files): if os.path.exists("/config/files"): if os.path.getsize('/config/files') == 0: print "There are currently no persisted files." - return True + return True if os.path.ismount("/config"): if isinstance(files,STRING_TYPE): files_list = [] -- 1.7.5.4
Apparently Analagous Threads
- [PATCH node] add network.py script
- [PATCH] map nics-> bridges correctly in network pages, when cancelling nic configuration return to network page
- [PATCH] fix ipv6 switch to disabled
- [PATCH node] Adds vlan support to auto-installations for the node. bz#511056
- [PATCH node] First draft of replacing some of the ovirt-config-* scripts with python equivalents.