Discussion:
[Libstoragemgmt-devel] [PATCH 2/4] Remove get_key
Andy Grover
2014-07-30 21:40:53 UTC
Permalink
We can just invert the dict and then lookup the key.

Signed-off-by: Andy Grover <***@redhat.com>
---
plugin/smispy/smis.py | 16 +++++-----------
python_binding/lsm/_data.py | 14 +++-----------
2 files changed, 8 insertions(+), 22 deletions(-)

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index b8b7f8a..31db35f 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -205,13 +205,6 @@ def _dmtf_init_type_to_lsm(cim_init):
return AccessGroup.INIT_TYPE_UNKNOWN


-def _get_key(dictionary, value):
- keys = [k for k, v in dictionary.items() if v == value]
- if len(keys) > 0:
- return keys[0]
- return None
-
-
def _lsm_tgt_port_type_of_cim_fc_tgt(cim_fc_tgt):
"""
We are assuming we got CIM_FCPort. Caller should make sure of that.
@@ -230,12 +223,13 @@ def _lsm_tgt_port_type_of_cim_fc_tgt(cim_fc_tgt):


def _lsm_init_type_to_dmtf(init_type):
- key = _get_key(_INIT_TYPE_CONV, init_type)
- if key is None:
+ # Invert dict. Assumes values are unique.
+ try:
+ inv_dict = dict((v,k) for k, v in _INIT_TYPE_CONV.iteritems())
+ return inv_dict[init_type]
+ except KeyError:
raise LsmError(ErrorNumber.NO_SUPPORT,
"Does not support provided init_type: %d" % init_type)
- else:
- return key


class SNIA(object):
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 56e7fd9..77dfb93 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -27,13 +27,6 @@ from json.decoder import WHITESPACE
from _common import get_class, default_property


-def get_key(dictionary, value):
- keys = [k for k, v in dictionary.items() if v == value]
- if len(keys) > 0:
- return keys[0]
- return None
-
-
class DataEncoder(json.JSONEncoder):
"""
Custom json encoder for objects derived form ILsmData
@@ -463,10 +456,9 @@ class Pool(IData):
Convert disk_type to Pool.MEMBER_TYPE_DISK_XXXX
Will return Pool.MEMBER_TYPE_DISK as failback.
"""
- key = get_key(Pool._MEMBER_TYPE_2_DISK_TYPE, disk_type)
- if key or key == 0:
- return key
- return Pool.MEMBER_TYPE_DISK
+ # Invert dict. Assumes values are unique.
+ inv_dict = dict((v,k) for k, v in Pool._MEMBER_TYPE_2_DISK_TYPE.iteritems())
+ return inv_dict.get(disk_type, Pool.MEMBER_TYPE_DISK)

THINP_TYPE_UNKNOWN = 0
THINP_TYPE_THIN = 1
--
1.9.3
Andy Grover
2014-07-30 21:40:54 UTC
Permalink
Several instances where we can just return an expression instead of
assigning it to a value first.

Signed-off-by: Andy Grover <***@redhat.com>
---
python_binding/lsm/_data.py | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)

diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 77dfb93..51626bd 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -87,9 +87,7 @@ class DataDecoder(json.JSONDecoder):
return e

def decode(self, json_string, _w=WHITESPACE.match):
- decoded = json.loads(json_string)
- decoded = DataDecoder.__decode(decoded)
- return decoded
+ return DataDecoder.__decode(json.loads(json_string))


class IData(object):
@@ -133,8 +131,7 @@ class IData(object):
else:
d['_' + k] = d.pop(k)

- i = c(**d)
- return i
+ return c(**d)

def __str__(self):
"""
@@ -436,9 +433,7 @@ class Pool(IData):
Returns True if defined 'member_type' is disk.
False when else.
"""
- if member_type in Pool._MEMBER_TYPE_2_DISK_TYPE.keys():
- return True
- return False
+ return member_type in Pool._MEMBER_TYPE_2_DISK_TYPE

@staticmethod
def member_type_to_disk_type(member_type):
@@ -446,9 +441,8 @@ class Pool(IData):
Convert member_type to disk_type.
For non-disk member, we return Disk.DISK_TYPE_NOT_APPLICABLE
"""
- if member_type in Pool._MEMBER_TYPE_2_DISK_TYPE.keys():
- return Pool._MEMBER_TYPE_2_DISK_TYPE[member_type]
- return Disk.DISK_TYPE_NOT_APPLICABLE
+ return Pool._MEMBER_TYPE_2_DISK_TYPE.get(member_type,
+ Disk.DISK_TYPE_NOT_APPLICABLE)

@staticmethod
def disk_type_to_member_type(disk_type):
@@ -837,9 +831,8 @@ class Capabilities(IData):
DISKS = 220

def _to_dict(self):
- rc = {'class': self.__class__.__name__,
- 'cap': ''.join(['%02x' % b for b in self._cap])}
- return rc
+ return {'class': self.__class__.__name__,
+ 'cap': ''.join(['%02x' % b for b in self._cap])}

def __init__(self, _cap=None):
if _cap is not None:
@@ -848,9 +841,7 @@ class Capabilities(IData):
self._cap = bytearray(Capabilities._NUM)

def supported(self, capability):
- if self.get(capability) == Capabilities.SUPPORTED:
- return True
- return False
+ return self.get(capability) == Capabilities.SUPPORTED

def get(self, capability):
if capability >= len(self._cap):
@@ -890,7 +881,6 @@ class Capabilities(IData):

def set(self, capability, value=SUPPORTED):
self._cap[capability] = value
- return None

def enable_all(self):
for i in range(len(self._cap)):
--
1.9.3
Tony Asleson
2014-07-31 16:27:22 UTC
Permalink
Patch committed.

Thanks!
Post by Andy Grover
Several instances where we can just return an expression instead of
assigning it to a value first.
---
python_binding/lsm/_data.py | 26 ++++++++------------------
1 file changed, 8 insertions(+), 18 deletions(-)
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 77dfb93..51626bd 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
return e
- decoded = json.loads(json_string)
- decoded = DataDecoder.__decode(decoded)
- return decoded
+ return DataDecoder.__decode(json.loads(json_string))
d['_' + k] = d.pop(k)
- i = c(**d)
- return i
+ return c(**d)
"""
Returns True if defined 'member_type' is disk.
False when else.
"""
- return True
- return False
+ return member_type in Pool._MEMBER_TYPE_2_DISK_TYPE
@staticmethod
Convert member_type to disk_type.
For non-disk member, we return Disk.DISK_TYPE_NOT_APPLICABLE
"""
- return Pool._MEMBER_TYPE_2_DISK_TYPE[member_type]
- return Disk.DISK_TYPE_NOT_APPLICABLE
+ return Pool._MEMBER_TYPE_2_DISK_TYPE.get(member_type,
+ Disk.DISK_TYPE_NOT_APPLICABLE)
@staticmethod
DISKS = 220
- rc = {'class': self.__class__.__name__,
- 'cap': ''.join(['%02x' % b for b in self._cap])}
- return rc
+ return {'class': self.__class__.__name__,
+ 'cap': ''.join(['%02x' % b for b in self._cap])}
self._cap = bytearray(Capabilities._NUM)
- return True
- return False
+ return self.get(capability) == Capabilities.SUPPORTED
self._cap[capability] = value
- return None
Andy Grover
2014-07-30 21:40:55 UTC
Permalink
Signed-off-by: Andy Grover <***@redhat.com>
---
plugin/smispy/smis.py | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 31db35f..f394022 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -367,7 +367,7 @@ class Smis(IStorageAreaNetwork):
DMTF_STATUS_POWER_MODE = 18

# We will rework this once SNIA documented these out.
- _DMTF_STAUTS_TO_POOL_STATUS = {
+ _DMTF_STATUS_TO_POOL_STATUS = {
DMTF_STATUS_UNKNOWN: Pool.STATUS_UNKNOWN,
DMTF_STATUS_OTHER: Pool.STATUS_OTHER,
DMTF_STATUS_OK: Pool.STATUS_OK,
@@ -388,7 +388,7 @@ class Smis(IStorageAreaNetwork):
DMTF_STATUS_POWER_MODE: Pool.STATUS_OTHER,
}

- _DMTF_STAUTS_TO_POOL_STATUS_INFO = {
+ _DMTF_STATUS_TO_POOL_STATUS_INFO = {
# TODO: Use CIM_RelatedElementCausingError
# to find out the error info.
DMTF_STATUS_PREDICTIVE_FAILURE: 'Predictive failure',
@@ -400,7 +400,7 @@ class Smis(IStorageAreaNetwork):
DMTF_STATUS_POWER_MODE: 'Power mode',
}

- _DMTF_STAUTS_TO_DISK_STATUS = {
+ _DMTF_STATUS_TO_DISK_STATUS = {
DMTF_STATUS_UNKNOWN: Disk.STATUS_UNKNOWN,
DMTF_STATUS_OTHER: Disk.STATUS_OTHER,
DMTF_STATUS_OK: Disk.STATUS_OK,
@@ -421,7 +421,7 @@ class Smis(IStorageAreaNetwork):
DMTF_STATUS_POWER_MODE: Disk.STATUS_OTHER,
}

- _DMTF_STAUTS_TO_DISK_STATUS_INFO = {
+ _DMTF_STATUS_TO_DISK_STATUS_INFO = {
DMTF_STATUS_DORMANT: 'Dormant',
DMTF_STATUS_IN_SERVICE: 'In service',
DMTF_STATUS_NO_CONTACT: 'No contact',
@@ -3187,14 +3187,14 @@ class Smis(IStorageAreaNetwork):
status_info = []
dmtf_statuses = cim_disk['OperationalStatus']
for dmtf_status in dmtf_statuses:
- if dmtf_status in Smis._DMTF_STAUTS_TO_DISK_STATUS.keys():
- lsm_status = Smis._DMTF_STAUTS_TO_DISK_STATUS[dmtf_status]
+ if dmtf_status in Smis._DMTF_STATUS_TO_DISK_STATUS.keys():
+ lsm_status = Smis._DMTF_STATUS_TO_DISK_STATUS[dmtf_status]
if status == Disk.STATUS_UNKNOWN:
status = lsm_status
else:
status |= lsm_status
- if dmtf_status in Smis._DMTF_STAUTS_TO_DISK_STATUS_INFO.keys():
- status_info.append(Smis._DMTF_STAUTS_TO_DISK_STATUS_INFO[dmtf_status])
+ if dmtf_status in Smis._DMTF_STATUS_TO_DISK_STATUS_INFO.keys():
+ status_info.append(Smis._DMTF_STATUS_TO_DISK_STATUS_INFO[dmtf_status])
return (status, ", ",join(status_info))

def _new_disk(self, cim_disk, cim_ext):
@@ -3310,15 +3310,15 @@ class Smis(IStorageAreaNetwork):
status_info = []
dmtf_statuses = cim_pool['OperationalStatus']
for dmtf_status in dmtf_statuses:
- if dmtf_status in Smis._DMTF_STAUTS_TO_POOL_STATUS.keys():
+ if dmtf_status in Smis._DMTF_STATUS_TO_POOL_STATUS.keys():

- lsm_status = Smis._DMTF_STAUTS_TO_POOL_STATUS[dmtf_status]
+ lsm_status = Smis._DMTF_STATUS_TO_POOL_STATUS[dmtf_status]
if status == Pool.STATUS_UNKNOWN:
status = lsm_status
else:
status |= lsm_status
- if dmtf_status in Smis._DMTF_STAUTS_TO_POOL_STATUS_INFO.keys():
- status_info.append(Smis._DMTF_STAUTS_TO_POOL_STATUS_INFO[dmtf_status])
+ if dmtf_status in Smis._DMTF_STATUS_TO_POOL_STATUS_INFO.keys():
+ status_info.append(Smis._DMTF_STATUS_TO_POOL_STATUS_INFO[dmtf_status])
return (status, ", ".join(status_info))

def _find_out_bottom_cexts(self, cim_pool_path, pros_list=None):
--
1.9.3
Tony Asleson
2014-07-31 16:27:36 UTC
Permalink
Patch committed.

Thanks!
Post by Andy Grover
---
plugin/smispy/smis.py | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 31db35f..f394022 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
DMTF_STATUS_POWER_MODE = 18
# We will rework this once SNIA documented these out.
- _DMTF_STAUTS_TO_POOL_STATUS = {
+ _DMTF_STATUS_TO_POOL_STATUS = {
DMTF_STATUS_UNKNOWN: Pool.STATUS_UNKNOWN,
DMTF_STATUS_OTHER: Pool.STATUS_OTHER,
DMTF_STATUS_OK: Pool.STATUS_OK,
DMTF_STATUS_POWER_MODE: Pool.STATUS_OTHER,
}
- _DMTF_STAUTS_TO_POOL_STATUS_INFO = {
+ _DMTF_STATUS_TO_POOL_STATUS_INFO = {
# TODO: Use CIM_RelatedElementCausingError
# to find out the error info.
DMTF_STATUS_PREDICTIVE_FAILURE: 'Predictive failure',
DMTF_STATUS_POWER_MODE: 'Power mode',
}
- _DMTF_STAUTS_TO_DISK_STATUS = {
+ _DMTF_STATUS_TO_DISK_STATUS = {
DMTF_STATUS_UNKNOWN: Disk.STATUS_UNKNOWN,
DMTF_STATUS_OTHER: Disk.STATUS_OTHER,
DMTF_STATUS_OK: Disk.STATUS_OK,
DMTF_STATUS_POWER_MODE: Disk.STATUS_OTHER,
}
- _DMTF_STAUTS_TO_DISK_STATUS_INFO = {
+ _DMTF_STATUS_TO_DISK_STATUS_INFO = {
DMTF_STATUS_DORMANT: 'Dormant',
DMTF_STATUS_IN_SERVICE: 'In service',
DMTF_STATUS_NO_CONTACT: 'No contact',
status_info = []
dmtf_statuses = cim_disk['OperationalStatus']
- lsm_status = Smis._DMTF_STAUTS_TO_DISK_STATUS[dmtf_status]
+ lsm_status = Smis._DMTF_STATUS_TO_DISK_STATUS[dmtf_status]
status = lsm_status
status |= lsm_status
- status_info.append(Smis._DMTF_STAUTS_TO_DISK_STATUS_INFO[dmtf_status])
+ status_info.append(Smis._DMTF_STATUS_TO_DISK_STATUS_INFO[dmtf_status])
return (status, ", ",join(status_info))
status_info = []
dmtf_statuses = cim_pool['OperationalStatus']
- lsm_status = Smis._DMTF_STAUTS_TO_POOL_STATUS[dmtf_status]
+ lsm_status = Smis._DMTF_STATUS_TO_POOL_STATUS[dmtf_status]
status = lsm_status
status |= lsm_status
- status_info.append(Smis._DMTF_STAUTS_TO_POOL_STATUS_INFO[dmtf_status])
+ status_info.append(Smis._DMTF_STATUS_TO_POOL_STATUS_INFO[dmtf_status])
return (status, ", ".join(status_info))
Tony Asleson
2014-07-30 22:26:14 UTC
Permalink
Thanks for the patches! The others in the series look good. This one
has a minor issue. See comments below.
A more Pythonic way of generating a comma-delimited string of 0 to n
elements is to put them in a list and then ", ".join() them.
Thanks for the tip!
However, in the usage in smis.py, it doesn't actually appear the
status_info is actually being added-to more than once, so it's
possible status_info could just be a string that we set to the new value,
but I've kept the code as-is for now.
dmtf_statuses can be a list, so it can potentially be more than one.
---
plugin/smispy/smis.py | 18 +++++++-----------
python_binding/lsm/__init__.py | 2 +-
python_binding/lsm/_data.py | 7 -------
3 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 3ad92f8..b8b7f8a 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -27,7 +27,7 @@ from pywbem import CIMError
from lsm import (IStorageAreaNetwork, error, uri_parse, LsmError, ErrorNumber,
JobStatus, md5, Pool, Volume, AccessGroup, System,
- Capabilities, Disk, txt_a, VERSION, TargetPort,
+ Capabilities, Disk, VERSION, TargetPort,
search_property)
Return (status, status_info)
"""
status = Disk.STATUS_UNKNOWN
- status_info = ''
+ status_info = []
dmtf_statuses = cim_disk['OperationalStatus']
status |= lsm_status
- status_info = txt_a(
- status_info,
- Smis._DMTF_STAUTS_TO_DISK_STATUS_INFO[dmtf_status])
- return (status, status_info)
+ status_info.append(Smis._DMTF_STAUTS_TO_DISK_STATUS_INFO[dmtf_status])
+ return (status, ", ",join(status_info))
This should be a dot, not a comma before the join
"""
Return (status, status_info)
"""
status = Pool.STATUS_UNKNOWN
- status_info = ''
+ status_info = []
dmtf_statuses = cim_pool['OperationalStatus']
status |= lsm_status
- status_info = txt_a(
- status_info,
- Smis._DMTF_STAUTS_TO_POOL_STATUS_INFO[dmtf_status])
- return (status, status_info)
+ status_info.append(Smis._DMTF_STAUTS_TO_POOL_STATUS_INFO[dmtf_status])
+ return (status, ", ".join(status_info))
"""
diff --git a/python_binding/lsm/__init__.py b/python_binding/lsm/__init__.py
index 1887c93..308ad15 100644
--- a/python_binding/lsm/__init__.py
+++ b/python_binding/lsm/__init__.py
@@ -7,7 +7,7 @@ from _common import error, info, LsmError, ErrorLevel, ErrorNumber, \
common_urllib2_error_handler, size_human_2_size_bytes
from _data import (Disk, Volume, Pool, System, FileSystem, FsSnapshot,
NfsExport, BlockRange, AccessGroup, TargetPort,
- Capabilities, txt_a)
+ Capabilities)
from _iplugin import IPlugin, IStorageAreaNetwork, INetworkAttachedStorage, \
INfs
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index bd06286..56e7fd9 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -27,13 +27,6 @@ from json.decoder import WHITESPACE
from _common import get_class, default_property
- return txt + ',' + append
- return append
-
-
keys = [k for k, v in dictionary.items() if v == value]
Tony Asleson
2014-07-31 16:26:31 UTC
Permalink
Amended patch committed.

Thanks,
Tony
A more Pythonic way of generating a comma-delimited string of 0 to n
elements is to put them in a list and then ", ".join() them.
However, in the usage in smis.py, it doesn't actually appear the
status_info is actually being added-to more than once, so it's
possible status_info could just be a string that we set to the new value,
but I've kept the code as-is for now.
---
plugin/smispy/smis.py | 18 +++++++-----------
python_binding/lsm/__init__.py | 2 +-
python_binding/lsm/_data.py | 7 -------
3 files changed, 8 insertions(+), 19 deletions(-)
diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index 3ad92f8..b8b7f8a 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
@@ -27,7 +27,7 @@ from pywbem import CIMError
from lsm import (IStorageAreaNetwork, error, uri_parse, LsmError, ErrorNumber,
JobStatus, md5, Pool, Volume, AccessGroup, System,
- Capabilities, Disk, txt_a, VERSION, TargetPort,
+ Capabilities, Disk, VERSION, TargetPort,
search_property)
Return (status, status_info)
"""
status = Disk.STATUS_UNKNOWN
- status_info = ''
+ status_info = []
dmtf_statuses = cim_disk['OperationalStatus']
status |= lsm_status
- status_info = txt_a(
- status_info,
- Smis._DMTF_STAUTS_TO_DISK_STATUS_INFO[dmtf_status])
- return (status, status_info)
+ status_info.append(Smis._DMTF_STAUTS_TO_DISK_STATUS_INFO[dmtf_status])
+ return (status, ", ",join(status_info))
"""
Return (status, status_info)
"""
status = Pool.STATUS_UNKNOWN
- status_info = ''
+ status_info = []
dmtf_statuses = cim_pool['OperationalStatus']
status |= lsm_status
- status_info = txt_a(
- status_info,
- Smis._DMTF_STAUTS_TO_POOL_STATUS_INFO[dmtf_status])
- return (status, status_info)
+ status_info.append(Smis._DMTF_STAUTS_TO_POOL_STATUS_INFO[dmtf_status])
+ return (status, ", ".join(status_info))
"""
diff --git a/python_binding/lsm/__init__.py b/python_binding/lsm/__init__.py
index 1887c93..308ad15 100644
--- a/python_binding/lsm/__init__.py
+++ b/python_binding/lsm/__init__.py
@@ -7,7 +7,7 @@ from _common import error, info, LsmError, ErrorLevel, ErrorNumber, \
common_urllib2_error_handler, size_human_2_size_bytes
from _data import (Disk, Volume, Pool, System, FileSystem, FsSnapshot,
NfsExport, BlockRange, AccessGroup, TargetPort,
- Capabilities, txt_a)
+ Capabilities)
from _iplugin import IPlugin, IStorageAreaNetwork, INetworkAttachedStorage, \
INfs
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index bd06286..56e7fd9 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -27,13 +27,6 @@ from json.decoder import WHITESPACE
from _common import get_class, default_property
- return txt + ',' + append
- return append
-
-
keys = [k for k, v in dictionary.items() if v == value]
Tony Asleson
2014-07-31 16:27:09 UTC
Permalink
Patch committed.

Thanks!
Post by Andy Grover
We can just invert the dict and then lookup the key.
---
plugin/smispy/smis.py | 16 +++++-----------
python_binding/lsm/_data.py | 14 +++-----------
2 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/plugin/smispy/smis.py b/plugin/smispy/smis.py
index b8b7f8a..31db35f 100644
--- a/plugin/smispy/smis.py
+++ b/plugin/smispy/smis.py
return AccessGroup.INIT_TYPE_UNKNOWN
- keys = [k for k, v in dictionary.items() if v == value]
- return keys[0]
- return None
-
-
"""
We are assuming we got CIM_FCPort. Caller should make sure of that.
- key = _get_key(_INIT_TYPE_CONV, init_type)
+ # Invert dict. Assumes values are unique.
+ inv_dict = dict((v,k) for k, v in _INIT_TYPE_CONV.iteritems())
+ return inv_dict[init_type]
raise LsmError(ErrorNumber.NO_SUPPORT,
"Does not support provided init_type: %d" % init_type)
- return key
diff --git a/python_binding/lsm/_data.py b/python_binding/lsm/_data.py
index 56e7fd9..77dfb93 100644
--- a/python_binding/lsm/_data.py
+++ b/python_binding/lsm/_data.py
@@ -27,13 +27,6 @@ from json.decoder import WHITESPACE
from _common import get_class, default_property
- keys = [k for k, v in dictionary.items() if v == value]
- return keys[0]
- return None
-
-
"""
Custom json encoder for objects derived form ILsmData
Convert disk_type to Pool.MEMBER_TYPE_DISK_XXXX
Will return Pool.MEMBER_TYPE_DISK as failback.
"""
- key = get_key(Pool._MEMBER_TYPE_2_DISK_TYPE, disk_type)
- return key
- return Pool.MEMBER_TYPE_DISK
+ # Invert dict. Assumes values are unique.
+ inv_dict = dict((v,k) for k, v in Pool._MEMBER_TYPE_2_DISK_TYPE.iteritems())
+ return inv_dict.get(disk_type, Pool.MEMBER_TYPE_DISK)
THINP_TYPE_UNKNOWN = 0
THINP_TYPE_THIN = 1
Loading...