summaryrefslogtreecommitdiffstats
path: root/cobbler/item_system.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_system.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_system.py')
-rw-r--r--cobbler/item_system.py67
1 files changed, 67 insertions, 0 deletions
diff --git a/cobbler/item_system.py b/cobbler/item_system.py
new file mode 100644
index 0000000..e489e4b
--- /dev/null
+++ b/cobbler/item_system.py
@@ -0,0 +1,67 @@
+import utils
+import item
+
+class System(item.Item):
+
+ def __init__(self,config):
+ self.config = config
+ self.clear()
+
+ def clear(self):
+ self.name = None
+ self.profile = None # a name, not a reference
+ self.kernel_options = ""
+
+ def from_datastruct(self,seed_data):
+ self.name = seed_data['name']
+ self.profile = seed_data['profile']
+ self.kernel_options = seed_data['kernel_options']
+
+ def set_name(self,name):
+ """
+ A name can be a resolvable hostname (it instantly resolved and replaced with the IP),
+ any legal ipv4 address, or any legal mac address. ipv6 is not supported yet but _should_ be.
+ See utils.py
+ """
+ new_name = utils.find_system_identifier(name)
+ if new_name is None or new_name == False:
+ utils.set_error("bad_sys_name")
+ return False
+ self.name = name # we check it add time, but store the original value.
+ return True
+
+ def set_profile(self,profile_name):
+ """
+ Set the system to use a certain named profile. The profile
+ must have already been loaded into the Profiles collection.
+ """
+ if self.config.profiles().find(profile_name):
+ self.profile = profile_name
+ return True
+ return False
+
+ def is_valid(self):
+ """
+ A system is valid when it contains a valid name and a profile.
+ """
+ if self.name is None:
+ utils.set_error("bad_sys_name")
+ return False
+ if self.profile is None:
+ return False
+ return True
+
+ def to_datastruct(self):
+ return {
+ 'name' : self.name,
+ 'profile' : self.profile,
+ 'kernel_options' : self.kernel_options
+ }
+
+ def printable(self):
+ buf = ""
+ buf = buf + "system : %s\n" % self.name
+ buf = buf + "profile : %s\n" % self.profile
+ buf = buf + "kernel opts : %s" % self.kernel_options
+ return buf
+