<s> """<STR_LIT>""" <EOL> import logging <EOL> from os import environ <EOL> from aminator . config import conf_action <EOL> from aminator . plugins . finalizer . tagging_base import TaggingBaseFinalizerPlugin <EOL> from aminator . util . linux import sanitize_metadata <EOL> __all__ = ( '<STR_LIT>' , ) <EOL> log = logging . getLogger ( __name__ ) <EOL> class TaggingEBSFinalizerPlugin ( TaggingBaseFinalizerPlugin ) : <EOL> _name = '<STR_LIT>' <EOL> def add_plugin_args ( self ) : <EOL> tagging = super ( TaggingEBSFinalizerPlugin , self ) . add_plugin_args ( ) <EOL> context = self . _config . context <EOL> tagging . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT:name>' , action = conf_action ( context . ami ) , help = '<STR_LIT>' ) <EOL> def _set_metadata ( self ) : <EOL> super ( TaggingEBSFinalizerPlugin , self ) . _set_metadata ( ) <EOL> context = self . _config . context <EOL> config = self . _config . plugins [ self . full_name ] <EOL> metadata = context . package . attributes <EOL> ami_name = context . ami . get ( '<STR_LIT:name>' , None ) <EOL> if not ami_name : <EOL> ami_name = config . name_format . format ( ** metadata ) <EOL> context . ami . name = sanitize_metadata ( '<STR_LIT>' . format ( ami_name ) ) <EOL> def _snapshot_volume ( self ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> if not self . _cloud . snapshot_volume ( ) : <EOL> return False <EOL> log . info ( '<STR_LIT>' ) <EOL> return True <EOL> def _register_image ( self , block_device_map = None , root_device = None ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> config = self . _config . plugins [ self . full_name ] <EOL> if block_device_map is None : <EOL> block_device_map = config . default_block_device_map <EOL> if root_device is None : <EOL> root_device = config . default_root_device <EOL> if not self . _cloud . register_image ( block_device_map , root_device ) : <EOL> return False <EOL> log . info ( '<STR_LIT>' ) <EOL> return True <EOL> def finalize ( self ) : <EOL> log . info ( '<STR_LIT>' ) <EOL> self . _set_metadata ( ) <EOL> if not self . _snapshot_volume ( ) : <EOL> log . critical ( '<STR_LIT>' ) <EOL> return False <EOL> if not self . _register_image ( ) : <EOL> log . critical ( '<STR_LIT>' ) <EOL> return False <EOL> if not self . _add_tags ( [ '<STR_LIT>' , '<STR_LIT>' ] ) : <EOL> log . critical ( '<STR_LIT>' ) <EOL> return False <EOL> log . info ( '<STR_LIT>' ) <EOL> self . _log_ami_metadata ( ) <EOL> return True <EOL> def __enter__ ( self ) : <EOL> context = self . _config . context <EOL> environ [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> if context . ami . get ( "<STR_LIT:name>" , None ) : <EOL> environ [ "<STR_LIT>" ] = context . ami . name <EOL> return super ( TaggingEBSFinalizerPlugin , self ) . __enter__ ( ) </s>
