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