<s> """<STR_LIT>""" <EOL> import os <EOL> import shutil <EOL> import tempfile <EOL> from ironic_lib import utils as ironic_utils <EOL> from oslo_config import cfg <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 . glance_service import service_utils <EOL> from ironic . common . i18n import _ <EOL> from ironic . common . i18n import _LE <EOL> from ironic . common . i18n import _LI <EOL> from ironic . common import images <EOL> from ironic . common import states <EOL> from ironic . conductor import utils as manager_utils <EOL> from ironic . drivers import base <EOL> from ironic . drivers . modules import deploy_utils <EOL> from ironic . drivers . modules . irmc import common as irmc_common <EOL> scci = importutils . try_import ( '<STR_LIT>' ) <EOL> CONF = cfg . CONF <EOL> try : <EOL> if CONF . debug : <EOL> scci . DEBUG = True <EOL> except Exception : <EOL> pass <EOL> opts = [ <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> ignore_case = True , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , secret = True , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> cfg . StrOpt ( '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) , <EOL> ] <EOL> CONF . register_opts ( opts , group = '<STR_LIT>' ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> REQUIRED_PROPERTIES = { <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> } <EOL> COMMON_PROPERTIES = REQUIRED_PROPERTIES <EOL> def _parse_config_option ( ) : <EOL> """<STR_LIT>""" <EOL> error_msgs = [ ] <EOL> if not os . path . isdir ( CONF . irmc . remote_image_share_root ) : <EOL> error_msgs . append ( <EOL> _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> CONF . irmc . remote_image_share_root ) <EOL> if error_msgs : <EOL> msg = ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % error_msgs ) <EOL> raise exception . InvalidParameterValue ( msg ) <EOL> def _parse_driver_info ( node ) : <EOL> """<STR_LIT>""" <EOL> d_info = node . driver_info <EOL> deploy_info = { } <EOL> deploy_info [ '<STR_LIT>' ] = d_info . get ( '<STR_LIT>' ) <EOL> error_msg = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> deploy_utils . check_for_missing_params ( deploy_info , error_msg ) <EOL> if service_utils . is_image_href_ordinary_file_name ( <EOL> deploy_info [ '<STR_LIT>' ] ) : <EOL> deploy_iso = os . path . join ( CONF . irmc . remote_image_share_root , <EOL> deploy_info [ '<STR_LIT>' ] ) <EOL> if not os . path . isfile ( deploy_iso ) : <EOL> msg = ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { '<STR_LIT>' : deploy_iso , '<STR_LIT>' : node . uuid } ) <EOL> raise exception . InvalidParameterValue ( msg ) <EOL> return deploy_info <EOL> def _parse_instance_info ( node ) : <EOL> """<STR_LIT>""" <EOL> i_info = node . instance_info <EOL> deploy_info = { } <EOL> if i_info . get ( '<STR_LIT>' ) : <EOL> deploy_info [ '<STR_LIT>' ] = i_info [ '<STR_LIT>' ] <EOL> if service_utils . is_image_href_ordinary_file_name ( <EOL> deploy_info [ '<STR_LIT>' ] ) : <EOL> boot_iso = os . path . join ( CONF . irmc . remote_image_share_root , <EOL> deploy_info [ '<STR_LIT>' ] ) <EOL> if not os . path . isfile ( boot_iso ) : <EOL> msg = ( _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) % <EOL> { '<STR_LIT>' : boot_iso , '<STR_LIT>' : node . uuid } ) <EOL> raise exception . InvalidParameterValue ( msg ) <EOL> return deploy_info <EOL> def _parse_deploy_info ( node ) : <EOL> """<STR_LIT>""" <EOL> deploy_info = { } <EOL> deploy_info . update ( deploy_utils . get_image_instance_info ( node ) ) <EOL> deploy_info . update ( _parse_driver_info ( node ) ) <EOL> deploy_info . update ( _parse_instance_info ( node ) ) <EOL> return deploy_info <EOL> def _setup_deploy_iso ( task , ramdisk_options ) : <EOL> """<STR_LIT>""" <EOL> d_info = task . node . driver_info <EOL> deploy_iso_href = d_info [ '<STR_LIT>' ] <EOL> if service_utils . is_image_href_ordinary_file_name ( deploy_iso_href ) : <EOL> deploy_iso_file = deploy_iso_href <EOL> else : <EOL> deploy_iso_file = _get_deploy_iso_name ( task . node ) <EOL> deploy_iso_fullpathname = os . path . join ( <EOL> CONF . irmc . remote_image_share_root , deploy_iso_file ) <EOL> images . fetch ( task . context , deploy_iso_href , deploy_iso_fullpathname ) <EOL> _setup_vmedia_for_boot ( task , deploy_iso_file , ramdisk_options ) <EOL> manager_utils . node_set_boot_device ( task , boot_devices . CDROM ) <EOL> def _get_deploy_iso_name ( node ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % node . uuid <EOL> def _get_boot_iso_name ( node ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % node . uuid <EOL> def _prepare_boot_iso ( task , root_uuid ) : <EOL> """<STR_LIT>""" <EOL> deploy_info = _parse_deploy_info ( task . node ) <EOL> driver_internal_info = task . node . driver_internal_info <EOL> if deploy_info . get ( '<STR_LIT>' ) : <EOL> boot_iso_href = deploy_info [ '<STR_LIT>' ] <EOL> if service_utils . is_image_href_ordinary_file_name ( boot_iso_href ) : <EOL> driver_internal_info [ '<STR_LIT>' ] = boot_iso_href <EOL> else : <EOL> boot_iso_filename = _get_boot_iso_name ( task . node ) <EOL> boot_iso_fullpathname = os . path . join ( <EOL> CONF . irmc . remote_image_share_root , boot_iso_filename ) <EOL> images . fetch ( task . context , boot_iso_href , boot_iso_fullpathname ) <EOL> driver_internal_info [ '<STR_LIT>' ] = boot_iso_filename <EOL> else : <EOL> image_href = deploy_info [ '<STR_LIT>' ] <EOL> image_props = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> image_properties = images . get_image_properties ( <EOL> task . context , image_href , image_props ) <EOL> kernel_href = ( task . node . instance_info . get ( '<STR_LIT>' ) or <EOL> image_properties [ '<STR_LIT>' ] ) <EOL> ramdisk_href = ( task . node . instance_info . get ( '<STR_LIT>' ) or <EOL> image_properties [ '<STR_LIT>' ] ) <EOL> deploy_iso_filename = _get_deploy_iso_name ( task . node ) <EOL> deploy_iso = ( '<STR_LIT>' + os . path . join ( <EOL> CONF . irmc . remote_image_share_root , deploy_iso_filename ) ) <EOL> boot_mode = deploy_utils . get_boot_mode_for_deploy ( task . node ) <EOL> kernel_params = CONF . pxe . pxe_append_params <EOL> boot_iso_filename = _get_boot_iso_name ( task . node ) <EOL> boot_iso_fullpathname = os . path . join ( <EOL> CONF . irmc . remote_image_share_root , boot_iso_filename ) <EOL> images . create_boot_iso ( task . context , boot_iso_fullpathname , <EOL> kernel_href , ramdisk_href , <EOL> deploy_iso , root_uuid , <EOL> kernel_params , boot_mode ) <EOL> driver_internal_info [ '<STR_LIT>' ] = boot_iso_filename <EOL> task . node . driver_internal_info = driver_internal_info <EOL> task . node . save ( ) <EOL> def _get_floppy_image_name ( node ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" % node . uuid <EOL> def _prepare_floppy_image ( task , params ) : <EOL> """<STR_LIT>""" <EOL> floppy_filename = _get_floppy_image_name ( task . node ) <EOL> floppy_fullpathname = os . path . join ( <EOL> CONF . irmc . remote_image_share_root , floppy_filename ) <EOL> with tempfile . NamedTemporaryFile ( ) as vfat_image_tmpfile_obj : <EOL> images . create_vfat_image ( vfat_image_tmpfile_obj . name , <EOL> parameters = params ) <EOL> try : <EOL> shutil . copyfile ( vfat_image_tmpfile_obj . name , <EOL> floppy_fullpathname ) <EOL> except IOError as e : <EOL> operation = _ ( "<STR_LIT>" ) <EOL> raise exception . IRMCOperationError ( <EOL> operation = operation , error = e ) <EOL> return floppy_filename <EOL> def attach_boot_iso_if_needed ( task ) : <EOL> """<STR_LIT>""" <EOL> d_info = task . node . driver_internal_info <EOL> node_state = task . node . provision_state <EOL> if '<STR_LIT>' in d_info and node_state == states . ACTIVE : <EOL> _setup_vmedia_for_boot ( task , d_info [ '<STR_LIT>' ] ) <EOL> manager_utils . node_set_boot_device ( task , boot_devices . CDROM ) <EOL> def _setup_vmedia_for_boot ( task , bootable_iso_filename , parameters = None ) : <EOL> """<STR_LIT>""" <EOL> LOG . info ( _LI ( "<STR_LIT>" ) , <EOL> task . node . uuid ) <EOL> _detach_virtual_cd ( task . node ) <EOL> _detach_virtual_fd ( task . node ) <EOL> if parameters : <EOL> floppy_image_filename = _prepare_floppy_image ( task , parameters ) <EOL> _attach_virtual_fd ( task . node , floppy_image_filename ) <EOL> _attach_virtual_cd ( task . node , bootable_iso_filename ) <EOL> def _cleanup_vmedia_boot ( task ) : <EOL> """<STR_LIT>""" <EOL> LOG . debug ( "<STR_LIT>" , task . node . uuid ) <EOL> node = task . node <EOL> _detach_virtual_cd ( node ) <EOL> _detach_virtual_fd ( node ) <EOL> _remove_share_file ( _get_floppy_image_name ( node ) ) <EOL> _remove_share_file ( _get_deploy_iso_name ( node ) ) <EOL> def _remove_share_file ( share_filename ) : <EOL> """<STR_LIT>""" <EOL> share_fullpathname = os . path . join ( <EOL> CONF . irmc . remote_image_share_name , share_filename ) <EOL> ironic_utils . unlink_without_raise ( share_fullpathname ) <EOL> def _attach_virtual_cd ( node , bootable_iso_filename ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> irmc_client = irmc_common . get_irmc_client ( node ) <EOL> cd_set_params = scci . get_virtual_cd_set_params_cmd ( <EOL> CONF . irmc . remote_image_server , <EOL> CONF . irmc . remote_image_user_domain , <EOL> scci . get_share_type ( CONF . irmc . remote_image_share_type ) , <EOL> CONF . irmc . remote_image_share_name , <EOL> bootable_iso_filename , <EOL> CONF . irmc . remote_image_user_name , <EOL> CONF . irmc . remote_image_user_password ) <EOL> irmc_client ( cd_set_params , async = False ) <EOL> irmc_client ( scci . MOUNT_CD , async = False ) <EOL> except scci . SCCIClientError as irmc_exception : <EOL> LOG . exception ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : irmc_exception } ) <EOL> operation = _ ( "<STR_LIT>" ) <EOL> raise exception . IRMCOperationError ( operation = operation , <EOL> error = irmc_exception ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , node . uuid ) <EOL> def _detach_virtual_cd ( node ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> irmc_client = irmc_common . get_irmc_client ( node ) <EOL> irmc_client ( scci . UNMOUNT_CD ) <EOL> except scci . SCCIClientError as irmc_exception : <EOL> LOG . exception ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : irmc_exception } ) <EOL> operation = _ ( "<STR_LIT>" ) <EOL> raise exception . IRMCOperationError ( operation = operation , <EOL> error = irmc_exception ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , node . uuid ) <EOL> def _attach_virtual_fd ( node , floppy_image_filename ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> irmc_client = irmc_common . get_irmc_client ( node ) <EOL> fd_set_params = scci . get_virtual_fd_set_params_cmd ( <EOL> CONF . irmc . remote_image_server , <EOL> CONF . irmc . remote_image_user_domain , <EOL> scci . get_share_type ( CONF . irmc . remote_image_share_type ) , <EOL> CONF . irmc . remote_image_share_name , <EOL> floppy_image_filename , <EOL> CONF . irmc . remote_image_user_name , <EOL> CONF . irmc . remote_image_user_password ) <EOL> irmc_client ( fd_set_params , async = False ) <EOL> irmc_client ( scci . MOUNT_FD , async = False ) <EOL> except scci . SCCIClientError as irmc_exception : <EOL> LOG . exception ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : irmc_exception } ) <EOL> operation = _ ( "<STR_LIT>" ) <EOL> raise exception . IRMCOperationError ( operation = operation , <EOL> error = irmc_exception ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , node . uuid ) <EOL> def _detach_virtual_fd ( node ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> irmc_client = irmc_common . get_irmc_client ( node ) <EOL> irmc_client ( scci . UNMOUNT_FD ) <EOL> except scci . SCCIClientError as irmc_exception : <EOL> LOG . exception ( _LE ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> { '<STR_LIT>' : node . uuid , '<STR_LIT:error>' : irmc_exception } ) <EOL> operation = _ ( "<STR_LIT>" ) <EOL> raise exception . IRMCOperationError ( operation = operation , <EOL> error = irmc_exception ) <EOL> LOG . info ( _LI ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , node . uuid ) <EOL> def check_share_fs_mounted ( ) : <EOL> """<STR_LIT>""" <EOL> _parse_config_option ( ) <EOL> if not os . path . ismount ( CONF . irmc . remote_image_share_root ) : <EOL> raise exception . IRMCSharedFileSystemNotMounted ( <EOL> share = CONF . irmc . remote_image_share_root ) <EOL> class IRMCVirtualMediaBoot ( base . BootInterface ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> """<STR_LIT>""" <EOL> check_share_fs_mounted ( ) <EOL> super ( IRMCVirtualMediaBoot , self ) . __init__ ( ) <EOL> def get_properties ( self ) : <EOL> return COMMON_PROPERTIES <EOL> def validate ( self , task ) : <EOL> """<STR_LIT>""" <EOL> check_share_fs_mounted ( ) <EOL> d_info = _parse_deploy_info ( task . node ) <EOL> if task . node . driver_internal_info . get ( '<STR_LIT>' ) : <EOL> props = [ ] <EOL> elif service_utils . is_glance_image ( d_info [ '<STR_LIT>' ] ) : <EOL> props = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> else : <EOL> props = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> deploy_utils . validate_image_properties ( task . context , d_info , <EOL> props ) <EOL> def prepare_ramdisk ( self , task , ramdisk_params ) : <EOL> """<STR_LIT>""" <EOL> if task . node . provision_state != states . DEPLOYING : <EOL> return <EOL> deploy_nic_mac = deploy_utils . get_single_nic_with_vif_port_id ( task ) <EOL> ramdisk_params [ '<STR_LIT>' ] = deploy_nic_mac <EOL> _setup_deploy_iso ( task , ramdisk_params ) <EOL> def clean_up_ramdisk ( self , task ) : <EOL> """<STR_LIT>""" <EOL> _cleanup_vmedia_boot ( task ) <EOL> def prepare_instance ( self , task ) : <EOL> """<STR_LIT>""" <EOL> _cleanup_vmedia_boot ( task ) <EOL> node = task . node <EOL> iwdi = node . driver_internal_info . get ( '<STR_LIT>' ) <EOL> if deploy_utils . get_boot_option ( node ) == "<STR_LIT>" or iwdi : <EOL> manager_utils . node_set_boot_device ( task , boot_devices . DISK , <EOL> persistent = True ) <EOL> else : <EOL> driver_internal_info = node . driver_internal_info <EOL> root_uuid_or_disk_id = driver_internal_info [ '<STR_LIT>' ] <EOL> self . _configure_vmedia_boot ( task , root_uuid_or_disk_id ) <EOL> def clean_up_instance ( self , task ) : <EOL> """<STR_LIT>""" <EOL> _remove_share_file ( _get_boot_iso_name ( task . node ) ) <EOL> driver_internal_info = task . node . driver_internal_info <EOL> driver_internal_info . pop ( '<STR_LIT>' , None ) <EOL> driver_internal_info . pop ( '<STR_LIT>' , None ) <EOL> task . node . driver_internal_info = driver_internal_info <EOL> task . node . save ( ) <EOL> _cleanup_vmedia_boot ( task ) <EOL> def _configure_vmedia_boot ( self , task , root_uuid_or_disk_id ) : <EOL> """<STR_LIT>""" <EOL> node = task . node <EOL> _prepare_boot_iso ( task , root_uuid_or_disk_id ) <EOL> _setup_vmedia_for_boot ( <EOL> task , node . driver_internal_info [ '<STR_LIT>' ] ) <EOL> manager_utils . node_set_boot_device ( task , boot_devices . CDROM , <EOL> persistent = True ) </s>
