From 8b063147ff16bb9412e15f841c673fdc12d5abdb Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Tue, 9 Oct 2007 18:47:51 -0400 Subject: The stringification problem appears to lie in the serializer, so explicitly use strings in the YAML to pacify the XMLRPC bits. Plus, this is more readable. --- cobbler/item_system.py | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'cobbler/item_system.py') diff --git a/cobbler/item_system.py b/cobbler/item_system.py index 1a77e89..d8412b3 100644 --- a/cobbler/item_system.py +++ b/cobbler/item_system.py @@ -42,9 +42,12 @@ class System(item.Item): self.virt_type = "<>" # use value in profile def __get_interface(self,name): - n = "%s" % name - if not self.interfaces.has_key(n): - self.interfaces[n] = { + + if name not in [ "intf0", "intf1", "intf2", "intf3", "intf4", "intf5", "intf6", "intf7" ]: + raise CX(_("internal error: invalid key for interface lookup or storage, must be 'intfX' where x is 0..7")) + + if not self.interfaces.has_key(name): + self.interfaces[name] = { "mac_address" : "", "ip_address" : "", "dhcp_tag" : "", @@ -53,7 +56,7 @@ class System(item.Item): "hostname" : "", "virt_bridge" : "" } - return self.interfaces[n] + return self.interfaces[name] def from_datastruct(self,seed_data): @@ -88,13 +91,13 @@ class System(item.Item): # before the upgrade if __hostname != "": - self.set_hostname(__hostname, "0") + self.set_hostname(__hostname, "intf0") if __mac_address != "": - self.set_mac_address(__mac_address, "0") + self.set_mac_address(__mac_address, "intf0") if __ip_address != "": - self.set_ip_address(__ip_address, "0") + self.set_ip_address(__ip_address, "intf0") if __dhcp_tag != "": - self.set_dhcp_tag(__dhcp_tag, "0") + self.set_dhcp_tag(__dhcp_tag, "intf0") # backwards compatibility -- convert string entries to dicts for storage # this allows for better usage from the API. @@ -123,7 +126,7 @@ class System(item.Item): Set the name. If the name is a MAC or IP, and the first MAC and/or IP is not defined, go ahead and fill that value in. """ - intf = self.__get_interface("0") + intf = self.__get_interface("intf0") if utils.is_mac(name): if intf["mac_address"] == "": @@ -135,7 +138,7 @@ class System(item.Item): return True - def get_mac_address(self,interface="0"): + def get_mac_address(self,interface="intf0"): """ Get the mac address, which may be implicit in the object name or explicit with --mac-address. Use the explicit location first. @@ -145,12 +148,12 @@ class System(item.Item): intf = self.__get_interface(interface) if intf["mac_address"] != "": return intf["mac_address"] - elif utils.is_mac(self.name) and interface == "0": + elif utils.is_mac(self.name) and interface == "intf0": return self.name else: return None - def get_ip_address(self,interface="0"): + def get_ip_address(self,interface="intf0"): """ Get the IP address, which may be implicit in the object name or explict with --ip-address. Use the explicit location first. @@ -159,12 +162,12 @@ class System(item.Item): intf = self.__get_interface(interface) if intf["ip_address"] != "": return intf["ip_address"] - elif utils.is_ip(self.name) and interface == "0": + elif utils.is_ip(self.name) and interface == "intf0": return self.name else: return None - def is_pxe_supported(self,interface="0"): + def is_pxe_supported(self,interface="intf0"): """ Can only add system PXE records if a MAC or IP address is available, else it's a koan only record. Actually Itanium goes beyond all this and needs the IP all of the time @@ -178,17 +181,17 @@ class System(item.Item): return False return True - def set_dhcp_tag(self,dhcp_tag,interface="0"): + def set_dhcp_tag(self,dhcp_tag,interface="intf0"): intf = self.__get_interface(interface) intf["dhcp_tag"] = dhcp_tag return True - def set_hostname(self,hostname,interface="0"): + def set_hostname(self,hostname,interface="intf0"): intf = self.__get_interface(interface) intf["hostname"] = hostname return True - def set_ip_address(self,address,interface="0"): + def set_ip_address(self,address,interface="intf0"): """ Assign a IP or hostname in DHCP when this MAC boots. Only works if manage_dhcp is set in /var/lib/cobbler/settings @@ -199,24 +202,24 @@ class System(item.Item): return True raise CX(_("invalid format for IP address (%s)") % address) - def set_mac_address(self,address,interface="0"): + def set_mac_address(self,address,interface="intf0"): intf = self.__get_interface(interface) if utils.is_mac(address): intf["mac_address"] = address return True raise CX(_("invalid format for MAC address (%s)" % address)) - def set_gateway(self,gateway,interface="0"): + def set_gateway(self,gateway,interface="intf0"): intf = self.__get_interface(interface) intf["gateway"] = gateway return True - def set_subnet(self,subnet,interface="0"): + def set_subnet(self,subnet,interface="intf0"): intf = self.__get_interface(interface) intf["subnet"] = subnet return True - def set_virt_bridge(self,bridge,interface="0"): + def set_virt_bridge(self,bridge,interface="intf0"): # FIXME: validate intf = self.__get_interface(interface) intf["virt_bridge"] = bridge @@ -343,7 +346,6 @@ class System(item.Item): buf = buf + _(" subnet : %s\n") % x.get("subnet","") buf = buf + _(" virt bridge : %s\n") % x.get("virt_bridge","") buf = buf + _(" dhcp tag : %s\n") % x.get("dhcp_tag","") - # buf = buf + _(" config id : %s\n") % utils.get_config_filename(self,counter) counter = counter + 1 -- cgit