# HG changeset patch
# User Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
# Date 1253007144 25200
# Node ID df6777d1b6327e85aee0080be2cd7f296a301d36
# Parent 34b2abf04c101dfa45651e201476bb2055b4654c
[TEST] #3 Modified pool.py to support RPCS CreateResourceInPool.
Patch 3:
--------
1) Moved get_sto_vol_rasd() to pool.py as get_sto_vol_rasd_for_pool(),
since it is used in RPCS/13*py and RPCS/14*py
Patch 2:
-------
1) Added check in get_stovol_rasd_from_sdc()
2) Added get_diskpool() to pool.py as it is used in 10*py/11*py, RPCS/12*py
and will be useful for further tests as well
3) Added rev for storagevol deletion
NOTE: Please base this patch on the patch "Modifying common_util.py for netnfs"
Patch 1:
--------
Added the following two functions which are used in RPCS/10*py and RPCS/11*py
1) get_stovol_rasd_from_sdc() to get the stovol rasd from sdc
2) get_stovol_default_settings() to get default sto vol settings
Also, modified common_util.py to remove the backed up exportfs file
Added RAW_VOL_TYPE which is the FormatType supported by RPCS currently
Once this patch gets accepted we can modify RPCS/10*py to refer to these functions.
Tested with KVM and current sources on SLES11.
Signed-off-by: Deepti B. Kalakeri <deeptik(a)linux.vnet.ibm.com>
diff -r 34b2abf04c10 -r df6777d1b632 suites/libvirt-cim/lib/XenKvmLib/common_util.py
--- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py Sun Sep 13 23:46:16 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py Tue Sep 15 02:32:24 2009 -0700
@@ -582,6 +582,8 @@
try:
# Backup the original exports file.
if (os.path.exists(exports_file)):
+ if os.path.exists(back_exports_file):
+ os.remove(back_exports_file)
move_file(exports_file, back_exports_file)
fd = open(exports_file, "w")
line = "\n %s %s(rw)" %(src_dir_for_mnt, server)
diff -r 34b2abf04c10 -r df6777d1b632 suites/libvirt-cim/lib/XenKvmLib/pool.py
--- a/suites/libvirt-cim/lib/XenKvmLib/pool.py Sun Sep 13 23:46:16 2009 -0700
+++ b/suites/libvirt-cim/lib/XenKvmLib/pool.py Tue Sep 15 02:32:24 2009 -0700
@@ -25,7 +25,7 @@
from CimTest.ReturnCodes import PASS, FAIL, SKIP
from XenKvmLib.classes import get_typed_class, inst_to_mof
from XenKvmLib.const import get_provider_version, default_pool_name
-from XenKvmLib.enumclass import EnumInstances, GetInstance
+from XenKvmLib.enumclass import EnumInstances, GetInstance, EnumNames
from XenKvmLib.assoc import Associators
from VirtLib.utils import run_remote
from XenKvmLib.xm_virt_util import virt2uri, net_list
@@ -34,11 +34,13 @@
from CimTest.CimExt import CIMClassMOF
from XenKvmLib.vxml import NetXML, PoolXML
from XenKvmLib.xm_virt_util import virsh_version
+from XenKvmLib.vsms import RASD_TYPE_STOREVOL
cim_errno = pywbem.CIM_ERR_NOT_SUPPORTED
cim_mname = "CreateChildResourcePool"
input_graphics_pool_rev = 757
libvirt_cim_child_pool_rev = 837
+libvirt_rasd_spool_del_changes = 971
DIR_POOL = 1L
FS_POOL = 2L
@@ -48,6 +50,9 @@
LOGICAL_POOL = 6L
SCSI_POOL = 7L
+#Volume types
+RAW_VOL_TYPE = 1
+
def pool_cn_to_rasd_cn(pool_cn, virt):
if pool_cn.find('ProcessorPool') >= 0:
return get_typed_class(virt, "ProcResourceAllocationSettingData")
@@ -297,3 +302,77 @@
status = PASS
return status
+
+def get_stovol_rasd_from_sdc(virt, server, dp_inst_id):
+ rasd = None
+ ac_cn = get_typed_class(virt, "AllocationCapabilities")
+ an_cn = get_typed_class(virt, "SettingsDefineCapabilities")
+ key_list = {"InstanceID" : dp_inst_id}
+
+ try:
+ inst = GetInstance(server, ac_cn, key_list)
+ if inst == None:
+ raise Exception("Failed to GetInstance for %s" % dp_inst_id)
+
+ rasd = Associators(server, an_cn, ac_cn, InstanceID=inst.InstanceID)
+ if len(rasd) < 4:
+ raise Exception("Failed to get default StorageVolRASD , "\
+ "Expected atleast 4, Got '%s'" %
len(rasd))
+
+ except Exception, detail:
+ logger.error("Exception: %s", detail)
+ return FAIL, None
+
+ return PASS, rasd
+
+def get_stovol_default_settings(virt, server, dp_cn,
+ pool_name, path, vol_name):
+
+ dp_inst_id = "%s/%s" % (dp_cn, pool_name)
+ status, dp_rasds = get_stovol_rasd_from_sdc(virt, server, dp_inst_id)
+ if status != PASS:
+ logger.error("Failed to get the StorageVol RASD's")
+ return None
+
+ for dpool_rasd in dp_rasds:
+ if dpool_rasd['ResourceType'] == RASD_TYPE_STOREVOL and \
+ 'Default' in dpool_rasd['InstanceID']:
+
+ dpool_rasd['PoolID'] = dp_inst_id
+ dpool_rasd['Path'] = path
+ dpool_rasd['VolumeName'] = vol_name
+ break
+
+ if not pool_name in dpool_rasd['PoolID']:
+ return None
+
+ return dpool_rasd
+
+def get_diskpool(server, virt, dp_cn, pool_name):
+ dp_inst = None
+ dpool_cn = get_typed_class(virt, dp_cn)
+ pools = EnumNames(server, dpool_cn)
+
+ dp_inst_id = "%s/%s" % (dp_cn, pool_name)
+ for pool in pools:
+ if pool['InstanceID'] == dp_inst_id:
+ dp_inst = pool
+ break
+
+ return dp_inst
+
+def get_sto_vol_rasd_for_pool(virt, server, dp_cn, pool_name, exp_vol_path):
+ dv_rasds = None
+ dp_inst_id = "%s/%s" % (dp_cn, pool_name)
+ status, rasds = get_stovol_rasd_from_sdc(virt, server, dp_inst_id)
+ if status != PASS:
+ logger.error("Failed to get the StorageVol for '%s' vol",
exp_vol_path)
+ return FAIL
+
+ for item in rasds:
+ if item['Address'] == exp_vol_path and item['PoolID'] ==
dp_inst_id:
+ dv_rasds = item
+ break
+
+ return dv_rasds
+