<s> """<STR_LIT>""" <EOL> import copy <EOL> from oslo_log import log as logging <EOL> from oslo_utils import excutils <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 _LI <EOL> from ironic . conductor import task_manager <EOL> from ironic . drivers import base <EOL> from ironic . drivers . modules . amt import common as amt_common <EOL> from ironic . drivers . modules . amt import resource_uris <EOL> pywsman = importutils . try_import ( '<STR_LIT>' ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> _ADDRESS = '<STR_LIT>' <EOL> _ANONYMOUS = '<STR_LIT>' <EOL> _WSMAN = '<STR_LIT>' <EOL> def _generate_change_boot_order_input ( device ) : <EOL> """<STR_LIT>""" <EOL> method_input = "<STR_LIT>" <EOL> namespace = resource_uris . CIM_BootConfigSetting <EOL> doc = pywsman . XmlDoc ( method_input ) <EOL> root = doc . root ( ) <EOL> root . set_ns ( namespace ) <EOL> child = root . add ( namespace , '<STR_LIT>' , None ) <EOL> child . add ( _ADDRESS , '<STR_LIT>' , _ANONYMOUS ) <EOL> grand_child = child . add ( _ADDRESS , '<STR_LIT>' , None ) <EOL> grand_child . add ( _WSMAN , '<STR_LIT>' , resource_uris . CIM_BootSourceSetting ) <EOL> g_grand_child = grand_child . add ( _WSMAN , '<STR_LIT>' , None ) <EOL> g_g_grand_child = g_grand_child . add ( _WSMAN , '<STR_LIT>' , device ) <EOL> g_g_grand_child . attr_add ( _WSMAN , '<STR_LIT:Name>' , '<STR_LIT>' ) <EOL> return doc <EOL> def _set_boot_device_order ( node , boot_device ) : <EOL> """<STR_LIT>""" <EOL> amt_common . awake_amt_interface ( node ) <EOL> client = amt_common . get_wsman_client ( node ) <EOL> device = amt_common . BOOT_DEVICES_MAPPING [ boot_device ] <EOL> doc = _generate_change_boot_order_input ( device ) <EOL> method = '<STR_LIT>' <EOL> options = pywsman . ClientOptions ( ) <EOL> options . add_selector ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> try : <EOL> client . wsman_invoke ( options , resource_uris . CIM_BootConfigSetting , <EOL> method , doc ) <EOL> except ( exception . AMTFailure , exception . AMTConnectFailure ) as e : <EOL> with excutils . save_and_reraise_exception ( ) : <EOL> LOG . exception ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : boot_device , '<STR_LIT>' : node . uuid , <EOL> '<STR_LIT:error>' : e } ) <EOL> else : <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : boot_device , '<STR_LIT>' : node . uuid } ) <EOL> def _generate_enable_boot_config_input ( ) : <EOL> """<STR_LIT>""" <EOL> method_input = "<STR_LIT>" <EOL> namespace = resource_uris . CIM_BootService <EOL> doc = pywsman . XmlDoc ( method_input ) <EOL> root = doc . root ( ) <EOL> root . set_ns ( namespace ) <EOL> child = root . add ( namespace , '<STR_LIT>' , None ) <EOL> child . add ( _ADDRESS , '<STR_LIT>' , _ANONYMOUS ) <EOL> grand_child = child . add ( _ADDRESS , '<STR_LIT>' , None ) <EOL> grand_child . add ( _WSMAN , '<STR_LIT>' , resource_uris . CIM_BootConfigSetting ) <EOL> g_grand_child = grand_child . add ( _WSMAN , '<STR_LIT>' , None ) <EOL> g_g_grand_child = g_grand_child . add ( _WSMAN , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> g_g_grand_child . attr_add ( _WSMAN , '<STR_LIT:Name>' , '<STR_LIT>' ) <EOL> root . add ( namespace , '<STR_LIT>' , '<STR_LIT:1>' ) <EOL> return doc <EOL> def _enable_boot_config ( node ) : <EOL> """<STR_LIT>""" <EOL> amt_common . awake_amt_interface ( node ) <EOL> client = amt_common . get_wsman_client ( node ) <EOL> method = '<STR_LIT>' <EOL> doc = _generate_enable_boot_config_input ( ) <EOL> options = pywsman . ClientOptions ( ) <EOL> options . add_selector ( '<STR_LIT:Name>' , '<STR_LIT>' ) <EOL> try : <EOL> client . wsman_invoke ( options , resource_uris . CIM_BootService , <EOL> method , doc ) <EOL> except ( exception . AMTFailure , exception . AMTConnectFailure ) as e : <EOL> with excutils . save_and_reraise_exception ( ) : <EOL> LOG . exception ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : e } ) <EOL> else : <EOL> LOG . info ( _LI ( "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : node . uuid } ) <EOL> class AMTManagement ( base . ManagementInterface ) : <EOL> def get_properties ( self ) : <EOL> return copy . deepcopy ( amt_common . COMMON_PROPERTIES ) <EOL> def validate ( self , task ) : <EOL> """<STR_LIT>""" <EOL> amt_common . parse_driver_info ( task . node ) <EOL> def get_supported_boot_devices ( self , task ) : <EOL> """<STR_LIT>""" <EOL> return list ( amt_common . BOOT_DEVICES_MAPPING ) <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 amt_common . BOOT_DEVICES_MAPPING : <EOL> raise exception . InvalidParameterValue ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) % { '<STR_LIT>' : device , '<STR_LIT>' : node . uuid } ) <EOL> driver_internal_info = node . driver_internal_info <EOL> driver_internal_info [ '<STR_LIT>' ] = device <EOL> driver_internal_info [ '<STR_LIT>' ] = persistent <EOL> node . driver_internal_info = driver_internal_info <EOL> node . save ( ) <EOL> def get_boot_device ( self , task ) : <EOL> """<STR_LIT>""" <EOL> driver_internal_info = task . node . driver_internal_info <EOL> device = driver_internal_info . get ( '<STR_LIT>' ) <EOL> persistent = driver_internal_info . get ( '<STR_LIT>' ) <EOL> if not device : <EOL> device = amt_common . DEFAULT_BOOT_DEVICE <EOL> persistent = True <EOL> return { '<STR_LIT>' : device , <EOL> '<STR_LIT>' : persistent } <EOL> def ensure_next_boot_device ( self , node , boot_device ) : <EOL> """<STR_LIT>""" <EOL> driver_internal_info = node . driver_internal_info <EOL> if not driver_internal_info . get ( '<STR_LIT>' ) : <EOL> driver_internal_info [ '<STR_LIT>' ] = ( <EOL> amt_common . DEFAULT_BOOT_DEVICE ) <EOL> driver_internal_info [ '<STR_LIT>' ] = True <EOL> node . driver_internal_info = driver_internal_info <EOL> node . save ( ) <EOL> _set_boot_device_order ( node , boot_device ) <EOL> _enable_boot_config ( node ) <EOL> def get_sensors_data ( self , task ) : <EOL> raise NotImplementedError ( ) </s>
