From 62e70a354f497585387adedd613629c29c497a44 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Thu, 20 Aug 2009 18:20:51 -0400 Subject: Reinstate duplicate protection along the lines of what 1.6 offered, should we take a harder line and require alternate fields and such to be provided when using copy/etc ? --- cobbler/item_system.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'cobbler') diff --git a/cobbler/item_system.py b/cobbler/item_system.py index cb1381e0..ed75deab 100644 --- a/cobbler/item_system.py +++ b/cobbler/item_system.py @@ -244,6 +244,15 @@ class System(item.Item): def set_dns_name(self,dns_name,interface): intf = self.__get_interface(interface) + # FIXME: move duplicate supression code to the object validation + # functions to take a harder line on supression? + if not str(self.config._settings.allow_duplicate_hostnames).lower() in [ "1", "y", "yes"]: + matched = self.config.api.find_items("system", {"dns_name" : dns_name}) + for x in matched: + if x.name != self.name: + raise CX("dns-name duplicated: %s" % dns_name) + + intf["dns_name"] = dns_name return True @@ -270,6 +279,16 @@ class System(item.Item): Only works if manage_dhcp is set in /etc/cobbler/settings """ intf = self.__get_interface(interface) + + # FIXME: move duplicate supression code to the object validation + # functions to take a harder line on supression? + if not str(self.config._settings.allow_duplicate_ips).lower() in [ "1", "y", "yes"]: + matched = self.config.api.find_items("system", {"ip_address" : address}) + for x in matched: + if x.name != self.name: + raise CX("IP address duplicated: %s" % address) + + if address == "" or utils.is_ip(address): intf["ip_address"] = address.strip() return True @@ -278,12 +297,22 @@ class System(item.Item): def set_mac_address(self,address,interface): if address == "random": address = utils.get_random_mac(self.config.api) + + # FIXME: move duplicate supression code to the object validation + # functions to take a harder line on supression? + if not str(self.config._settings.allow_duplicate_macs).lower() in [ "1", "y", "yes"]: + matched = self.config.api.find_items("system", {"mac_address" : address}) + for x in matched: + if x.name != self.name: + raise CX("MAC address duplicated: %s" % address) + intf = self.__get_interface(interface) if address == "" or utils.is_mac(address): intf["mac_address"] = address.strip() return True raise CX(_("invalid format for MAC address (%s)" % address)) + def set_gateway(self,gateway): if gateway is None: gateway = "" @@ -498,4 +527,3 @@ class System(item.Item): raise CX("profile is required") - -- cgit