Kaitlin Rupert wrote:
# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1223515128 25200
# Node ID 25b12a8b5257cd983e4926875dc619812fc1ce88
# Parent c2c64b0ee95d55ac09375f0a3518d60fd569ee7d
[TEST] Add get_default_rasds() and get_rasd_templates() to rasd.py
NOTE: This patch only works with recent versions of pywbem (svn checkout of 09/04/2008
or later).
These functions can be used to get the template RASD instances. Instead of building
instances by hand (see default_vssd_rasd_str()), the test cases should be using the
template RASDs provided by the SettingsDefineCapabilities association.
get_rasd_templates() - returns the min, max, increment, and default template RASD
instances for a given AllocationCapabilities instance.
get_default_rasds() - returns just the default template RASD instances for the resource
pools.
Add inst_to_mof() to convert instances to mof format. This is only needed for
libcmpiutil version 0.4 and older.
Add get_default_rasd_mofs() - returns default template RASDs in mof format.
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r c2c64b0ee95d -r 25b12a8b5257 suites/libvirt-cim/lib/XenKvmLib/classes.py
--- a/suites/libvirt-cim/lib/XenKvmLib/classes.py Wed Oct 08 12:59:17 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/classes.py Wed Oct 08 18:18:48 2008 -0700
@@ -44,3 +44,18 @@
return cn[dash_index+1:]
+#FIXME This function is only needed for libcmpiutil versions 0.4 and later.
+#Once version 0.4 is obsolete, this function should be removed.
+def inst_to_mof(inst):
+ mof_str = inst.tomof()
+
+ mof_inst = ""
+
+ for str in mof_str.splitlines():
+ if str.endswith('{') or not str.endswith('NULL;'):
+ mof_inst += "%s\n" % str
+ elif str.endswith('};'):
+ mof_inst += "%s\n" % str
The above two conditions can be combined as follows:
if str.endswith('{') or str.endswith('};') or not
str.endswith('NULL;'):
Because all of them are mutually exclusive and will not occur on the
same line at any given time.
Any one of them is true we need to store the line.
Any specific reason for having separate conditions instead of it having
it in one.
+
+ return mof_inst
+
diff -r c2c64b0ee95d -r 25b12a8b5257 suites/libvirt-cim/lib/XenKvmLib/rasd.py
--- a/suites/libvirt-cim/lib/XenKvmLib/rasd.py Wed Oct 08 12:59:17 2008 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/rasd.py Wed Oct 08 18:18:48 2008 -0700
@@ -24,8 +24,11 @@
from CimTest.Globals import logger
from CimTest.ReturnCodes import FAIL, PASS
from XenKvmLib import vxml
-from XenKvmLib.classes import get_typed_class
-
+from XenKvmLib import const
+from XenKvmLib.classes import get_typed_class, get_class_type
+from XenKvmLib.enumclass import GetInstance
+from XenKvmLib.assoc import Associators
+from XenKvmLib.const import default_pool_name, default_network_name
pasd_cn = 'ProcResourceAllocationSettingData'
nasd_cn = 'NetResourceAllocationSettingData'
@@ -165,3 +168,63 @@
memrasd_list['VirtualQuantity'])
status = FAIL
return status
+
+def get_rasd_templates(host_ip, type, pool_id):
+ ac_cn = get_typed_class(type, "AllocationCapabilities")
+ an_cn = get_typed_class(type, "SettingsDefineCapabilities")
+
+ templates = []
+
+ try:
+ key_list = {"InstanceID" : pool_id }
+
+ inst = GetInstance(host_ip, ac_cn, key_list)
+
+ temps = Associators(host_ip, an_cn, ac_cn, InstanceID=inst.InstanceID)
+
+ for temp in temps:
+ templates.append(temp)
+
+ except Exception, detail:
+ logger.error("Exception: %s", detail)
+
+ return templates
+
+def get_default_rasds(host_ip, type):
+ ac_id_list = [ "MemoryPool/0",
+ "DiskPool/%s" % default_pool_name,
+ ]
+
+ if type == "LXC":
+ if const.LXC_netns_support is True:
+ ac_id_list.append("NetworkPool/%s" % default_network_name)
+ else:
+ ac_id_list.append("NetworkPool/%s" % default_network_name)
+ ac_id_list.append("ProcessorPool/0")
+
+ templates = []
+
+ for id in ac_id_list:
+ rasd_list = get_rasd_templates(host_ip, type, id)
+ if len(rasd_list) < 1:
+ logger.info("No RASD templates returned for %s", id)
+ return []
+
+ for rasd in rasd_list:
+ if rasd['InstanceID'] == "Default":
+ templates.append(rasd)
+
+ return templates
+
+def get_default_rasd_mofs(host_ip, type):
+ rasds = get_default_rasds(ip, virt)
+
+ rasd_mofs = []
+
+ #FIXME for libcmpiutil versions 0.4 and later, inst_to_mof() is needed.
+ #This should be changed to rasd.tomof() once version 0.4 is obsolete.
+ for rasd in rasds:
+ rasd_mofs.append(inst_to_mof(rasd))
+
+ return rasd_mofs
+
_______________________________________________
Libvirt-cim mailing list
Libvirt-cim(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-cim