@@ -25,7 +25,8 @@ def __init__(self, snmp_handler, logger, if_table):
2525 self ._sorted_module_list = []
2626 self ._power_supply_list = []
2727 self ._filtered_power_supply_list = []
28- self .port_exclude_pattern = r'stack|engine|management|mgmt|voice|foreign|cpu|control\s*ethernet\s*port'
28+ self .port_exclude_pattern = r'stack|engine|management|mgmt|voice|foreign|' \
29+ r'cpu|control\s*ethernet\s*port|console\s*port'
2930 # self.module_exclude_pattern = r''
3031 self .entity_to_container_pattern = "powershelf|cevsfp|cevxfr|cevxfp|cevContainer10GigBasePort|cevModulePseAsicPlim"
3132 # self.ignore_entity_pattern = "cevModule$|cevModuleDaughterCard$"
@@ -76,7 +77,12 @@ def _get_sorted_modules_with_ports(self):
7677 def _analyze_module (self , module ):
7778 if module not in self .exclusion_list :
7879 module_parent_address = self .get_relative_address (module )
79- module_parent_address = module_parent_address [:3 ]
80+ if not module_parent_address :
81+ self ._excluded_models .append (module )
82+ return
83+ module_parent_address_list = module_parent_address .split ("/" )
84+ if len (module_parent_address_list ) > 2 :
85+ module_parent_address = '{0}/{1}' .format (module_parent_address [0 ], module_parent_address [1 ])
8086
8187 module_rel_path = module_parent_address + '/' + self .get_resource_id (module )
8288 i = 1
@@ -107,8 +113,8 @@ def _get_entity_table(self):
107113
108114 result_dict = QualiMibTable ('entPhysicalTable' )
109115
110- entity_table_critical_port_attr = {'entPhysicalContainedIn' : 'str' , 'entPhysicalClass' : 'str' ,
111- 'entPhysicalVendorType' : 'str' }
116+ # entity_table_critical_port_attr = {'entPhysicalContainedIn': 'str', 'entPhysicalClass': 'str',
117+ # 'entPhysicalVendorType': 'str'}
112118 entity_table_optional_port_attr = {'entPhysicalDescr' : 'str' , 'entPhysicalName' : 'str' }
113119
114120 physical_indexes = self ._snmp .get_table ('ENTITY-MIB' , 'entPhysicalParentRelPos' )
@@ -119,27 +125,38 @@ def _get_entity_table(self):
119125 self .exclusion_list .append (index )
120126 continue
121127 temp_entity_table = physical_indexes [index ].copy ()
122- temp_entity_table .update (self ._snmp .get_properties ('ENTITY-MIB' , index , entity_table_critical_port_attr )
128+
129+ temp_entity_table .update (self ._snmp .get_properties ('ENTITY-MIB' , index , {"entPhysicalClass" : "str" })
123130 [index ])
124- if re .search (r"cevsensor|cevfan" , temp_entity_table ['entPhysicalVendorType' ].lower ()):
131+ if re .search (r"cpu|fan|sensor" , temp_entity_table ['entPhysicalClass' ].lower ()):
132+ self ._logger .debug ("Loaded {}, skipping." .format (temp_entity_table ['entPhysicalClass' ]))
125133 continue
134+
135+ temp_entity_table .update (self ._snmp .get_properties ('ENTITY-MIB' , index , {"entPhysicalContainedIn" : "str" })
136+ [index ])
126137 if temp_entity_table ['entPhysicalContainedIn' ] == '' :
127138 self .exclusion_list .append (index )
128139 continue
129140
130- if temp_entity_table ['entPhysicalClass' ] == '' or "other" in temp_entity_table ['entPhysicalClass' ]:
141+ temp_entity_table .update (self ._snmp .get_properties ('ENTITY-MIB' , index , {"entPhysicalVendorType" : "str" })
142+ [index ])
143+ ent_physical_class = temp_entity_table .get ("entPhysicalClass" )
144+ if not ent_physical_class or ent_physical_class == "''" or "other" in ent_physical_class :
131145 vendor_type = temp_entity_table ['entPhysicalVendorType' ]
132146 if not vendor_type :
133147 continue
134148 vendor_type_match = re .search (vendor_type_match_pattern , vendor_type .lower ())
149+ index_entity_class = None
135150 if vendor_type_match :
136151 index_entity_class = self .ENTITY_VENDOR_TYPE_TO_CLASS_MAP [vendor_type_match .group ()]
137- else :
138- continue
139152 if index_entity_class :
140153 temp_entity_table ['entPhysicalClass' ] = index_entity_class
141- if re .search (self .entity_to_container_pattern , temp_entity_table ['entPhysicalVendorType' ].lower (),
142- re .IGNORECASE ):
154+ elif not ent_physical_class or ent_physical_class == "''" :
155+ self .exclusion_list .append (index )
156+ continue
157+ if "module" in temp_entity_table ['entPhysicalClass' ].lower () \
158+ and re .search (self .entity_to_container_pattern , temp_entity_table ['entPhysicalVendorType' ].lower (),
159+ re .IGNORECASE ):
143160 temp_entity_table ['entPhysicalClass' ] = 'container'
144161 else :
145162 temp_entity_table ['entPhysicalClass' ] = temp_entity_table ['entPhysicalClass' ].replace ("'" , "" )
@@ -165,6 +182,8 @@ def _get_entity_table(self):
165182 and not re .search (self .port_exclude_pattern , temp_entity_table ['entPhysicalDescr' ],
166183 re .IGNORECASE ):
167184 port_entity = self ._get_mapping (index , temp_entity_table [self .ENTITY_PHYSICAL ])
185+ if not port_entity :
186+ port_entity = self ._get_mapping (index , temp_entity_table ["entPhysicalName" ])
168187 if port_entity and port_entity not in self .port_mapping .values ():
169188 self .port_mapping [index ] = port_entity
170189 self ._port_list .append (index )
@@ -246,8 +265,9 @@ def _filter_entity_table(self, raw_entity_table):
246265 elements = raw_entity_table .sort_by_column ('ParentRelPos' ).keys ()
247266 for element in reversed (elements ):
248267 parent_id = int (raw_entity_table [element ]['entPhysicalContainedIn' ])
249- if (parent_id not in raw_entity_table and "chassis" not in raw_entity_table [element ][
250- "entPhysicalClass" ]) or parent_id in self .exclusion_list :
268+ element_class = raw_entity_table .get (element , dict ()).get ("entPhysicalClass" )
269+ if (parent_id not in raw_entity_table and element_class not in ["chassis" ,
270+ "stack" ]) or parent_id in self .exclusion_list :
251271 self .exclusion_list .append (element )
252272 return raw_entity_table
253273
0 commit comments