<s> """<STR_LIT>""" <EOL> from oslo_log import log as logging <EOL> from oslo_utils import importutils <EOL> from ironic . common import exception <EOL> from ironic . common . i18n import _ <EOL> from ironic . common . i18n import _LI <EOL> from ironic . common . i18n import _LW <EOL> from ironic . common import states <EOL> from ironic . drivers import base <EOL> from ironic . drivers . modules . irmc import common as irmc_common <EOL> from ironic . drivers . modules import snmp <EOL> from ironic import objects <EOL> scci = importutils . try_import ( '<STR_LIT>' ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> """<STR_LIT>""" <EOL> NODE_CLASS_OID_VALUE = { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> '<STR_LIT>' : <NUM_LIT:6> , <EOL> '<STR_LIT>' : <NUM_LIT:7> <EOL> } <EOL> NODE_CLASS_OID = '<STR_LIT>' <EOL> """<STR_LIT>""" <EOL> MAC_ADDRESS_OID = '<STR_LIT>' <EOL> def _get_mac_addresses ( node ) : <EOL> """<STR_LIT>""" <EOL> d_info = irmc_common . parse_driver_info ( node ) <EOL> snmp_client = snmp . SNMPClient ( d_info [ '<STR_LIT>' ] , <EOL> d_info [ '<STR_LIT>' ] , <EOL> d_info [ '<STR_LIT>' ] , <EOL> d_info [ '<STR_LIT>' ] , <EOL> d_info [ '<STR_LIT>' ] ) <EOL> node_classes = snmp_client . get_next ( NODE_CLASS_OID ) <EOL> mac_addresses = [ '<STR_LIT::>' . join ( [ '<STR_LIT>' % ord ( x ) for x in mac ] ) <EOL> for mac in snmp_client . get_next ( MAC_ADDRESS_OID ) ] <EOL> return [ a for c , a in zip ( node_classes , mac_addresses ) <EOL> if c == NODE_CLASS_OID_VALUE [ '<STR_LIT>' ] ] <EOL> def _inspect_hardware ( node ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> report = irmc_common . get_irmc_report ( node ) <EOL> props = scci . get_essential_properties ( <EOL> report , IRMCInspect . ESSENTIAL_PROPERTIES ) <EOL> macs = _get_mac_addresses ( node ) <EOL> except ( scci . SCCIInvalidInputError , <EOL> scci . SCCIClientError , <EOL> exception . SNMPFailure ) as e : <EOL> error = ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : e } ) <EOL> raise exception . HardwareInspectionFailure ( error = error ) <EOL> return ( props , macs ) <EOL> class IRMCInspect ( base . InspectInterface ) : <EOL> """<STR_LIT>""" <EOL> def get_properties ( self ) : <EOL> """<STR_LIT>""" <EOL> return irmc_common . COMMON_PROPERTIES <EOL> def validate ( self , task ) : <EOL> """<STR_LIT>""" <EOL> irmc_common . parse_driver_info ( task . node ) <EOL> def inspect_hardware ( self , task ) : <EOL> """<STR_LIT>""" <EOL> node = task . node <EOL> ( props , macs ) = _inspect_hardware ( node ) <EOL> node . properties = dict ( node . properties , ** props ) <EOL> node . save ( ) <EOL> for mac in macs : <EOL> try : <EOL> new_port = objects . Port ( task . context , <EOL> address = mac , node_id = node . id ) <EOL> new_port . create ( ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT:address>' : mac , '<STR_LIT>' : node . uuid } ) <EOL> except exception . MACAlreadyExists : <EOL> LOG . warning ( _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT:address>' : mac , '<STR_LIT>' : node . uuid } ) <EOL> LOG . info ( _LI ( "<STR_LIT>" ) , node . uuid ) <EOL> return states . MANAGEABLE </s>
