00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 from utils import merge_list
00018 import dmtf
00019 from lsm import System, LsmError, ErrorNumber
00020
00021
00022 def cim_sys_id_pros():
00023 """
00024 Return the property of CIM_ComputerSystem required to generate
00025 lsm.System.id
00026 """
00027 return ['Name']
00028
00029
00030 def sys_id_of_cim_sys(cim_sys):
00031 if 'Name' in cim_sys:
00032 return cim_sys['Name']
00033 else:
00034 raise LsmError(
00035 ErrorNumber.PLUGIN_BUG,
00036 "sys_id_of_cim_sys(): Got a CIM_ComputerSystem does not have "
00037 "'Name' property: %s, %s" % (cim_sys.items(), cim_sys.path))
00038
00039
00040 def sys_id_of_cim_vol(cim_vol):
00041 if 'SystemName' in cim_vol:
00042 return cim_vol['SystemName']
00043 else:
00044 raise LsmError(
00045 ErrorNumber.PLUGIN_BUG,
00046 "sys_id_of_cim_vol(): Got a CIM_StorageVolume does not have "
00047 "'SystemName' property: %s, %s" % (cim_vol.items(), cim_vol.path))
00048
00049
00050 def root_cim_sys(smis_common, property_list=None):
00051 """
00052 Use this association to find out the root CIM_ComputerSystem:
00053 CIM_RegisteredProfile # Root Profile('Array') in interop
00054 |
00055 | CIM_ElementConformsToProfile
00056 v
00057 CIM_ComputerSystem # vendor namespace
00058 """
00059 id_pros = cim_sys_id_pros()
00060 if property_list is None:
00061 property_list = id_pros
00062 else:
00063 property_list = merge_list(property_list, id_pros)
00064
00065 cim_syss = []
00066 if smis_common.is_megaraid():
00067 cim_syss = smis_common.EnumerateInstances(
00068 'CIM_ComputerSystem', PropertyList=property_list)
00069 else:
00070 cim_syss = smis_common.Associators(
00071 smis_common.root_blk_cim_rp.path,
00072 ResultClass='CIM_ComputerSystem',
00073 AssocClass='CIM_ElementConformsToProfile',
00074 PropertyList=property_list)
00075
00076 if len(cim_syss) == 0:
00077 raise LsmError(ErrorNumber.NO_SUPPORT,
00078 "Current SMI-S provider does not provide "
00079 "the root CIM_ComputerSystem associated "
00080 "to 'Array' CIM_RegisteredProfile.")
00081
00082
00083 if smis_common.system_list:
00084 needed_cim_syss = []
00085 for cim_sys in cim_syss:
00086 if sys_id_of_cim_sys(cim_sys) in smis_common.system_list:
00087 needed_cim_syss.extend([cim_sys])
00088 return needed_cim_syss
00089 else:
00090 return cim_syss
00091
00092
00093 def cim_sys_pros():
00094 """
00095 Return a list of properties required to create a LSM System
00096 """
00097 cim_sys_properties = cim_sys_id_pros()
00098 cim_sys_properties.extend(['ElementName', 'OperationalStatus'])
00099 return cim_sys_properties
00100
00101
00102 _LSM_SYS_OP_STATUS_CONV = {
00103 dmtf.OP_STATUS_UNKNOWN: System.STATUS_UNKNOWN,
00104 dmtf.OP_STATUS_OK: System.STATUS_OK,
00105 dmtf.OP_STATUS_ERROR: System.STATUS_ERROR,
00106 dmtf.OP_STATUS_DEGRADED: System.STATUS_DEGRADED,
00107 dmtf.OP_STATUS_NON_RECOVERABLE_ERROR: System.STATUS_ERROR,
00108 dmtf.OP_STATUS_PREDICTIVE_FAILURE: System.STATUS_PREDICTIVE_FAILURE,
00109 dmtf.OP_STATUS_SUPPORTING_ENTITY_IN_ERROR: System.STATUS_ERROR,
00110 }
00111
00112
00113 def _sys_status_of_cim_sys(cim_sys):
00114 """
00115 Convert CIM_ComputerSystem['OperationalStatus']
00116 """
00117 if 'OperationalStatus' not in cim_sys:
00118 raise LsmError(
00119 ErrorNumber.PLUGIN_BUG,
00120 "sys_status_of_cim_sys(): Got a CIM_ComputerSystem with no "
00121 "OperationalStatus: %s, %s" % (cim_sys.items(), cim_sys.path))
00122
00123 return dmtf.op_status_list_conv(
00124 _LSM_SYS_OP_STATUS_CONV, cim_sys['OperationalStatus'],
00125 System.STATUS_UNKNOWN, System.STATUS_OTHER)
00126
00127
00128 def cim_sys_to_lsm_sys(cim_sys):
00129 status = System.STATUS_UNKNOWN
00130 status_info = ''
00131
00132 if 'OperationalStatus' in cim_sys:
00133 (status, status_info) = _sys_status_of_cim_sys(cim_sys)
00134
00135 sys_id = sys_id_of_cim_sys(cim_sys)
00136 sys_name = cim_sys['ElementName']
00137
00138 return System(sys_id, sys_name, status, status_info)
00139
00140
00141 def cim_sys_of_sys_id(smis_common, sys_id, property_list=None):
00142 """
00143 Find out the CIM_ComputerSystem for given lsm.System.id using
00144 root_cim_sys()
00145 """
00146 id_pros = cim_sys_id_pros()
00147 if property_list is None:
00148 property_list = id_pros
00149 else:
00150 property_list = merge_list(property_list, id_pros)
00151
00152 cim_syss = root_cim_sys(smis_common, property_list)
00153 for cim_sys in cim_syss:
00154 if sys_id_of_cim_sys(cim_sys) == sys_id:
00155 return cim_sys
00156 raise LsmError(
00157 ErrorNumber.NOT_FOUND_SYSTEM,
00158 "Not found System")