
# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1223330027 25200 # Node ID 66508277e8139993c9fb8bcc0368a77f8f597052 # Parent 311bf6eda3786eb8e47ede06c4da6dc1570aff61 [TEST] Add new enumerate infrastructure... CIM_CimtestClass, EnumNames, EnumInstances, and GetInstance will replace the existing CIM_MyClass, enumerate, enumerate_inst, and getInstance. Since there are a lot of tests to change, the original infrastructure is left in place. This should be removed once the tests are updated to use the new infrastructure. There's a few problems with the existing infrastructure. These replacesments aim to remove these issues: -A new classes require an entry in enumclass.py for each virt type. These changes remove the requirement. -A key_list is a necessary parameter to the enumerate calls. This goes against the extrinsic API definitions - the CIM API does not include an equivallent paremeter for the enumerate calls. -The enumerate() call currently takes a base classname, and a virt type. Really, the just the classname (complete with prefix) should be passed in. This way, SBLIM classes are supported in a more natrual way. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r 311bf6eda378 -r 66508277e813 suites/libvirt-cim/lib/XenKvmLib/enumclass.py --- a/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Sun Oct 05 23:56:40 2008 -0700 +++ b/suites/libvirt-cim/lib/XenKvmLib/enumclass.py Mon Oct 06 14:53:47 2008 -0700 @@ -28,6 +28,8 @@ from XenKvmLib.devices import CIM_Instance from XenKvmLib.classes import get_typed_class from CimTest import Globals, CimExt +from VirtLib import utils +from CimTest.Globals import logger class CIM_MyClass(CIM_Instance): def __init__(self, server, keys): @@ -405,3 +407,86 @@ return None return inst + +class CIM_CimtestClass(CIM_Instance): + def __init__(self, host, ref): + + conn = pywbem.WBEMConnection('http://%s' % host, + (Globals.CIM_USER, Globals.CIM_PASS), + Globals.CIM_NS) + try: + inst = conn.GetInstance(ref) + except pywbem.CIMError, arg: + raise arg + + self.conn = conn + self.inst = inst + self.ref = ref + + CIM_Instance.__init__(self, inst) + + def __invoke(self, method, params): + try: + return self.conn.InvokeMethod(method, + self.ref, + **params) + except pywbem.CIMError, arg: + print 'InvokeMethod(%s): %s' % (method, arg[1]) + raise + + def __getattr__(self, attr): + if self.inst.has_key(attr): + return self.inst[attr] + else: + return CimExt._Method(self.__invoke, attr) + +def EnumNames(host, cn): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstanceName objects.''' + + conn = pywbem.WBEMConnection('http://%s' % host, + (Globals.CIM_USER, Globals.CIM_PASS), + Globals.CIM_NS) + + names = [] + + try: + names = conn.EnumerateInstanceNames(cn) + except pywbem.CIMError, arg: + print arg[1] + return names + + return names + +def EnumInstances(host, cn): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstance objects.''' + + refs = [] + + try: + refs = EnumNames(host, cn) + except pywbem.CIMError, arg: + print arg[1] + + list = [] + + for name in refs: + list.append(CIM_CimtestClass(host, name)) + + return list + +def GetInstance(host, cn, keys): + '''Resolve the enumeration given the @cn. + Return a list of CIMInstance objects.''' + + ref = CIMInstanceName(cn, keybindings=keys) + inst = None + + try: + inst = CIM_CimtestClass(host, ref) + except pywbem.CIMError, arg: + print arg[1] + + return inst +