summaryrefslogtreecommitdiffstats
path: root/cobbler/item_distro.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2006-05-05 18:30:44 -0400
committerJim Meyering <jim@meyering.net>2006-05-05 18:30:44 -0400
commitc1aea64f02ae55d47c18269895717af99839ed0e (patch)
treebe13cc5c96d135cd8a08fd0794507650a55ad35b /cobbler/item_distro.py
parent3e38df5996d007b4eedc65c4b357502f3e03b604 (diff)
downloadthird_party-cobbler-c1aea64f02ae55d47c18269895717af99839ed0e.tar.gz
third_party-cobbler-c1aea64f02ae55d47c18269895717af99839ed0e.tar.xz
third_party-cobbler-c1aea64f02ae55d47c18269895717af99839ed0e.zip
Interim commit during refactoring. Pretty broken as a result of some cleanup but it will get straightened out very soon. The main thing I'm doing here is to remove backreferences from the object tree and make the API simpler, so that folks using the API screw up less. This means making the CLI code simpler as well. The serializer has also been overhauled so it's not as much bolted on, although I have some fixing to do to make it work entirely correctly. Wanted to check all of this in case someone decided to patch something else, making diffing really complex in the interim. I'd recommend not patching anything else to this code as I'm not close to done, really.
Diffstat (limited to 'cobbler/item_distro.py')
-rw-r--r--cobbler/item_distro.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/cobbler/item_distro.py b/cobbler/item_distro.py
new file mode 100644
index 0000000..1c1a8d4
--- /dev/null
+++ b/cobbler/item_distro.py
@@ -0,0 +1,86 @@
+import utils
+import item
+import weakref
+import os
+
+class Distro(item.Item):
+
+ def __init__(self,config):
+ self.config = config
+ self.clear()
+
+ def clear(self):
+ self.name = None
+ self.kernel = None
+ self.initrd = None
+ self.kernel_options = ""
+
+ def from_datastruct(self,seed_data):
+ self.name = seed_data['name']
+ self.kernel = seed_data['kernel']
+ self.initrd = seed_data['initrd']
+ self.kernel_options = seed_data['kernel_options']
+
+ def set_kernel(self,kernel):
+ """
+ Specifies a kernel. The kernel parameter is a full path, a filename
+ in the configured kernel directory (set in /etc/cobbler.conf) or a
+ directory path that would contain a selectable kernel. Kernel
+ naming conventions are checked, see docs in the utils module
+ for find_kernel.
+ """
+ if utils.find_kernel(kernel):
+ self.kernel = kernel
+ return True
+ utils.set_error("no_kernel")
+ return False
+
+ def set_initrd(self,initrd):
+ """
+ Specifies an initrd image. Path search works as in set_kernel.
+ File must be named appropriately.
+ """
+ if utils.find_initrd(initrd):
+ self.initrd = initrd
+ return True
+ utils.set_error("no_initrd")
+ return False
+
+ def is_valid(self):
+ """
+ A distro requires that the kernel and initrd be set. All
+ other variables are optional.
+ """
+ for x in (self.name,self.kernel,self.initrd):
+ if x is None: return False
+ return True
+
+ def to_datastruct(self):
+ return {
+ 'name': self.name,
+ 'kernel': self.kernel,
+ 'initrd' : self.initrd,
+ 'kernel_options' : self.kernel_options
+ }
+
+ def printable(self):
+ """
+ Human-readable representation.
+ """
+ kstr = utils.find_kernel(self.kernel)
+ istr = utils.find_initrd(self.initrd)
+ if kstr is None:
+ kstr = "%s (NOT FOUND!)" % self.kernel
+ elif os.path.isdir(self.kernel):
+ kstr = "%s (FOUND BY SEARCH)" % kstr
+ if istr is None:
+ istr = "%s (NOT FOUND)" % self.initrd
+ elif os.path.isdir(self.initrd):
+ istr = "%s (FOUND BY SEARCH)" % istr
+ buf = ""
+ buf = buf + "distro : %s\n" % self.name
+ buf = buf + "kernel : %s\n" % kstr
+ buf = buf + "initrd : %s\n" % istr
+ buf = buf + "kernel opts : %s" % self.kernel_options
+ return buf
+