summaryrefslogtreecommitdiffstats
path: root/cobbler/collection.py
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2007-10-09 13:46:38 -0400
committerMichael DeHaan <mdehaan@redhat.com>2007-10-09 13:46:38 -0400
commit6dce1a9c7d6957ee7a51595de4d0a5bf12dbb3ec (patch)
tree5786b081bc3cbdd13a3ddb2a2c0eda31229234a0 /cobbler/collection.py
parentc86302a23426c3f087dc4b6a1741267e2228cc29 (diff)
downloadthird_party-cobbler-6dce1a9c7d6957ee7a51595de4d0a5bf12dbb3ec.tar.gz
third_party-cobbler-6dce1a9c7d6957ee7a51595de4d0a5bf12dbb3ec.tar.xz
third_party-cobbler-6dce1a9c7d6957ee7a51595de4d0a5bf12dbb3ec.zip
Storing NICs in a hash for easier access + some refactoring + modifications to the find function.
Diffstat (limited to 'cobbler/collection.py')
-rw-r--r--cobbler/collection.py65
1 files changed, 2 insertions, 63 deletions
diff --git a/cobbler/collection.py b/cobbler/collection.py
index 75ce48c..59eebe8 100644
--- a/cobbler/collection.py
+++ b/cobbler/collection.py
@@ -77,69 +77,8 @@ class Collection(serializable.Serializable):
if len(kargs) == 1 and kargs.has_key("name") and not return_list:
return self.listing.get(kargs["name"].lower(), None)
- argument_check_made = False
-
- # for each item in the collection
- for name in self.listing:
-
- # used to flag that this particular object is not a match
- failed = False
- obj = self.listing[name]
- objdata = self.listing[name].to_datastruct()
-
- # make sure that the object being queried actually has
- # the property being queried -- only need to be run once
- # this will ensure the user gets no unexpected false
- # positives
-
- if not argument_check_made:
- fields = objdata.keys()
- for x in kargs.keys():
- if not x in fields:
- ok = False
- # 2nd chance ...
- # also check all of the intefaces, if there are any present...
- if objdata.has_key("interfaces"):
- if len(objdata["interfaces"]) == 0:
- raise CX(_("internal error: interfaces of zero length"))
- for interface in objdata["interfaces"]:
- if interface.has_key(x):
- ok = True
- continue
- # FIXME: something is possibly wrong with this check.
- # disabling for now...
- if not ok:
- raise CX(_("queried object has no field: %s, %s") % (x,objdata))
- argument_check_made = True
-
- # now do the comparision...
- # for each key in the object's data
-
- for key in objdata.keys():
-
- # if the key was specified as an arg to find
- if kargs.has_key(key):
-
- # reject if it doesn't match
- if str(kargs[key]).lower() != str(objdata[key]).lower():
- failed = True
- continue
-
- # now we must also process rejections in the interfaces subobject,
- # if one exists, as that may have other reasons to reject the key.
-
- if objdata.has_key("interfaces"):
- match_ok = False
- for interface in objdata["interfaces"]:
- for key in interface.keys():
- if kargs.has_key(key):
- if str(kargs[key]).lower() != interface[key].lower():
- failed = True
- continue
-
-
- # if no matches failed, this is our item
- if not failed:
+ for (name, obj) in self.listing.iteritems():
+ if obj.find_match(kargs):
matches.append(obj)
if not return_list: