<s> """<STR_LIT>""" <EOL> from oslo_log import log as logging <EOL> from oslo_utils import importutils <EOL> from ironic . common import boot_devices <EOL> from ironic . common import exception <EOL> from ironic . common . i18n import _ <EOL> from ironic . common . i18n import _LE <EOL> from ironic . conductor import task_manager <EOL> from ironic . drivers import base <EOL> from ironic . drivers . modules . drac import common as drac_common <EOL> from ironic . drivers . modules . drac import job as drac_job <EOL> drac_exceptions = importutils . try_import ( '<STR_LIT>' ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> _BOOT_DEVICES_MAP = { <EOL> boot_devices . DISK : '<STR_LIT>' , <EOL> boot_devices . PXE : '<STR_LIT>' , <EOL> boot_devices . CDROM : '<STR_LIT>' , <EOL> } <EOL> PERSISTENT_BOOT_MODE = '<STR_LIT>' <EOL> NON_PERSISTENT_BOOT_MODE = '<STR_LIT>' <EOL> def _get_boot_device ( node , drac_boot_devices = None ) : <EOL> client = drac_common . get_drac_client ( node ) <EOL> try : <EOL> boot_modes = client . list_boot_modes ( ) <EOL> next_boot_modes = [ mode . id for mode in boot_modes if mode . is_next ] <EOL> if NON_PERSISTENT_BOOT_MODE in next_boot_modes : <EOL> next_boot_mode = NON_PERSISTENT_BOOT_MODE <EOL> else : <EOL> next_boot_mode = next_boot_modes [ <NUM_LIT:0> ] <EOL> if drac_boot_devices is None : <EOL> drac_boot_devices = client . list_boot_devices ( ) <EOL> drac_boot_device = drac_boot_devices [ next_boot_mode ] [ <NUM_LIT:0> ] <EOL> boot_device = next ( key for ( key , value ) in _BOOT_DEVICES_MAP . items ( ) <EOL> if value in drac_boot_device . id ) <EOL> return { '<STR_LIT>' : boot_device , <EOL> '<STR_LIT>' : next_boot_mode == PERSISTENT_BOOT_MODE } <EOL> except ( drac_exceptions . BaseClientException , IndexError ) as exc : <EOL> LOG . error ( _LE ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : exc } ) <EOL> raise exception . DracOperationError ( error = exc ) <EOL> def set_boot_device ( node , device , persistent = False ) : <EOL> """<STR_LIT>""" <EOL> drac_job . validate_job_queue ( node ) <EOL> client = drac_common . get_drac_client ( node ) <EOL> try : <EOL> drac_boot_devices = client . list_boot_devices ( ) <EOL> current_boot_device = _get_boot_device ( node , drac_boot_devices ) <EOL> if current_boot_device == { '<STR_LIT>' : device , <EOL> '<STR_LIT>' : persistent } : <EOL> LOG . debug ( '<STR_LIT>' , device ) <EOL> return <EOL> drac_boot_device = next ( drac_device . id for drac_device <EOL> in drac_boot_devices [ PERSISTENT_BOOT_MODE ] <EOL> if _BOOT_DEVICES_MAP [ device ] in drac_device . id ) <EOL> if persistent : <EOL> boot_list = PERSISTENT_BOOT_MODE <EOL> else : <EOL> boot_list = NON_PERSISTENT_BOOT_MODE <EOL> client . change_boot_device_order ( boot_list , drac_boot_device ) <EOL> client . commit_pending_bios_changes ( ) <EOL> except drac_exceptions . BaseClientException as exc : <EOL> LOG . error ( _LE ( '<STR_LIT>' <EOL> '<STR_LIT>' ) , <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : exc } ) <EOL> raise exception . DracOperationError ( error = exc ) <EOL> class DracManagement ( base . ManagementInterface ) : <EOL> def get_properties ( self ) : <EOL> """<STR_LIT>""" <EOL> return drac_common . COMMON_PROPERTIES <EOL> def validate ( self , task ) : <EOL> """<STR_LIT>""" <EOL> return drac_common . parse_driver_info ( task . node ) <EOL> def get_supported_boot_devices ( self , task ) : <EOL> """<STR_LIT>""" <EOL> return list ( _BOOT_DEVICES_MAP . keys ( ) ) <EOL> def get_boot_device ( self , task ) : <EOL> """<STR_LIT>""" <EOL> node = task . node <EOL> boot_device = node . driver_internal_info . get ( '<STR_LIT>' ) <EOL> if boot_device is not None : <EOL> return boot_device <EOL> return _get_boot_device ( node ) <EOL> @ task_manager . require_exclusive_lock <EOL> def set_boot_device ( self , task , device , persistent = False ) : <EOL> """<STR_LIT>""" <EOL> node = task . node <EOL> if device not in _BOOT_DEVICES_MAP : <EOL> raise exception . InvalidParameterValue ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % { '<STR_LIT>' : device , <EOL> '<STR_LIT>' : node . uuid } ) <EOL> driver_internal_info = node . driver_internal_info <EOL> driver_internal_info [ '<STR_LIT>' ] = { '<STR_LIT>' : device , <EOL> '<STR_LIT>' : persistent } <EOL> node . driver_internal_info = driver_internal_info <EOL> node . save ( ) <EOL> def get_sensors_data ( self , task ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError ( ) </s>
