From 32908858c032f91726b02520d11a16d6cff2e93a Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Wed, 13 Jun 2007 15:59:47 -0400 Subject: Lots of work towards profile inheritance. This works in the UI now, with some rough edges (like listing the tree). cobbler profile add --name=profile2 --inherit=profile1 --otherparameters=... cobbler profile edit --name=profile2 --stillmoreparamters=... Data is interleaved for hashes, combined for arrays, and overriden for scalar values. This was heavily inspired by Will-It-Blend, and in this implementation it all blends. Implementation notes -- Updating a parent profile doesn't apply changes to the child objects until a sync, so this seems like a good upgrade for a future commit. Also, the children mapping that makes this possible needs some tweaks because they may load out of order, in which case "cobbler list" can't render a full tree. There are various approaches to deal with this and it should be a (relatively) easy change. --- cobbler/item_system.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'cobbler/item_system.py') diff --git a/cobbler/item_system.py b/cobbler/item_system.py index 9de575e..c2e8243 100644 --- a/cobbler/item_system.py +++ b/cobbler/item_system.py @@ -28,17 +28,21 @@ class System(item.Item): cloned.from_datastruct(ds) return cloned - def clear(self): - self.name = None - self.profile = None # a name, not a reference - self.kernel_options = {} - self.ks_meta = {} - self.ip_address = "" # bad naming here, to the UI, this is usually 'ip-address' - self.mac_address = "" - self.netboot_enabled = 1 - self.hostname = "" + def clear(self,is_subobject=False): + # names of cobbler repo definitions + + self.name = None + self.profile = (None, '<>')[is_subobject] + self.kernel_options = ({}, '<>')[is_subobject] + self.ks_meta = ({}, '<>')[is_subobject] + self.ip_address = ("", '<>')[is_subobject] + self.mac_address = ("", '<>')[is_subobject] + self.netboot_enabled = (1, '<>')[is_subobject] + self.hostname = ("", '<>')[is_subobject] def from_datastruct(self,seed_data): + + self.parent = self.load_item(seed_data, 'parent') self.name = self.load_item(seed_data, 'name') self.profile = self.load_item(seed_data, 'profile') self.kernel_options = self.load_item(seed_data, 'kernel_options') @@ -82,7 +86,10 @@ class System(item.Item): """ Return object next highest up the tree. """ - return self.config.profiles().find(self.profile) + if self.parent is None or self.parent == '': + return self.config.profiles().find(self.profile) + else: + return self.config.systems().find(self.parent) def set_name(self,name): """ @@ -198,6 +205,8 @@ class System(item.Item): """ A system is valid when it contains a valid name and a profile. """ + # NOTE: this validation code does not support inheritable distros at this time. + # this is by design as inheritable systems don't make sense. if self.name is None: return False if self.profile is None: @@ -213,7 +222,8 @@ class System(item.Item): 'ip_address' : self.ip_address, 'netboot_enabled' : self.netboot_enabled, 'hostname' : self.hostname, - 'mac_address' : self.mac_address + 'mac_address' : self.mac_address, + 'parent' : self.parent } def printable(self): -- cgit