<s> """<STR_LIT>""" <EOL> import copy <EOL> import six <EOL> from openstackclient . common import command <EOL> from openstackclient . common import parseractions <EOL> from openstackclient . common import utils <EOL> class CreateSnapshot ( command . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( CreateSnapshot , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> volume_client = self . app . client_manager . volume <EOL> volume_id = utils . find_resource ( <EOL> volume_client . volumes , parsed_args . volume ) . id <EOL> snapshot = volume_client . volume_snapshots . create ( <EOL> volume_id , <EOL> force = parsed_args . force , <EOL> name = parsed_args . name , <EOL> description = parsed_args . description <EOL> ) <EOL> snapshot . _info . update ( <EOL> { '<STR_LIT>' : utils . format_dict ( snapshot . _info . pop ( '<STR_LIT>' ) ) } <EOL> ) <EOL> return zip ( * sorted ( six . iteritems ( snapshot . _info ) ) ) <EOL> class DeleteSnapshot ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( DeleteSnapshot , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> nargs = "<STR_LIT:+>" , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> volume_client = self . app . client_manager . volume <EOL> for snapshot in parsed_args . snapshots : <EOL> snapshot_id = utils . find_resource ( <EOL> volume_client . volume_snapshots , snapshot ) . id <EOL> volume_client . volume_snapshots . delete ( snapshot_id ) <EOL> class ListSnapshot ( command . Lister ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ListSnapshot , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> def _format_volume_id ( volume_id ) : <EOL> """<STR_LIT>""" <EOL> volume = volume_id <EOL> if volume_id in volume_cache . keys ( ) : <EOL> volume = volume_cache [ volume_id ] . name <EOL> return volume <EOL> if parsed_args . long : <EOL> columns = [ '<STR_LIT>' , '<STR_LIT:Name>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> column_headers = copy . deepcopy ( columns ) <EOL> column_headers [ <NUM_LIT:6> ] = '<STR_LIT>' <EOL> column_headers [ <NUM_LIT:7> ] = '<STR_LIT>' <EOL> else : <EOL> columns = [ '<STR_LIT>' , '<STR_LIT:Name>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> column_headers = copy . deepcopy ( columns ) <EOL> volume_cache = { } <EOL> try : <EOL> for s in self . app . client_manager . volume . volumes . list ( ) : <EOL> volume_cache [ s . id ] = s <EOL> except Exception : <EOL> pass <EOL> search_opts = { <EOL> '<STR_LIT>' : parsed_args . all_projects , <EOL> } <EOL> data = self . app . client_manager . volume . volume_snapshots . list ( <EOL> search_opts = search_opts ) <EOL> return ( column_headers , <EOL> ( utils . get_item_properties ( <EOL> s , columns , <EOL> formatters = { '<STR_LIT>' : utils . format_dict , <EOL> '<STR_LIT>' : _format_volume_id } , <EOL> ) for s in data ) ) <EOL> class SetSnapshot ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( SetSnapshot , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = parseractions . KeyValueAction , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> volume_client = self . app . client_manager . volume <EOL> snapshot = utils . find_resource ( volume_client . volume_snapshots , <EOL> parsed_args . snapshot ) <EOL> kwargs = { } <EOL> if parsed_args . name : <EOL> kwargs [ '<STR_LIT:name>' ] = parsed_args . name <EOL> if parsed_args . description : <EOL> kwargs [ '<STR_LIT:description>' ] = parsed_args . description <EOL> if not kwargs and not parsed_args . property : <EOL> self . app . log . error ( "<STR_LIT>" ) <EOL> return <EOL> if parsed_args . property : <EOL> volume_client . volume_snapshots . set_metadata ( snapshot . id , <EOL> parsed_args . property ) <EOL> volume_client . volume_snapshots . update ( snapshot . id , ** kwargs ) <EOL> class ShowSnapshot ( command . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ShowSnapshot , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> volume_client = self . app . client_manager . volume <EOL> snapshot = utils . find_resource ( <EOL> volume_client . volume_snapshots , parsed_args . snapshot ) <EOL> snapshot . _info . update ( <EOL> { '<STR_LIT>' : utils . format_dict ( snapshot . _info . pop ( '<STR_LIT>' ) ) } <EOL> ) <EOL> return zip ( * sorted ( six . iteritems ( snapshot . _info ) ) ) <EOL> class UnsetSnapshot ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( UnsetSnapshot , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <EOL> default = [ ] , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> volume_client = self . app . client_manager . volume <EOL> snapshot = utils . find_resource ( <EOL> volume_client . volume_snapshots , parsed_args . snapshot ) <EOL> if parsed_args . property : <EOL> volume_client . volume_snapshots . delete_metadata ( <EOL> snapshot . id , <EOL> parsed_args . property , <EOL> ) <EOL> else : <EOL> self . app . log . error ( "<STR_LIT>" ) </s>
