Discussion:
[Libstoragemgmt-devel] [PATCH 00/10] SMI-S Plugin: Split lsm.Disk methods to smis_disk.py
Gris Ge
2014-09-30 09:22:05 UTC
Permalink
* Move lsm.Disk related codes to smis_disk.py

This patchset is based on master plus these patchset:
* [V2 0/3] Move capablities to separate file
* [PATCH V3 00/10] SMI-S plugin: Reorganize code layout.
* [PATCH 0/7] Move lsm.System related methods to smis_sys.py.
* [PATCH V2 0/8] SMI-S Plugin: Split lsm.Pool related methods from smis.py
to smis_pool.py

Any feedback will be appreciated.

Thank you in advanced.

Gris Ge (10):
SMI-S Plugin: New smis_disk.py file.
SMI-S Plugin: Remove EMC_DISK_STATUS_REMOVED
SMI-S Plugin: Move disk status method to smsi_disk
SMI-S Plugin: Move disk type method to smis_disk
SMI-S Plugin: Remove unused _cim_disk_of_pri_ext()
SMI-S Plugin: Move disk id method to smis_disk.py
SMI-S Plugin: Move cim_disk properties method to smis_disk.
SMI-S Plugin: Move sys_id of disk method to smis_disk
SMI-S Plugin: Move cim_disk to lsm converter to smis_disk.py
SMI-S Plugin: Hide internal methods of smis_disk.

packaging/libstoragemgmt.spec.in | 1 +
plugin/Makefile.am | 3 +-
plugin/smispy/dmtf.py | 39 --------
plugin/smispy/smis.py | 171 ++-------------------------------
plugin/smispy/smis_disk.py | 197 ++++++++++++++++++++++++++++++++++++++
5 files changed, 208 insertions(+), 203 deletions(-)
create mode 100644 plugin/smispy/smis_disk.py
Gris Ge
2014-09-30 09:22:06 UTC
Permalink
* Empty smis_disk.py with license file only.
* Makefile and RPM spec file updated.

Signed-off-by: Gris Ge <***@redhat.com>
---
packaging/libstoragemgmt.spec.in | 1 +
plugin/Makefile.am | 3 ++-
plugin/smispy/smis_disk.py | 16 ++++++++++++++++
3 files changed, 19 insertions(+), 1 deletions(-)
create mode 100644 plugin/smispy/smis_disk.py

diff --git a/packaging/libstoragemgmt.spec.in b/packaging/libstoragemgmt.spec.in
index 5656548..32125ee 100644
--- a/packaging/libstoragemgmt.spec.in
+++ b/packaging/libstoragemgmt.spec.in
@@ -320,6 +320,7 @@ fi
%{python_sitelib}/lsm/plugin/smispy/smis_cap.*
%{python_sitelib}/lsm/plugin/smispy/smis_sys.*
%{python_sitelib}/lsm/plugin/smispy/smis_pool.*
+%{python_sitelib}/lsm/plugin/smispy/smis_disk.*
%{_bindir}/smispy_lsmplugin

%files netapp-plugin
diff --git a/plugin/Makefile.am b/plugin/Makefile.am
index 793fb0b..df8907d 100644
--- a/plugin/Makefile.am
+++ b/plugin/Makefile.am
@@ -31,7 +31,8 @@ smispy_PYTHON = \
smispy/dmtf.py \
smispy/smis_cap.py \
smispy/smis_sys.py \
- smispy/smis_pool.py
+ smispy/smis_pool.py \
+ smispy/smis_disk.py

nstordir = $(plugindir)/nstor
nstor_PYTHON = \
diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
new file mode 100644
index 0000000..e1f46a5
--- /dev/null
+++ b/plugin/smispy/smis_disk.py
@@ -0,0 +1,16 @@
+## Copyright (C) 2014 Red Hat, Inc.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Author: Gris Ge <***@redhat.com>
--
1.7.1
Gris Ge
2014-09-30 09:22:07 UTC
Permalink
* Remove as no method is using EMC_DISK_STATUS_REMOVED constants.

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/dmtf.py | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)

diff --git a/plugin/smispy/dmtf.py b/plugin/smispy/dmtf.py
index c5ea3fe..601c332 100644
--- a/plugin/smispy/dmtf.py
+++ b/plugin/smispy/dmtf.py
@@ -96,8 +96,6 @@ class DMTF(object):
return status, " ".join(status_info_list)


- EMC_DISK_STATUS_REMOVED = 32768
-
_LSM_DISK_OP_STATUS_CONV = {
OP_STATUS_UNKNOWN: Disk.STATUS_UNKNOWN,
OP_STATUS_OK: Disk.STATUS_OK,
--
1.7.1
Gris Ge
2014-09-30 09:22:08 UTC
Permalink
* Replace DMTF.cim_disk_status_of() with smis_disk.disk_status_of_cim_disk()

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/dmtf.py | 21 ---------------------
plugin/smispy/smis.py | 6 ++----
plugin/smispy/smis_disk.py | 28 ++++++++++++++++++++++++++++
3 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/plugin/smispy/dmtf.py b/plugin/smispy/dmtf.py
index 601c332..3afb167 100644
--- a/plugin/smispy/dmtf.py
+++ b/plugin/smispy/dmtf.py
@@ -96,27 +96,6 @@ class DMTF(object):
return status, " ".join(status_info_list)


- _LSM_DISK_OP_STATUS_CONV = {
- OP_STATUS_UNKNOWN: Disk.STATUS_UNKNOWN,
- OP_STATUS_OK: Disk.STATUS_OK,
- OP_STATUS_PREDICTIVE_FAILURE: Disk.STATUS_PREDICTIVE_FAILURE,
- OP_STATUS_ERROR: Disk.STATUS_ERROR,
- OP_STATUS_NON_RECOVERABLE_ERROR: Disk.STATUS_ERROR,
- OP_STATUS_STARTING: Disk.STATUS_STARTING,
- OP_STATUS_STOPPING: Disk.STATUS_STOPPING,
- OP_STATUS_STOPPED: Disk.STATUS_STOPPED,
- }
-
- @staticmethod
- def cim_disk_status_of(dmtf_op_status_list):
- """
- Convert CIM_DiskDrive['OperationalStatus'] to LSM
- Only return status, no status_info
- """
- return DMTF.dmtf_op_status_list_conv(
- DMTF._LSM_DISK_OP_STATUS_CONV, dmtf_op_status_list,
- Disk.STATUS_UNKNOWN, Disk.STATUS_OTHER)[0]
-
# CIM_StorageHardwareID['IDType']
ID_TYPE_OTHER = Uint16(1)
ID_TYPE_WWPN = Uint16(2)
diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 56b2912..d1ebd74 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -32,6 +32,7 @@ from smis_constants import *
import smis_cap
import smis_sys
import smis_pool
+import smis_disk

from lsm import (IStorageAreaNetwork, uri_parse, LsmError, ErrorNumber,
JobStatus, md5, Volume, AccessGroup,
@@ -2179,18 +2180,15 @@ class Smis(IStorageAreaNetwork):
Assuming cim_disk and cim_ext already contained the correct
properties.
"""
- status = Disk.STATUS_UNKNOWN
+ status = smis_disk.disk_status_of_cim_disk(cim_disk)
name = ''
block_size = Disk.BLOCK_SIZE_NOT_FOUND
num_of_block = Disk.BLOCK_COUNT_NOT_FOUND
disk_type = Disk.TYPE_UNKNOWN
- status_info = ''
sys_id = self._sys_id_child(cim_disk)

# These are mandatory
# we do not check whether they follow the SNIA standard.
- if 'OperationalStatus' in cim_disk:
- status = DMTF.cim_disk_status_of(cim_disk['OperationalStatus'])
if 'Name' in cim_disk:
name = cim_disk["Name"]
if 'BlockSize' in cim_ext:
diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
index e1f46a5..3b41ffe 100644
--- a/plugin/smispy/smis_disk.py
+++ b/plugin/smispy/smis_disk.py
@@ -14,3 +14,31 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Author: Gris Ge <***@redhat.com>
+
+from lsm import Disk
+from dmtf import DMTF
+
+
+_LSM_DISK_OP_STATUS_CONV = {
+ DMTF.OP_STATUS_UNKNOWN: Disk.STATUS_UNKNOWN,
+ DMTF.OP_STATUS_OK: Disk.STATUS_OK,
+ DMTF.OP_STATUS_PREDICTIVE_FAILURE: Disk.STATUS_PREDICTIVE_FAILURE,
+ DMTF.OP_STATUS_ERROR: Disk.STATUS_ERROR,
+ DMTF.OP_STATUS_NON_RECOVERABLE_ERROR: Disk.STATUS_ERROR,
+ DMTF.OP_STATUS_STARTING: Disk.STATUS_STARTING,
+ DMTF.OP_STATUS_STOPPING: Disk.STATUS_STOPPING,
+ DMTF.OP_STATUS_STOPPED: Disk.STATUS_STOPPED,
+}
+
+
+def disk_status_of_cim_disk(cim_disk):
+ """
+ Convert CIM_DiskDrive['OperationalStatus'] to LSM
+ Only return status, no status_info
+ """
+ if 'OperationalStatus' not in cim_disk:
+ return Disk.STATUS_UNKNOWN
+
+ return DMTF.dmtf_op_status_list_conv(
+ _LSM_DISK_OP_STATUS_CONV, cim_disk['OperationalStatus'],
+ Disk.STATUS_UNKNOWN, Disk.STATUS_OTHER)[0]
--
1.7.1
Gris Ge
2014-09-30 09:22:09 UTC
Permalink
* Replace dmtf.dmtf_disk_type_2_lsm_disk_type() with
smis_disk.dmtf_disk_type_2_lsm_disk_type()

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/dmtf.py | 16 ----------------
plugin/smispy/smis.py | 4 ++--
plugin/smispy/smis_disk.py | 20 +++++++++++++++++++-
3 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/plugin/smispy/dmtf.py b/plugin/smispy/dmtf.py
index 3afb167..8ebf06a 100644
--- a/plugin/smispy/dmtf.py
+++ b/plugin/smispy/dmtf.py
@@ -187,22 +187,6 @@ DMTF_DISK_TYPE_HDD = 2
DMTF_DISK_TYPE_SSD = 3
DMTF_DISK_TYPE_HYBRID = 4

-_DMTF_DISK_TYPE_2_LSM = {
- DMTF_DISK_TYPE_UNKNOWN: Disk.TYPE_UNKNOWN,
- DMTF_DISK_TYPE_OTHER: Disk.TYPE_OTHER,
- DMTF_DISK_TYPE_HDD: Disk.TYPE_HDD,
- DMTF_DISK_TYPE_SSD: Disk.TYPE_SSD,
- DMTF_DISK_TYPE_HYBRID: Disk.TYPE_HYBRID,
-}
-
-
-def dmtf_disk_type_2_lsm_disk_type(dmtf_disk_type):
- if dmtf_disk_type in _DMTF_DISK_TYPE_2_LSM.keys():
- return _DMTF_DISK_TYPE_2_LSM[dmtf_disk_type]
- else:
- return Disk.TYPE_UNKNOWN
-
-
DMTF_STATUS_UNKNOWN = 0
DMTF_STATUS_OTHER = 1
DMTF_STATUS_OK = 2
diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index d1ebd74..3d70e6f 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -2207,8 +2207,8 @@ class Smis(IStorageAreaNetwork):
disk_type = Disk.TYPE_NL_SAS

if disk_type == Disk.TYPE_UNKNOWN and 'DiskType' in cim_disk:
- disk_type = \
- dmtf_disk_type_2_lsm_disk_type(cim_disk['DiskType'])
+ disk_type = smis_disk.dmtf_disk_type_2_lsm_disk_type(
+ cim_disk['DiskType'])

# LSI way for checking disk type
if not disk_type and cim_disk.classname == 'LSIESG_DiskDrive':
diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
index 3b41ffe..38f4ca6 100644
--- a/plugin/smispy/smis_disk.py
+++ b/plugin/smispy/smis_disk.py
@@ -16,7 +16,9 @@
# Author: Gris Ge <***@redhat.com>

from lsm import Disk
-from dmtf import DMTF
+from dmtf import (
+ DMTF, DMTF_DISK_TYPE_UNKNOWN, DMTF_DISK_TYPE_OTHER,
+ DMTF_DISK_TYPE_HDD, DMTF_DISK_TYPE_SSD, DMTF_DISK_TYPE_HYBRID)


_LSM_DISK_OP_STATUS_CONV = {
@@ -42,3 +44,19 @@ def disk_status_of_cim_disk(cim_disk):
return DMTF.dmtf_op_status_list_conv(
_LSM_DISK_OP_STATUS_CONV, cim_disk['OperationalStatus'],
Disk.STATUS_UNKNOWN, Disk.STATUS_OTHER)[0]
+
+
+_DMTF_DISK_TYPE_2_LSM = {
+ DMTF_DISK_TYPE_UNKNOWN: Disk.TYPE_UNKNOWN,
+ DMTF_DISK_TYPE_OTHER: Disk.TYPE_OTHER,
+ DMTF_DISK_TYPE_HDD: Disk.TYPE_HDD,
+ DMTF_DISK_TYPE_SSD: Disk.TYPE_SSD,
+ DMTF_DISK_TYPE_HYBRID: Disk.TYPE_HYBRID,
+}
+
+
+def dmtf_disk_type_2_lsm_disk_type(dmtf_disk_type):
+ if dmtf_disk_type in _DMTF_DISK_TYPE_2_LSM.keys():
+ return _DMTF_DISK_TYPE_2_LSM[dmtf_disk_type]
+ else:
+ return Disk.TYPE_UNKNOWN
--
1.7.1
Gris Ge
2014-09-30 09:22:11 UTC
Permalink
* Replace Smis._disk_id() with smis_disk.disk_id_of_cim_disk()

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/smis.py | 10 +++-------
plugin/smispy/smis_disk.py | 14 +++++++++++++-
2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 59d102a..1673b4c 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -424,12 +424,6 @@ class Smis(IStorageAreaNetwork):
"""
return self._id('Volume', cim_vol)

- def _disk_id(self, cim_disk):
- """
- Return the MD5 hash of CIM_DiskDrive['SystemName'] and ['DeviceID']
- """
- return self._id('Disk', cim_disk)
-
def _job_id(self, cim_job, retrieve_data):
"""
Return the MD5 has of CIM_ConcreteJob['InstanceID'] in conjunction
@@ -2225,7 +2219,9 @@ class Smis(IStorageAreaNetwork):
if ccn == 'LSIESG_TargetSASProtocolEndpoint':
disk_type = Disk.TYPE_SAS

- new_disk = Disk(self._disk_id(cim_disk), name, disk_type, block_size,
+ disk_id = smis_disk.disk_id_of_cim_disk(cim_disk)
+
+ new_disk = Disk(disk_id, name, disk_type, block_size,
num_of_block, status, sys_id)

return new_disk
diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
index 38f4ca6..10192a4 100644
--- a/plugin/smispy/smis_disk.py
+++ b/plugin/smispy/smis_disk.py
@@ -15,7 +15,7 @@
#
# Author: Gris Ge <***@redhat.com>

-from lsm import Disk
+from lsm import Disk, md5, LsmError, ErrorNumber
from dmtf import (
DMTF, DMTF_DISK_TYPE_UNKNOWN, DMTF_DISK_TYPE_OTHER,
DMTF_DISK_TYPE_HDD, DMTF_DISK_TYPE_SSD, DMTF_DISK_TYPE_HYBRID)
@@ -60,3 +60,15 @@ def dmtf_disk_type_2_lsm_disk_type(dmtf_disk_type):
return _DMTF_DISK_TYPE_2_LSM[dmtf_disk_type]
else:
return Disk.TYPE_UNKNOWN
+
+
+def disk_id_of_cim_disk(cim_disk):
+ if 'SystemName' not in cim_disk or \
+ 'DeviceID' not in cim_disk:
+ raise LsmError(
+ ErrorNumber.PLUGIN_BUG,
+ "disk_id_of_cim_disk(): Got cim_disk with no "
+ "SystemName or DeviceID property: %s, %s" %
+ (cim_disk.path, cim_disk.items()))
+
+ return md5("%s%s" % (cim_disk['SystemName'], cim_disk['DeviceID']))
--
1.7.1
Gris Ge
2014-09-30 09:22:10 UTC
Permalink
* Remove unused method Smis._cim_disk_of_pri_ext()

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/smis.py | 29 -----------------------------
1 files changed, 0 insertions(+), 29 deletions(-)

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 3d70e6f..59d102a 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -2272,35 +2272,6 @@ class Smis(IStorageAreaNetwork):
"CIM_StorageExtent for CIM_DiskDrive %s " %
cim_disk_path)

- def _cim_disk_of_pri_ext(self, cim_pri_ext_path, pros_list=None):
- """
- Follow this procedure to find out CIM_DiskDrive from Primordial
- CIM_StorageExtent:
- CIM_StorageExtent (Primordial)
- ^
- |
- | CIM_MediaPresent
- |
- v
- CIM_DiskDrive
- """
- if pros_list is None:
- pros_list = []
- cim_disks = self._c.Associators(
- cim_pri_ext_path,
- AssocClass='CIM_MediaPresent',
- ResultClass='CIM_DiskDrive',
- PropertyList=pros_list)
- if len(cim_disks) == 1:
- return cim_disks[0]
- elif len(cim_disks) == 2:
- return None
- else:
- raise LsmError(ErrorNumber.PLUGIN_BUG,
- "Found two or more CIM_DiskDrive associated to " +
- "requested CIM_StorageExtent %s" %
- cim_pri_ext_path)
-
@staticmethod
def _is_frontend_fc_tgt(cim_fc_tgt):
"""
--
1.7.1
Gris Ge
2014-09-30 09:22:12 UTC
Permalink
* Replace Smis._new_disk_cim_disk_pros() with
smis_disk.cim_disk_pros()

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/smis.py | 11 +----------
plugin/smispy/smis_disk.py | 8 ++++++++
2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 1673b4c..133ac03 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -2137,7 +2137,7 @@ class Smis(IStorageAreaNetwork):
self._c.profile_check(SmisCommon.SNIA_DISK_LITE_PROFILE,
SmisCommon.SMIS_SPEC_VER_1_4,
raise_error=True)
- cim_disk_pros = Smis._new_disk_cim_disk_pros(flags)
+ cim_disk_pros = smis_disk.cim_disk_pros()
cim_disks = self._c.EnumerateInstances(
'CIM_DiskDrive', PropertyList=cim_disk_pros)
for cim_disk in cim_disks:
@@ -2152,15 +2152,6 @@ class Smis(IStorageAreaNetwork):
return search_property(rc, search_key, search_value)

@staticmethod
- def _new_disk_cim_disk_pros(flag=0):
- """
- Return all CIM_DiskDrive Properties needed to create a Disk object.
- """
- pros = ['OperationalStatus', 'Name', 'SystemName',
- 'Caption', 'InterconnectType', 'DiskType']
- return pros
-
- @staticmethod
def _new_disk_cim_ext_pros(flag=0):
"""
Return all CIM_StorageExtent Properties needed to create a Disk
diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
index 10192a4..be15de5 100644
--- a/plugin/smispy/smis_disk.py
+++ b/plugin/smispy/smis_disk.py
@@ -72,3 +72,11 @@ def disk_id_of_cim_disk(cim_disk):
(cim_disk.path, cim_disk.items()))

return md5("%s%s" % (cim_disk['SystemName'], cim_disk['DeviceID']))
+
+
+def cim_disk_pros():
+ """
+ Return all CIM_DiskDrive Properties needed to create a Disk object.
+ """
+ return ['OperationalStatus', 'Name', 'SystemName',
+ 'Caption', 'InterconnectType', 'DiskType']
--
1.7.1
Gris Ge
2014-09-30 09:22:13 UTC
Permalink
* Replace Smis._sys_id_child(cim_disk) with
smis_disk.sys_id_of_cim_disk(cim_disk)

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/smis.py | 9 +++++----
plugin/smispy/smis_disk.py | 10 ++++++++++
2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 133ac03..af20310 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -2141,9 +2141,10 @@ class Smis(IStorageAreaNetwork):
cim_disks = self._c.EnumerateInstances(
'CIM_DiskDrive', PropertyList=cim_disk_pros)
for cim_disk in cim_disks:
- if self._c.system_list:
- if self._sys_id_child(cim_disk) not in self._c.system_list:
- continue
+ if self._c.system_list and \
+ smis_disk.sys_id_of_cim_disk(cim_disk) not in \
+ self._c.system_list:
+ continue
cim_ext_pros = Smis._new_disk_cim_ext_pros(flags)
cim_ext = self._pri_cim_ext_of_cim_disk(cim_disk.path,
cim_ext_pros)
@@ -2170,7 +2171,7 @@ class Smis(IStorageAreaNetwork):
block_size = Disk.BLOCK_SIZE_NOT_FOUND
num_of_block = Disk.BLOCK_COUNT_NOT_FOUND
disk_type = Disk.TYPE_UNKNOWN
- sys_id = self._sys_id_child(cim_disk)
+ sys_id = smis_disk.sys_id_of_cim_sys(cim_disk)

# These are mandatory
# we do not check whether they follow the SNIA standard.
diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
index be15de5..7364f7f 100644
--- a/plugin/smispy/smis_disk.py
+++ b/plugin/smispy/smis_disk.py
@@ -80,3 +80,13 @@ def cim_disk_pros():
"""
return ['OperationalStatus', 'Name', 'SystemName',
'Caption', 'InterconnectType', 'DiskType']
+
+
+def sys_id_of_cim_disk(cim_disk):
+ if 'SystemName' not in cim_disk:
+ raise LsmError(
+ ErrorNumber.PLUGIN_BUG,
+ "sys_id_of_cim_disk(): Got cim_disk with no "
+ "SystemName property: %s, %s" %
+ (cim_disk.path, cim_disk.items()))
+ return cim_disk['SystemName']
--
1.7.1
Gris Ge
2014-09-30 09:22:14 UTC
Permalink
* Replace Smis._new_disk() with smis_disk.cim_disk_to_lsm_disk()
* Moved Smis._pri_cim_ext_of_cim_disk() into smis_disk.
* Merged Smis._new_disk_cim_ext_pros() into smis_disk.cim_disk_to_lsm_disk()
as no need to has a method for storing a non-shared list.
* Combining these changes in one patch as they are internal actions for
smis_disk.cim_disk_to_lsm_disk().

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/smis.py | 114 +-------------------------------------------
plugin/smispy/smis_disk.py | 107 ++++++++++++++++++++++++++++++++++++++++-
2 files changed, 107 insertions(+), 114 deletions(-)

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index af20310..351de57 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -2125,7 +2125,6 @@ class Smis(IStorageAreaNetwork):
return all object of data.Disk.
We are using "Disk Drive Lite Subprofile" v1.4 of SNIA SMI-S for these
classes to create LSM Disk:
- CIM_PhysicalPackage
CIM_DiskDrive
CIM_StorageExtent (Primordial)
Due to 'Multiple Computer System' profile, disks might associated to
@@ -2145,122 +2144,11 @@ class Smis(IStorageAreaNetwork):
smis_disk.sys_id_of_cim_disk(cim_disk) not in \
self._c.system_list:
continue
- cim_ext_pros = Smis._new_disk_cim_ext_pros(flags)
- cim_ext = self._pri_cim_ext_of_cim_disk(cim_disk.path,
- cim_ext_pros)

- rc.extend([self._new_disk(cim_disk, cim_ext)])
+ rc.extend([smis_disk.cim_disk_to_lsm_disk(self._c, cim_disk)])
return search_property(rc, search_key, search_value)

@staticmethod
- def _new_disk_cim_ext_pros(flag=0):
- """
- Return all CIM_StorageExtent Properties needed to create a Disk
- object.
- """
- return ['BlockSize', 'NumberOfBlocks']
-
- def _new_disk(self, cim_disk, cim_ext):
- """
- Takes a CIM_DiskDrive and CIM_StorageExtent, returns a lsm Disk
- Assuming cim_disk and cim_ext already contained the correct
- properties.
- """
- status = smis_disk.disk_status_of_cim_disk(cim_disk)
- name = ''
- block_size = Disk.BLOCK_SIZE_NOT_FOUND
- num_of_block = Disk.BLOCK_COUNT_NOT_FOUND
- disk_type = Disk.TYPE_UNKNOWN
- sys_id = smis_disk.sys_id_of_cim_sys(cim_disk)
-
- # These are mandatory
- # we do not check whether they follow the SNIA standard.
- if 'Name' in cim_disk:
- name = cim_disk["Name"]
- if 'BlockSize' in cim_ext:
- block_size = cim_ext['BlockSize']
- if 'NumberOfBlocks' in cim_ext:
- num_of_block = cim_ext['NumberOfBlocks']
-
- # SNIA SMI-S 1.4 or even 1.6 does not define anyway to find out disk
- # type.
- # Currently, EMC is following DMTF define to do so.
- if 'InterconnectType' in cim_disk: # DMTF 2.31 CIM_DiskDrive
- disk_type = cim_disk['InterconnectType']
- if 'Caption' in cim_disk:
- # EMC VNX introduced NL_SAS disk.
- if cim_disk['Caption'] == 'NL_SAS':
- disk_type = Disk.TYPE_NL_SAS
-
- if disk_type == Disk.TYPE_UNKNOWN and 'DiskType' in cim_disk:
- disk_type = smis_disk.dmtf_disk_type_2_lsm_disk_type(
- cim_disk['DiskType'])
-
- # LSI way for checking disk type
- if not disk_type and cim_disk.classname == 'LSIESG_DiskDrive':
- cim_pes = self._c.Associators(
- cim_disk.path,
- AssocClass='CIM_SAPAvailableForElement',
- ResultClass='CIM_ProtocolEndpoint',
- PropertyList=['CreationClassName'])
- if cim_pes and cim_pes[0]:
- if 'CreationClassName' in cim_pes[0]:
- ccn = cim_pes[0]['CreationClassName']
- if ccn == 'LSIESG_TargetSATAProtocolEndpoint':
- disk_type = Disk.TYPE_SATA
- if ccn == 'LSIESG_TargetSASProtocolEndpoint':
- disk_type = Disk.TYPE_SAS
-
- disk_id = smis_disk.disk_id_of_cim_disk(cim_disk)
-
- new_disk = Disk(disk_id, name, disk_type, block_size,
- num_of_block, status, sys_id)
-
- return new_disk
-
- def _pri_cim_ext_of_cim_disk(self, cim_disk_path, property_list=None):
- """
- Usage:
- Find out the Primordial CIM_StorageExtent of CIM_DiskDrive
- In SNIA SMI-S 1.4 rev.6 Block book, section 11.1.1 'Base Model'
- quote:
- A disk drive is modeled as a single MediaAccessDevice (DiskDrive)
- That shall be linked to a single StorageExtent (representing the
- storage in the drive) by a MediaPresent association. The
- StorageExtent class represents the storage of the drive and
- contains its size.
- Parameter:
- cim_disk_path # CIM_InstanceName of CIM_DiskDrive
- property_list # a List of properties needed on returned
- # CIM_StorageExtent
- Returns:
- cim_pri_ext # The CIM_Instance of Primordial CIM_StorageExtent
- Exceptions:
- LsmError
- ErrorNumber.LSM_PLUGIN_BUG # Failed to find out pri cim_ext
- """
- if property_list is None:
- property_list = ['Primordial']
- else:
- property_list = merge_list(property_list, ['Primordial'])
-
- cim_exts = self._c.Associators(
- cim_disk_path,
- AssocClass='CIM_MediaPresent',
- ResultClass='CIM_StorageExtent',
- PropertyList=property_list)
- cim_exts = [p for p in cim_exts if p["Primordial"]]
- if cim_exts and cim_exts[0]:
- # As SNIA commanded, only _ONE_ Primordial CIM_StorageExtent for
- # each CIM_DiskDrive
- return cim_exts[0]
- else:
- raise LsmError(ErrorNumber.PLUGIN_BUG,
- "Failed to find out Primordial " +
- "CIM_StorageExtent for CIM_DiskDrive %s " %
- cim_disk_path)
-
- @staticmethod
def _is_frontend_fc_tgt(cim_fc_tgt):
"""
Check CIM_FCPort['UsageRestriction'] for frontend port.
diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
index 7364f7f..4245a5b 100644
--- a/plugin/smispy/smis_disk.py
+++ b/plugin/smispy/smis_disk.py
@@ -19,6 +19,7 @@ from lsm import Disk, md5, LsmError, ErrorNumber
from dmtf import (
DMTF, DMTF_DISK_TYPE_UNKNOWN, DMTF_DISK_TYPE_OTHER,
DMTF_DISK_TYPE_HDD, DMTF_DISK_TYPE_SSD, DMTF_DISK_TYPE_HYBRID)
+from utils import merge_list


_LSM_DISK_OP_STATUS_CONV = {
@@ -79,7 +80,7 @@ def cim_disk_pros():
Return all CIM_DiskDrive Properties needed to create a Disk object.
"""
return ['OperationalStatus', 'Name', 'SystemName',
- 'Caption', 'InterconnectType', 'DiskType']
+ 'Caption', 'InterconnectType', 'DiskType', 'DeviceID']


def sys_id_of_cim_disk(cim_disk):
@@ -90,3 +91,107 @@ def sys_id_of_cim_disk(cim_disk):
"SystemName property: %s, %s" %
(cim_disk.path, cim_disk.items()))
return cim_disk['SystemName']
+
+
+def _pri_cim_ext_of_cim_disk(smis_common, cim_disk_path, property_list=None):
+ """
+ Usage:
+ Find out the Primordial CIM_StorageExtent of CIM_DiskDrive
+ In SNIA SMI-S 1.4 rev.6 Block book, section 11.1.1 'Base Model'
+ quote:
+ A disk drive is modeled as a single MediaAccessDevice (DiskDrive)
+ That shall be linked to a single StorageExtent (representing the
+ storage in the drive) by a MediaPresent association. The
+ StorageExtent class represents the storage of the drive and
+ contains its size.
+ Parameter:
+ cim_disk_path # CIM_InstanceName of CIM_DiskDrive
+ property_list # a List of properties needed on returned
+ # CIM_StorageExtent
+ Returns:
+ cim_pri_ext # The CIM_Instance of Primordial CIM_StorageExtent
+ Exceptions:
+ LsmError
+ ErrorNumber.LSM_PLUGIN_BUG # Failed to find out pri cim_ext
+ """
+ if property_list is None:
+ property_list = ['Primordial']
+ else:
+ property_list = merge_list(property_list, ['Primordial'])
+
+ cim_exts = smis_common.Associators(
+ cim_disk_path,
+ AssocClass='CIM_MediaPresent',
+ ResultClass='CIM_StorageExtent',
+ PropertyList=property_list)
+ cim_exts = [p for p in cim_exts if p["Primordial"]]
+ if len(cim_exts) == 1:
+ # As SNIA commanded, only _ONE_ Primordial CIM_StorageExtent for
+ # each CIM_DiskDrive
+ return cim_exts[0]
+ else:
+ raise LsmError(ErrorNumber.PLUGIN_BUG,
+ "_pri_cim_ext_of_cim_disk(): "
+ "Got unexpected count of Primordial " +
+ "CIM_StorageExtent for CIM_DiskDrive: %s, %s " %
+ (cim_disk_path, cim_exts))
+
+
+def cim_disk_to_lsm_disk(smis_common, cim_disk):
+ """
+ Convert CIM_DiskDrive to lsm.Disk.
+ """
+ # CIM_DiskDrive does not have disk size information.
+ # We have to find out the Primodial CIM_StorageExtent for that.
+ cim_ext = _pri_cim_ext_of_cim_disk(
+ smis_common, cim_disk.path,
+ property_list=['BlockSize', 'NumberOfBlocks'])
+
+ status = disk_status_of_cim_disk(cim_disk)
+ name = ''
+ block_size = Disk.BLOCK_SIZE_NOT_FOUND
+ num_of_block = Disk.BLOCK_COUNT_NOT_FOUND
+ disk_type = Disk.TYPE_UNKNOWN
+ sys_id = sys_id_of_cim_disk(cim_disk)
+
+ # These are mandatory
+ # we do not check whether they follow the SNIA standard.
+ if 'Name' in cim_disk:
+ name = cim_disk["Name"]
+ if 'BlockSize' in cim_ext:
+ block_size = cim_ext['BlockSize']
+ if 'NumberOfBlocks' in cim_ext:
+ num_of_block = cim_ext['NumberOfBlocks']
+
+ # SNIA SMI-S 1.4 or even 1.6 does not define anyway to find out disk
+ # type.
+ # Currently, EMC is following DMTF define to do so.
+ if 'InterconnectType' in cim_disk: # DMTF 2.31 CIM_DiskDrive
+ disk_type = cim_disk['InterconnectType']
+ if 'Caption' in cim_disk:
+ # EMC VNX introduced NL_SAS disk.
+ if cim_disk['Caption'] == 'NL_SAS':
+ disk_type = Disk.TYPE_NL_SAS
+
+ if disk_type == Disk.TYPE_UNKNOWN and 'DiskType' in cim_disk:
+ disk_type = dmtf_disk_type_2_lsm_disk_type(cim_disk['DiskType'])
+
+ # LSI way for checking disk type
+ if not disk_type and cim_disk.classname == 'LSIESG_DiskDrive':
+ cim_pes = smis_common.Associators(
+ cim_disk.path,
+ AssocClass='CIM_SAPAvailableForElement',
+ ResultClass='CIM_ProtocolEndpoint',
+ PropertyList=['CreationClassName'])
+ if cim_pes and cim_pes[0]:
+ if 'CreationClassName' in cim_pes[0]:
+ ccn = cim_pes[0]['CreationClassName']
+ if ccn == 'LSIESG_TargetSATAProtocolEndpoint':
+ disk_type = Disk.TYPE_SATA
+ if ccn == 'LSIESG_TargetSASProtocolEndpoint':
+ disk_type = Disk.TYPE_SAS
+
+ disk_id = disk_id_of_cim_disk(cim_disk)
+
+ return Disk(disk_id, name, disk_type, block_size, num_of_block, status,
+ sys_id)
--
1.7.1
Gris Ge
2014-09-30 09:22:15 UTC
Permalink
* Hide these internal methods of smis_disk:
smis_disk.disk_id_of_cim_disk()
-> smis_disk._disk_id_of_cim_disk()
smis_disk.dmtf_disk_type_2_lsm_disk_type()
-> smis_disk._dmtf_disk_type_2_lsm_disk_type()
smis_disk.disk_status_of_cim_disk()
-> smis_disk._disk_status_of_cim_disk()

Signed-off-by: Gris Ge <***@redhat.com>
---
plugin/smispy/smis_disk.py | 14 +++++++-------
1 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/plugin/smispy/smis_disk.py b/plugin/smispy/smis_disk.py
index 4245a5b..01de3db 100644
--- a/plugin/smispy/smis_disk.py
+++ b/plugin/smispy/smis_disk.py
@@ -34,7 +34,7 @@ _LSM_DISK_OP_STATUS_CONV = {
}


-def disk_status_of_cim_disk(cim_disk):
+def _disk_status_of_cim_disk(cim_disk):
"""
Convert CIM_DiskDrive['OperationalStatus'] to LSM
Only return status, no status_info
@@ -56,19 +56,19 @@ _DMTF_DISK_TYPE_2_LSM = {
}


-def dmtf_disk_type_2_lsm_disk_type(dmtf_disk_type):
+def _dmtf_disk_type_2_lsm_disk_type(dmtf_disk_type):
if dmtf_disk_type in _DMTF_DISK_TYPE_2_LSM.keys():
return _DMTF_DISK_TYPE_2_LSM[dmtf_disk_type]
else:
return Disk.TYPE_UNKNOWN


-def disk_id_of_cim_disk(cim_disk):
+def _disk_id_of_cim_disk(cim_disk):
if 'SystemName' not in cim_disk or \
'DeviceID' not in cim_disk:
raise LsmError(
ErrorNumber.PLUGIN_BUG,
- "disk_id_of_cim_disk(): Got cim_disk with no "
+ "_disk_id_of_cim_disk(): Got cim_disk with no "
"SystemName or DeviceID property: %s, %s" %
(cim_disk.path, cim_disk.items()))

@@ -147,7 +147,7 @@ def cim_disk_to_lsm_disk(smis_common, cim_disk):
smis_common, cim_disk.path,
property_list=['BlockSize', 'NumberOfBlocks'])

- status = disk_status_of_cim_disk(cim_disk)
+ status = _disk_status_of_cim_disk(cim_disk)
name = ''
block_size = Disk.BLOCK_SIZE_NOT_FOUND
num_of_block = Disk.BLOCK_COUNT_NOT_FOUND
@@ -174,7 +174,7 @@ def cim_disk_to_lsm_disk(smis_common, cim_disk):
disk_type = Disk.TYPE_NL_SAS

if disk_type == Disk.TYPE_UNKNOWN and 'DiskType' in cim_disk:
- disk_type = dmtf_disk_type_2_lsm_disk_type(cim_disk['DiskType'])
+ disk_type = _dmtf_disk_type_2_lsm_disk_type(cim_disk['DiskType'])

# LSI way for checking disk type
if not disk_type and cim_disk.classname == 'LSIESG_DiskDrive':
@@ -191,7 +191,7 @@ def cim_disk_to_lsm_disk(smis_common, cim_disk):
if ccn == 'LSIESG_TargetSASProtocolEndpoint':
disk_type = Disk.TYPE_SAS

- disk_id = disk_id_of_cim_disk(cim_disk)
+ disk_id = _disk_id_of_cim_disk(cim_disk)

return Disk(disk_id, name, disk_type, block_size, num_of_block, status,
sys_id)
--
1.7.1
Loading...