<s> import argparse <EOL> from neutronclient . _i18n import _ <EOL> from neutronclient . common import exceptions <EOL> from neutronclient . common import utils <EOL> from neutronclient . neutron import v2_0 as neutronV20 <EOL> from neutronclient . neutron . v2_0 import availability_zone <EOL> from neutronclient . neutron . v2_0 import dns <EOL> from neutronclient . neutron . v2_0 . qos import policy as qos_policy <EOL> def _format_subnets ( network ) : <EOL> try : <EOL> return '<STR_LIT:\n>' . join ( [ '<STR_LIT:U+0020>' . join ( [ s [ '<STR_LIT:id>' ] , s . get ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> for s in network [ '<STR_LIT>' ] ] ) <EOL> except ( TypeError , KeyError ) : <EOL> return '<STR_LIT>' <EOL> class ListNetwork ( neutronV20 . ListCommand ) : <EOL> """<STR_LIT>""" <EOL> subnet_id_filter_len = <NUM_LIT> <EOL> resource = '<STR_LIT>' <EOL> _formatters = { '<STR_LIT>' : _format_subnets , } <EOL> list_columns = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' ] <EOL> pagination_support = True <EOL> sorting_support = True <EOL> filter_attrs = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> { '<STR_LIT:name>' : '<STR_LIT:status>' , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : { '<STR_LIT:type>' : utils . convert_to_uppercase } } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _ ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' } } , <EOL> ] <EOL> def extend_list ( self , data , parsed_args ) : <EOL> """<STR_LIT>""" <EOL> neutron_client = self . get_client ( ) <EOL> search_opts = { '<STR_LIT>' : [ '<STR_LIT:id>' , '<STR_LIT>' ] } <EOL> if self . pagination_support : <EOL> page_size = parsed_args . page_size <EOL> if page_size : <EOL> search_opts . update ( { '<STR_LIT>' : page_size } ) <EOL> subnet_ids = [ ] <EOL> for n in data : <EOL> if '<STR_LIT>' in n : <EOL> subnet_ids . extend ( n [ '<STR_LIT>' ] ) <EOL> def _get_subnet_list ( sub_ids ) : <EOL> search_opts [ '<STR_LIT:id>' ] = sub_ids <EOL> return neutron_client . list_subnets ( <EOL> ** search_opts ) . get ( '<STR_LIT>' , [ ] ) <EOL> try : <EOL> subnets = _get_subnet_list ( subnet_ids ) <EOL> except exceptions . RequestURITooLong as uri_len_exc : <EOL> subnet_count = len ( subnet_ids ) <EOL> max_size = ( ( self . subnet_id_filter_len * subnet_count ) - <EOL> uri_len_exc . excess ) <EOL> chunk_size = max_size // self . subnet_id_filter_len <EOL> subnets = [ ] <EOL> for i in range ( <NUM_LIT:0> , subnet_count , chunk_size ) : <EOL> subnets . extend ( <EOL> _get_subnet_list ( subnet_ids [ i : i + chunk_size ] ) ) <EOL> subnet_dict = dict ( [ ( s [ '<STR_LIT:id>' ] , s ) for s in subnets ] ) <EOL> for n in data : <EOL> if '<STR_LIT>' in n : <EOL> n [ '<STR_LIT>' ] = [ ( subnet_dict . get ( s ) or { "<STR_LIT:id>" : s } ) <EOL> for s in n [ '<STR_LIT>' ] ] <EOL> class ListExternalNetwork ( ListNetwork ) : <EOL> """<STR_LIT>""" <EOL> pagination_support = True <EOL> sorting_support = True <EOL> def retrieve_list ( self , parsed_args ) : <EOL> external = '<STR_LIT>' <EOL> if external not in self . values_specs : <EOL> self . values_specs . append ( '<STR_LIT>' ) <EOL> return super ( ListExternalNetwork , self ) . retrieve_list ( parsed_args ) <EOL> class ShowNetwork ( neutronV20 . ShowCommand ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> class CreateNetwork ( neutronV20 . CreateCommand , qos_policy . CreateQosPolicyMixin ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> def add_known_arguments ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , action = '<STR_LIT>' , <EOL> help = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( '<STR_LIT>' ) , <EOL> default = argparse . SUPPRESS ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> utils . add_boolean_argument ( <EOL> parser , <EOL> '<STR_LIT>' , <EOL> default = argparse . SUPPRESS , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT:name>' , metavar = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> self . add_arguments_qos_policy ( parser ) <EOL> availability_zone . add_az_hint_argument ( parser , self . resource ) <EOL> dns . add_dns_argument_create ( parser , self . resource , '<STR_LIT>' ) <EOL> def args2body ( self , parsed_args ) : <EOL> body = { '<STR_LIT:name>' : parsed_args . name , <EOL> '<STR_LIT>' : parsed_args . admin_state } <EOL> neutronV20 . update_dict ( parsed_args , body , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:description>' ] ) <EOL> self . args2body_qos_policy ( parsed_args , body ) <EOL> availability_zone . args2body_az_hint ( parsed_args , body ) <EOL> dns . args2body_dns_create ( parsed_args , body , '<STR_LIT>' ) <EOL> return { '<STR_LIT>' : body } <EOL> class DeleteNetwork ( neutronV20 . DeleteCommand ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> class UpdateNetwork ( neutronV20 . UpdateCommand , qos_policy . UpdateQosPolicyMixin ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> def add_known_arguments ( self , parser ) : <EOL> self . add_arguments_qos_policy ( parser ) <EOL> dns . add_dns_argument_update ( parser , self . resource , '<STR_LIT>' ) <EOL> def args2body ( self , parsed_args ) : <EOL> body = { } <EOL> self . args2body_qos_policy ( parsed_args , body ) <EOL> dns . args2body_dns_update ( parsed_args , body , '<STR_LIT>' ) <EOL> return { '<STR_LIT>' : body } </s>
