<s> from oslo_config import cfg <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 _LE <EOL> from ironic . common . i18n import _LW <EOL> from ironic . common import states <EOL> from ironic . drivers import utils <EOL> LOG = logging . getLogger ( __name__ ) <EOL> client = importutils . try_import ( '<STR_LIT>' ) <EOL> oneview_states = importutils . try_import ( '<STR_LIT>' ) <EOL> oneview_exceptions = importutils . try_import ( '<STR_LIT>' ) <EOL> opts = [ <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT:username>' , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT:password>' , <EOL> secret = True , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . BoolOpt ( '<STR_LIT>' , <EOL> default = False , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = None , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . IntOpt ( '<STR_LIT>' , <EOL> default = <NUM_LIT:12> , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> ] <EOL> CONF = cfg . CONF <EOL> CONF . register_opts ( opts , group = '<STR_LIT>' ) <EOL> REQUIRED_ON_DRIVER_INFO = { <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" ) , <EOL> } <EOL> REQUIRED_ON_PROPERTIES = { <EOL> '<STR_LIT>' : _ ( <EOL> "<STR_LIT>" <EOL> ) , <EOL> } <EOL> OPTIONAL_ON_PROPERTIES = { <EOL> '<STR_LIT>' : _ ( <EOL> "<STR_LIT>" ) , <EOL> '<STR_LIT>' : _ ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> } <EOL> COMMON_PROPERTIES = { } <EOL> COMMON_PROPERTIES . update ( REQUIRED_ON_DRIVER_INFO ) <EOL> COMMON_PROPERTIES . update ( REQUIRED_ON_PROPERTIES ) <EOL> COMMON_PROPERTIES . update ( OPTIONAL_ON_PROPERTIES ) <EOL> def get_oneview_client ( ) : <EOL> """<STR_LIT>""" <EOL> oneview_client = client . Client ( <EOL> manager_url = CONF . oneview . manager_url , <EOL> username = CONF . oneview . username , <EOL> password = CONF . oneview . password , <EOL> allow_insecure_connections = CONF . oneview . allow_insecure_connections , <EOL> tls_cacert_file = CONF . oneview . tls_cacert_file , <EOL> max_polling_attempts = CONF . oneview . max_polling_attempts <EOL> ) <EOL> return oneview_client <EOL> def verify_node_info ( node ) : <EOL> """<STR_LIT>""" <EOL> capabilities_dict = utils . capabilities_to_dict ( <EOL> node . properties . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> driver_info = node . driver_info <EOL> _verify_node_info ( '<STR_LIT>' , capabilities_dict , <EOL> REQUIRED_ON_PROPERTIES ) <EOL> try : <EOL> _verify_node_info ( '<STR_LIT>' , capabilities_dict , <EOL> [ '<STR_LIT>' ] ) <EOL> except exception . MissingParameterValue : <EOL> try : <EOL> _verify_node_info ( '<STR_LIT>' , driver_info , <EOL> [ '<STR_LIT>' ] ) <EOL> LOG . warning ( <EOL> _LW ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> node . uuid <EOL> ) <EOL> except exception . MissingParameterValue : <EOL> raise exception . MissingParameterValue ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) <EOL> _verify_node_info ( '<STR_LIT>' , driver_info , <EOL> REQUIRED_ON_DRIVER_INFO ) <EOL> def get_oneview_info ( node ) : <EOL> """<STR_LIT>""" <EOL> capabilities_dict = utils . capabilities_to_dict ( <EOL> node . properties . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> driver_info = node . driver_info <EOL> oneview_info = { <EOL> '<STR_LIT>' : <EOL> driver_info . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : <EOL> capabilities_dict . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : <EOL> capabilities_dict . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : <EOL> capabilities_dict . get ( '<STR_LIT>' ) or <EOL> driver_info . get ( '<STR_LIT>' ) , <EOL> } <EOL> return oneview_info <EOL> def validate_oneview_resources_compatibility ( task ) : <EOL> """<STR_LIT>""" <EOL> node = task . node <EOL> node_ports = task . ports <EOL> try : <EOL> oneview_client = get_oneview_client ( ) <EOL> oneview_info = get_oneview_info ( node ) <EOL> oneview_client . validate_node_server_hardware ( <EOL> oneview_info , node . properties . get ( '<STR_LIT>' ) , <EOL> node . properties . get ( '<STR_LIT>' ) <EOL> ) <EOL> oneview_client . validate_node_server_hardware_type ( oneview_info ) <EOL> oneview_client . check_server_profile_is_applied ( oneview_info ) <EOL> oneview_client . is_node_port_mac_compatible_with_server_profile ( <EOL> oneview_info , node_ports <EOL> ) <EOL> oneview_client . validate_node_enclosure_group ( oneview_info ) <EOL> oneview_client . validate_node_server_profile_template ( oneview_info ) <EOL> except oneview_exceptions . OneViewException as oneview_exc : <EOL> msg = ( _ ( "<STR_LIT>" ) <EOL> % oneview_exc ) <EOL> LOG . error ( msg ) <EOL> raise exception . OneViewError ( error = msg ) <EOL> def translate_oneview_power_state ( power_state ) : <EOL> """<STR_LIT>""" <EOL> power_states_map = { <EOL> oneview_states . ONEVIEW_POWER_ON : states . POWER_ON , <EOL> oneview_states . ONEVIEW_POWERING_OFF : states . POWER_ON , <EOL> oneview_states . ONEVIEW_POWER_OFF : states . POWER_OFF , <EOL> oneview_states . ONEVIEW_POWERING_ON : states . POWER_OFF , <EOL> oneview_states . ONEVIEW_RESETTING : states . REBOOT <EOL> } <EOL> return power_states_map . get ( power_state , states . ERROR ) <EOL> def _verify_node_info ( node_namespace , node_info_dict , info_required ) : <EOL> """<STR_LIT>""" <EOL> missing_keys = set ( info_required ) - set ( node_info_dict ) <EOL> if missing_keys : <EOL> raise exception . MissingParameterValue ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { '<STR_LIT>' : node_namespace , <EOL> '<STR_LIT>' : '<STR_LIT:U+002CU+0020>' . join ( missing_keys ) <EOL> } <EOL> ) <EOL> missing_values_keys = [ k for k in info_required <EOL> if node_info_dict [ k ] in ( '<STR_LIT>' , None ) ] <EOL> if missing_values_keys : <EOL> missing_keys = [ "<STR_LIT>" % ( node_namespace , k ) <EOL> for k in missing_values_keys ] <EOL> raise exception . MissingParameterValue ( <EOL> _ ( "<STR_LIT>" ) % "<STR_LIT>" . join ( missing_keys ) <EOL> ) <EOL> def node_has_server_profile ( func ) : <EOL> """<STR_LIT>""" <EOL> def inner ( * args , ** kwargs ) : <EOL> task = args [ <NUM_LIT:1> ] <EOL> oneview_info = get_oneview_info ( task . node ) <EOL> oneview_client = get_oneview_client ( ) <EOL> try : <EOL> node_has_server_profile = ( <EOL> oneview_client . get_server_profile_from_hardware ( oneview_info ) <EOL> ) <EOL> except oneview_exceptions . OneViewException as oneview_exc : <EOL> LOG . error ( <EOL> _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { "<STR_LIT>" : task . node . uuid , "<STR_LIT:message>" : oneview_exc } <EOL> ) <EOL> raise exception . OneViewError ( error = oneview_exc ) <EOL> if not node_has_server_profile : <EOL> raise exception . OperationNotPermitted ( <EOL> _ ( "<STR_LIT>" ) % <EOL> task . node . uuid <EOL> ) <EOL> return func ( * args , ** kwargs ) <EOL> return inner </s>
