[Libvirt-cim] [PATCH 2 of 5] [TEST] Add rasd_cn_to_pool_cn() & pool_cn_to_rasd_cn()

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Tue Dec 9 20:24:47 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1228774860 28800
# Node ID 82da8f8250975568ee7030bd7ae1f6298b72ca20
# Parent  625cd6182f62b05bf0292d4174ec13a6682eef3b
[TEST] Add rasd_cn_to_pool_cn() & pool_cn_to_rasd_cn()

Returns the appropriate ResourcePool classname for a given RASD classname.
Add functions to return the enum of RASD and pool classes.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r 625cd6182f62 -r 82da8f825097 suites/libvirt-cim/lib/XenKvmLib/pool.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py	Mon Dec 08 14:21:00 2008 -0800
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+#
+# Copyright 2008 IBM Corp.
+#
+# Authors:
+#    Kaitlin Rupert <karupert at us.ibm.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+#
+
+import sys
+from CimTest.Globals import logger
+from CimTest.ReturnCodes import PASS, FAIL
+from XenKvmLib.classes import get_typed_class
+from XenKvmLib.const import get_provider_version 
+from XenKvmLib.enumclass import EnumInstances
+
+input_graphics_pool_rev = 757
+
+def pool_cn_to_rasd_cn(pool_cn, virt):
+    if pool_cn.find('ProcessorPool') >= 0:
+        return get_typed_class(virt, "ProcResourceAllocationSettingData")
+    elif pool_cn.find('NetworkPool') >= 0:
+        return get_typed_class(virt, "NetResourceAllocationSettingData")
+    elif pool_cn.find('DiskPool') >= 0:
+        return get_typed_class(virt, "DiskResourceAllocationSettingData")
+    elif pool_cn.find('MemoryPool') >= 0:
+        return get_typed_class(virt, "MemResourceAllocationSettingData")
+    elif pool_cn.find('GraphicsPool') >= 0:
+        return get_typed_class(virt, "GraphicsResourceAllocationSettingData")
+    elif pool_cn.find('InputPool') >= 0:
+        return get_typed_class(virt, "InputResourceAllocationSettingData")
+    else:
+        return None
+
+def enum_pools(virt, ip):
+    pool_list = ['ProcessorPool', 'MemoryPool', 'NetworkPool', 'DiskPool']
+
+    curr_cim_rev, changeset = get_provider_version(virt, ip)
+    if curr_cim_rev >= input_graphics_pool_rev:
+        pool_list.append('GraphicsPool')
+        pool_list.append('InputPool')
+
+    pool_insts = {}
+
+    try:
+        for pool in pool_list:
+            pool_cn = get_typed_class(virt, pool)
+            list = EnumInstances(ip, pool_cn)
+
+            if len(list) < 1:
+                raise Exception("%s did not return any instances" % pool_cn)
+
+            for pool in list:
+                if pool.Classname not in pool_insts.keys():
+                    pool_insts[pool.Classname] = []
+                pool_insts[pool.Classname].append(pool)
+
+        if len(pool_insts) != len(pool_list):
+            raise Exception("Got %d pool insts, exp %d" % (len(pool_insts),
+                            len(pool_list)))
+
+    except Exception, details:
+        logger.error(details)
+        return pool_insts, FAIL
+
+    return pool_insts, PASS
+
diff -r 625cd6182f62 -r 82da8f825097 suites/libvirt-cim/lib/XenKvmLib/rasd.py
--- a/suites/libvirt-cim/lib/XenKvmLib/rasd.py	Mon Dec 08 14:21:00 2008 -0800
+++ b/suites/libvirt-cim/lib/XenKvmLib/rasd.py	Mon Dec 08 14:21:00 2008 -0800
@@ -26,7 +26,7 @@
 from XenKvmLib import vxml
 from XenKvmLib import const
 from XenKvmLib.classes import get_typed_class, get_class_type
-from XenKvmLib.enumclass import GetInstance
+from XenKvmLib.enumclass import GetInstance, EnumInstances
 from XenKvmLib.assoc import Associators 
 from XenKvmLib.const import default_pool_name, default_network_name 
 
@@ -264,3 +264,41 @@
 
     return rasd_mofs
 
+def rasd_cn_to_pool_cn(rasd_cn, virt):
+    if rasd_cn.find('ProcResourceAllocationSettingData') >= 0:
+        return get_typed_class(virt, "ProcessorPool")
+    elif rasd_cn.find('NetResourceAllocationSettingData') >= 0:
+        return get_typed_class(virt, "NetworkPool")
+    elif rasd_cn.find('DiskResourceAllocationSettingData') >= 0:
+        return get_typed_class(virt, "DiskPool")
+    elif rasd_cn.find('MemResourceAllocationSettingData') >= 0:
+        return get_typed_class(virt, "MemoryPool")
+    elif rasd_cn.find('GraphicsResourceAllocationSettingData') >= 0:
+        return get_typed_class(virt, "GraphicsPool")
+    elif rasd_cn.find('InputResourceAllocationSettingData') >= 0:
+        return get_typed_class(virt, "InputPool")
+    else:
+        return None 
+
+def enum_rasds(virt, ip):
+    rasd_insts = {}
+
+    try:
+        rasd_cn = get_typed_class(virt, 'ResourceAllocationSettingData')
+        enum_list = EnumInstances(ip, rasd_cn)
+
+        if enum_list < 1:
+            logger.error("No RASD instances returned")
+            return rasd_insts, FAIL
+
+        for rasd in enum_list:
+            if rasd.Classname not in rasd_insts.keys():
+                rasd_insts[rasd.Classname] = []
+            rasd_insts[rasd.Classname].append(rasd)
+
+    except Exception, details:
+        logger.error(details)
+        return rasd_insts, FAIL
+
+    return rasd_insts, PASS
+




More information about the Libvirt-cim mailing list