<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> from openstackclient . identity import common as identity_common <EOL> class CreateVolume ( command . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( CreateVolume , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> "<STR_LIT:name>" , <EOL> metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> ) <EOL> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , <EOL> type = int , <EOL> required = True , <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> 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> 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> 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> identity_client = self . app . client_manager . identity <EOL> volume_client = self . app . client_manager . volume <EOL> image_client = self . app . client_manager . image <EOL> source_volume = None <EOL> if parsed_args . source : <EOL> source_volume = utils . find_resource ( <EOL> volume_client . volumes , <EOL> parsed_args . source ) . id <EOL> image = None <EOL> if parsed_args . image : <EOL> image = utils . find_resource ( <EOL> image_client . images , <EOL> parsed_args . image ) . id <EOL> snapshot = None <EOL> if parsed_args . snapshot : <EOL> snapshot = utils . find_resource ( <EOL> volume_client . volume_snapshots , <EOL> parsed_args . snapshot ) . id <EOL> project = None <EOL> if parsed_args . project : <EOL> project = utils . find_resource ( <EOL> identity_client . projects , <EOL> parsed_args . project ) . id <EOL> user = None <EOL> if parsed_args . user : <EOL> user = utils . find_resource ( <EOL> identity_client . users , <EOL> parsed_args . user ) . id <EOL> volume = volume_client . volumes . create ( <EOL> size = parsed_args . size , <EOL> snapshot_id = snapshot , <EOL> name = parsed_args . name , <EOL> description = parsed_args . description , <EOL> volume_type = parsed_args . type , <EOL> user_id = user , <EOL> project_id = project , <EOL> availability_zone = parsed_args . availability_zone , <EOL> metadata = parsed_args . property , <EOL> imageRef = image , <EOL> source_volid = source_volume <EOL> ) <EOL> volume . _info . update ( <EOL> { <EOL> '<STR_LIT>' : utils . format_dict ( volume . _info . pop ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:type>' : volume . _info . pop ( '<STR_LIT>' ) <EOL> } <EOL> ) <EOL> volume . _info . pop ( "<STR_LIT>" , None ) <EOL> return zip ( * sorted ( six . iteritems ( volume . _info ) ) ) <EOL> class DeleteVolume ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( DeleteVolume , 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> parser . add_argument ( <EOL> "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , <EOL> default = False , <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> for volume in parsed_args . volumes : <EOL> volume_obj = utils . find_resource ( <EOL> volume_client . volumes , volume ) <EOL> if parsed_args . force : <EOL> volume_client . volumes . force_delete ( volume_obj . id ) <EOL> else : <EOL> volume_client . volumes . delete ( volume_obj . id ) <EOL> class ListVolume ( command . Lister ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ListVolume , self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> identity_common . add_project_domain_option_to_parser ( parser ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> ) <EOL> identity_common . add_user_domain_option_to_parser ( parser ) <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> 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> volume_client = self . app . client_manager . volume <EOL> compute_client = self . app . client_manager . compute <EOL> identity_client = self . app . client_manager . identity <EOL> def _format_attach ( attachments ) : <EOL> """<STR_LIT>""" <EOL> msg = '<STR_LIT>' <EOL> for attachment in attachments : <EOL> server = attachment [ '<STR_LIT>' ] <EOL> if server in server_cache : <EOL> server = server_cache [ server ] . name <EOL> device = attachment [ '<STR_LIT>' ] <EOL> msg += '<STR_LIT>' % ( server , device ) <EOL> return msg <EOL> if parsed_args . long : <EOL> columns = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:Name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> column_headers = copy . deepcopy ( columns ) <EOL> column_headers [ <NUM_LIT:1> ] = '<STR_LIT>' <EOL> column_headers [ <NUM_LIT:4> ] = '<STR_LIT>' <EOL> column_headers [ <NUM_LIT:6> ] = '<STR_LIT>' <EOL> column_headers [ <NUM_LIT:7> ] = '<STR_LIT>' <EOL> else : <EOL> columns = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:Name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> column_headers = copy . deepcopy ( columns ) <EOL> column_headers [ <NUM_LIT:1> ] = '<STR_LIT>' <EOL> column_headers [ <NUM_LIT:4> ] = '<STR_LIT>' <EOL> server_cache = { } <EOL> try : <EOL> for s in compute_client . servers . list ( ) : <EOL> server_cache [ s . id ] = s <EOL> except Exception : <EOL> pass <EOL> project_id = None <EOL> if parsed_args . project : <EOL> project_id = identity_common . find_project ( <EOL> identity_client , <EOL> parsed_args . project , <EOL> parsed_args . project_domain ) <EOL> user_id = None <EOL> if parsed_args . user : <EOL> user_id = identity_common . find_user ( identity_client , <EOL> parsed_args . user , <EOL> parsed_args . user_domain ) <EOL> search_opts = { <EOL> '<STR_LIT>' : parsed_args . all_projects , <EOL> '<STR_LIT>' : project_id , <EOL> '<STR_LIT>' : user_id , <EOL> '<STR_LIT>' : parsed_args . name , <EOL> '<STR_LIT:status>' : parsed_args . status , <EOL> } <EOL> data = volume_client . volumes . list ( 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_attach } , <EOL> ) for s in data ) ) <EOL> class SetVolume ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( SetVolume , 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> type = int , <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> action = parseractions . KeyValueAction , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <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> volume = utils . find_resource ( volume_client . volumes , parsed_args . volume ) <EOL> if parsed_args . size : <EOL> if volume . status != '<STR_LIT>' : <EOL> self . app . log . error ( "<STR_LIT>" <EOL> "<STR_LIT>" % <EOL> volume . status ) <EOL> return <EOL> if parsed_args . size <= volume . size : <EOL> self . app . log . error ( "<STR_LIT>" % <EOL> volume . size ) <EOL> return <EOL> volume_client . volumes . extend ( volume . id , parsed_args . size ) <EOL> if parsed_args . property : <EOL> volume_client . volumes . set_metadata ( volume . id , parsed_args . property ) <EOL> if parsed_args . image_property : <EOL> volume_client . volumes . set_image_metadata ( <EOL> volume . id , parsed_args . image_property ) <EOL> kwargs = { } <EOL> if parsed_args . name : <EOL> kwargs [ '<STR_LIT>' ] = parsed_args . name <EOL> if parsed_args . description : <EOL> kwargs [ '<STR_LIT>' ] = parsed_args . description <EOL> if kwargs : <EOL> volume_client . volumes . update ( volume . id , ** kwargs ) <EOL> if ( not kwargs and not parsed_args . property <EOL> and not parsed_args . image_property and not parsed_args . size ) : <EOL> self . app . log . error ( "<STR_LIT>" ) <EOL> class ShowVolume ( command . ShowOne ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ShowVolume , 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> volume = utils . find_resource ( volume_client . volumes , parsed_args . volume ) <EOL> volume . _info . update ( <EOL> { <EOL> '<STR_LIT>' : utils . format_dict ( volume . _info . pop ( '<STR_LIT>' ) ) , <EOL> '<STR_LIT:type>' : volume . _info . pop ( '<STR_LIT>' ) , <EOL> } , <EOL> ) <EOL> volume . _info . pop ( "<STR_LIT>" , None ) <EOL> return zip ( * sorted ( six . iteritems ( volume . _info ) ) ) <EOL> class UnsetVolume ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( UnsetVolume , 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> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> action = '<STR_LIT>' , <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> volume = utils . find_resource ( <EOL> volume_client . volumes , parsed_args . volume ) <EOL> if parsed_args . property : <EOL> volume_client . volumes . delete_metadata ( <EOL> volume . id , parsed_args . property ) <EOL> if parsed_args . image_property : <EOL> volume_client . volumes . delete_image_metadata ( <EOL> volume . id , parsed_args . image_property ) <EOL> if ( not parsed_args . image_property and not parsed_args . property ) : <EOL> self . app . log . error ( "<STR_LIT>" ) </s>
