def discover_vlans(self): bridge_mac_address = self.get_bridge_mac_address() vlan_table_res = self.snmp_client.executeQuery( self.VLAN_TABLE_MIB) #@@CMD_PERMISION snmp protocol execution vlan_table = vlan_table_res.asTable() if len(vlan_table) == 0: raise NoVlansException, "No VLANs Configured on the device." vlan_ports_map = self.get_ports() for i in range(len(vlan_table)): oshv_result = ObjectStateHolderVector() vlan_oid = vlan_table[i][0] vlan_name = vlan_table[i][1] vlan_number = vlan_oid[vlan_oid.find('.') + 1:] port_list = vlan_ports_map.get(vlan_number) bridge_osh = None if not port_list: logger.warn( 'Skipping VLAN %s since it has no ports assigned.' % vlan_number) continue vlan_osh = ObjectStateHolder('vlan') vlan_osh.setContainer(self.host_osh) modeling.setVlanIdAttribute(vlan_osh, vlan_number) vlan_osh.setAttribute('data_name', vlan_name) if bridge_mac_address: vlan_osh.setAttribute('vlan_bridgemac', bridge_mac_address) bridge_osh = ObjectStateHolder('bridge') bridge_osh.setContainer(self.host_osh) bridge_osh.setAttribute('bridge_basemacaddr', bridge_mac_address) oshv_result.add(bridge_osh) depend_link = modeling.createLinkOSH('depend', vlan_osh, bridge_osh) oshv_result.add(depend_link) oshv_result.add(vlan_osh) for port in port_list: port_osh = ObjectStateHolder('port') port_osh.setContainer(self.host_osh) modeling.setPhysicalPortNumber(port_osh, port) oshv_result.add(port_osh) member_link = modeling.createLinkOSH('membership', vlan_osh, port_osh) oshv_result.add(member_link) if bridge_osh: contains_link = modeling.createLinkOSH( 'contains', bridge_osh, port_osh) oshv_result.add(contains_link) self.framework.sendObjects(oshv_result) self.framework.flushObjects() logger.debug( 'Vlan %s successfully discovered. Result vector contains %d objects.' % (vlan_name, oshv_result.size())) if self.snmp_client: self.snmp_client.close()
def discover_vlans(self): bridge_mac_address = self.get_bridge_mac_address() vlan_table_res = self.snmp_client.executeQuery(self.VLAN_TABLE_MIB)#@@CMD_PERMISION snmp protocol execution vlan_table = vlan_table_res.asTable() if len(vlan_table) == 0: raise NoVlansException, "No VLANs Configured on the device." vlan_ports_map = self.get_ports() for i in range(len(vlan_table)): oshv_result = ObjectStateHolderVector() vlan_oid = vlan_table[i][0] vlan_name = vlan_table[i][1] vlan_number = vlan_oid[vlan_oid.find('.')+1:] port_list = vlan_ports_map.get(vlan_number) bridge_osh = None if not port_list: logger.warn('Skipping VLAN %s since it has no ports assigned.' % vlan_number) continue vlan_osh = ObjectStateHolder('vlan') vlan_osh.setContainer(self.host_osh) modeling.setVlanIdAttribute(vlan_osh, vlan_number) vlan_osh.setAttribute('data_name', vlan_name) if bridge_mac_address: vlan_osh.setAttribute('vlan_bridgemac', bridge_mac_address) bridge_osh = ObjectStateHolder('bridge') bridge_osh.setContainer(self.host_osh) bridge_osh.setAttribute('bridge_basemacaddr', bridge_mac_address) oshv_result.add(bridge_osh) depend_link = modeling.createLinkOSH('depend',vlan_osh,bridge_osh) oshv_result.add(depend_link) oshv_result.add(vlan_osh) for port in port_list: port_osh = ObjectStateHolder('port') port_osh.setContainer(self.host_osh) modeling.setPhysicalPortNumber(port_osh, port) oshv_result.add(port_osh) member_link = modeling.createLinkOSH('membership', vlan_osh, port_osh) oshv_result.add(member_link) if bridge_osh: contains_link = modeling.createLinkOSH('contains', bridge_osh, port_osh) oshv_result.add(contains_link) self.framework.sendObjects(oshv_result) self.framework.flushObjects() logger.debug('Vlan %s successfully discovered. Result vector contains %d objects.' % (vlan_name, oshv_result.size())) if self.snmp_client: self.snmp_client.close()
def doAll(snmpClient, hostOSH, OSHVResult, ucmdbversion, Framework): vlanTableMib = '1.3.6.1.4.1.9.9.46.1.3.1.1.4,1.3.6.1.4.1.9.9.46.1.3.1.1.5,string' elanNameTableMib = '1.3.6.1.4.1.353.5.3.1.1.2.1.14,1.3.6.1.4.1.353.5.3.1.1.2.1.15,string' vlanNumberPerElanTableMib = '1.3.6.1.4.1.9.9.77.1.1.1.1.1,1.3.6.1.4.1.9.9.77.1.1.1.1.2,string' credentialsId = Framework.getDestinationAttribute('credentialsId') snmp_version = Framework.getProtocolProperty(credentialsId, "snmpprotocol_version") vlanTableRes = snmpClient.executeQuery( vlanTableMib) #@@CMD_PERMISION snmp protocol execution elanNameTableRes = snmpClient.executeQuery( elanNameTableMib) #@@CMD_PERMISION snmp protocol execution vlanNumberPerElanTableRes = snmpClient.executeQuery( vlanNumberPerElanTableMib) #@@CMD_PERMISION snmp protocol execution vlanTable = vlanTableRes.asTable() elanNameTable = elanNameTableRes.asTable() vlanNumberPerElanTable = vlanNumberPerElanTableRes.asTable() if len(vlanTable) == 0: raise Exception, "No VLANs Configured on the device." vlan_context_dict = {} if snmp_version and snmp_version == 'version 3': vlan_context_dict = snmputils.get_snmp_vlan_context_dict(snmpClient) if snmpClient: snmpClient.close() for i in range(len(vlanTable)): vlanOid = vlanTable[i][0] vlanName = vlanTable[i][1] vlanNumberA = vlanOid[vlanOid.find('.') + 1:] vlanOSH = ObjectStateHolder('vlan') vlanOSH.setContainer(hostOSH) modeling.setVlanIdAttribute(vlanOSH, vlanNumberA) try: linkedPorts = discoverPorts(vlanNumberA, vlanOSH, hostOSH, ucmdbversion, Framework, vlan_context_dict) except ValueError: logger.debug( 'No ports are assigned for VLAN %s, discarding port from result vector, Vlan will not be reported.' % vlanNumberA) continue except: logger.debug('Failed to discover ports for VLAN %s' % vlanNumberA) logger.debugException('') continue else: OSHVResult.addAll(linkedPorts) vlanOSH.setAttribute('data_name', vlanName) OSHVResult.add(vlanOSH) for j in range(len(elanNameTable)): elanIndexA = elanNameTable[j][0] elanName = elanNameTable[j][1] for k in range(len(vlanNumberPerElanTable)): elanIndexB = vlanNumberPerElanTable[k][0] vlanNumberB = vlanNumberPerElanTable[k][1] if (vlanNumberB == vlanNumberA) and (elanIndexB == elanIndexA): vlanOSH.setAttribute('vlan_aliasname', elanName) elanOSH = ObjectStateHolder('elan') elanOSH.setAttribute('data_name', elanName) OSHVResult.add(elanOSH) elanvlanmap_link = modeling.createLinkOSH( 'elanvlanmap', elanOSH, vlanOSH) OSHVResult.add(elanvlanmap_link) bcastdomain_link = modeling.createLinkOSH( 'bcastdomain', hostOSH, elanOSH) OSHVResult.add(bcastdomain_link) Framework.sendObjects(OSHVResult) Framework.flushObjects() logger.debug( 'Vlan %s successfully discovered. Result vector contains %d objects.' % (vlanName, OSHVResult.size())) OSHVResult = ObjectStateHolderVector()
def doAll(snmpClient ,hostOSH, OSHVResult, ucmdbversion, Framework): vlanTableMib = '1.3.6.1.4.1.9.9.46.1.3.1.1.4,1.3.6.1.4.1.9.9.46.1.3.1.1.5,string' elanNameTableMib = '1.3.6.1.4.1.353.5.3.1.1.2.1.14,1.3.6.1.4.1.353.5.3.1.1.2.1.15,string' vlanNumberPerElanTableMib = '1.3.6.1.4.1.9.9.77.1.1.1.1.1,1.3.6.1.4.1.9.9.77.1.1.1.1.2,string' credentialsId = Framework.getDestinationAttribute('credentialsId') snmp_version = Framework.getProtocolProperty(credentialsId, "snmpprotocol_version") vlanTableRes = snmpClient.executeQuery(vlanTableMib)#@@CMD_PERMISION snmp protocol execution elanNameTableRes = snmpClient.executeQuery(elanNameTableMib)#@@CMD_PERMISION snmp protocol execution vlanNumberPerElanTableRes = snmpClient.executeQuery(vlanNumberPerElanTableMib)#@@CMD_PERMISION snmp protocol execution vlanTable = vlanTableRes.asTable() elanNameTable = elanNameTableRes.asTable() vlanNumberPerElanTable = vlanNumberPerElanTableRes.asTable() if len(vlanTable) == 0: raise Exception, "No VLANs Configured on the device." vlan_context_dict = {} if snmp_version and snmp_version == 'version 3': vlan_context_dict = snmputils.get_snmp_vlan_context_dict(snmpClient) if snmpClient: snmpClient.close() for i in range(len(vlanTable)): vlanOid = vlanTable[i][0] vlanName = vlanTable[i][1] vlanNumberA = vlanOid[vlanOid.find('.')+1:] vlanOSH = ObjectStateHolder('vlan') vlanOSH.setContainer(hostOSH) modeling.setVlanIdAttribute(vlanOSH, vlanNumberA) try: linkedPorts = discoverPorts(vlanNumberA, vlanOSH, hostOSH, ucmdbversion, Framework, vlan_context_dict) except ValueError: logger.debug('No ports are assigned for VLAN %s, discarding port from result vector, Vlan will not be reported.' % vlanNumberA) continue except: logger.debug('Failed to discover ports for VLAN %s' % vlanNumberA) logger.debugException('') continue else: OSHVResult.addAll(linkedPorts) vlanOSH.setAttribute('data_name', vlanName) OSHVResult.add(vlanOSH) for j in range(len(elanNameTable)): elanIndexA = elanNameTable[j][0] elanName = elanNameTable[j][1] for k in range(len(vlanNumberPerElanTable)): elanIndexB = vlanNumberPerElanTable[k][0] vlanNumberB = vlanNumberPerElanTable[k][1] if (vlanNumberB == vlanNumberA) and (elanIndexB == elanIndexA): vlanOSH.setAttribute('vlan_aliasname', elanName) elanOSH = ObjectStateHolder('elan') elanOSH.setAttribute('data_name', elanName) OSHVResult.add(elanOSH) elanvlanmap_link = modeling.createLinkOSH('elanvlanmap',elanOSH,vlanOSH) OSHVResult.add(elanvlanmap_link) bcastdomain_link = modeling.createLinkOSH('bcastdomain',hostOSH, elanOSH) OSHVResult.add(bcastdomain_link) Framework.sendObjects(OSHVResult) Framework.flushObjects() logger.debug('Vlan %s successfully discovered. Result vector contains %d objects.' % (vlanName, OSHVResult.size())) OSHVResult = ObjectStateHolderVector()