<s> """<STR_LIT>""" <EOL> from openstackclient . common import command <EOL> from openstackclient . common import exceptions <EOL> from openstackclient . common import utils <EOL> from openstackclient . i18n import _ <EOL> from openstackclient . identity import common as identity_common <EOL> from openstackclient . network import common <EOL> def _format_admin_state ( item ) : <EOL> return '<STR_LIT>' if item else '<STR_LIT>' <EOL> def _format_router_external ( item ) : <EOL> return '<STR_LIT>' if item else '<STR_LIT>' <EOL> _formatters = { <EOL> '<STR_LIT>' : utils . format_list , <EOL> '<STR_LIT>' : _format_admin_state , <EOL> '<STR_LIT>' : _format_router_external , <EOL> '<STR_LIT>' : utils . format_list , <EOL> '<STR_LIT>' : utils . format_list , <EOL> } <EOL> def _get_columns ( item ) : <EOL> columns = list ( item . keys ( ) ) <EOL> if '<STR_LIT>' in columns : <EOL> columns . remove ( '<STR_LIT>' ) <EOL> columns . append ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in columns : <EOL> columns . remove ( '<STR_LIT>' ) <EOL> columns . append ( '<STR_LIT>' ) <EOL> return tuple ( sorted ( columns ) ) <EOL> def _get_attrs ( client_manager , parsed_args ) : <EOL> attrs = { } <EOL> if parsed_args . name is not None : <EOL> attrs [ '<STR_LIT:name>' ] = str ( parsed_args . name ) <EOL> if parsed_args . enable : <EOL> attrs [ '<STR_LIT>' ] = True <EOL> if parsed_args . disable : <EOL> attrs [ '<STR_LIT>' ] = False <EOL> if parsed_args . share : <EOL> attrs [ '<STR_LIT>' ] = True <EOL> if parsed_args . no_share : <EOL> attrs [ '<STR_LIT>' ] = False <EOL> if '<STR_LIT>' in parsed_args and parsed_args . project is not None : <EOL> identity_client = client_manager . identity <EOL> project_id = identity_common . find_project ( <EOL> identity_client , <EOL> parsed_args . project , <EOL> parsed_args . project_domain , <EOL> ) . id <EOL> attrs [ '<STR_LIT>' ] = project_id <EOL> if '<STR_LIT>' in parsed_args and parsed_args . availability_zone_hints is not None : <EOL> attrs [ '<STR_LIT>' ] = parsed_args . availability_zone_hints <EOL> if parsed_args . internal : <EOL> attrs [ '<STR_LIT>' ] = False <EOL> if parsed_args . external : <EOL> attrs [ '<STR_LIT>' ] = True <EOL> if parsed_args . no_default : <EOL> attrs [ '<STR_LIT>' ] = False <EOL> if parsed_args . default : <EOL> attrs [ '<STR_LIT>' ] = True <EOL> if parsed_args . provider_network_type : <EOL> attrs [ '<STR_LIT>' ] = parsed_args . provider_network_type <EOL> if parsed_args . physical_network : <EOL> attrs [ '<STR_LIT>' ] = parsed_args . physical_network <EOL> if parsed_args . segmentation_id : <EOL> attrs [ '<STR_LIT>' ] = parsed_args . segmentation_id <EOL> return attrs <EOL> def _add_provider_network_options ( parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> choices = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) ) <EOL> def _get_attrs_compute ( client_manager , parsed_args ) : <EOL> attrs = { } <EOL> if parsed_args . name is not None : <EOL> attrs [ '<STR_LIT:label>' ] = str ( parsed_args . name ) <EOL> if parsed_args . share : <EOL> attrs [ '<STR_LIT>' ] = True <EOL> if parsed_args . no_share : <EOL> attrs [ '<STR_LIT>' ] = False <EOL> if parsed_args . subnet is not None : <EOL> attrs [ '<STR_LIT>' ] = parsed_args . subnet <EOL> return attrs <EOL> class CreateNetwork ( common . NetworkAndComputeShowOne ) : <EOL> """<STR_LIT>""" <EOL> def update_parser_common ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT:name>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> share_group = parser . add_mutually_exclusive_group ( ) <EOL> share_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = None , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> share_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> return parser <EOL> def update_parser_network ( self , parser ) : <EOL> admin_group = parser . add_mutually_exclusive_group ( ) <EOL> admin_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = True , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> admin_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <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> action = '<STR_LIT>' , <EOL> dest = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) <EOL> external_router_grp = parser . add_mutually_exclusive_group ( ) <EOL> external_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) <EOL> external_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> default_router_grp = parser . add_mutually_exclusive_group ( ) <EOL> default_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) <EOL> default_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) <EOL> _add_provider_network_options ( parser ) <EOL> return parser <EOL> def update_parser_compute ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> return parser <EOL> def take_action_network ( self , client , parsed_args ) : <EOL> attrs = _get_attrs ( self . app . client_manager , parsed_args ) <EOL> obj = client . create_network ( ** attrs ) <EOL> columns = _get_columns ( obj ) <EOL> data = utils . get_item_properties ( obj , columns , formatters = _formatters ) <EOL> return ( columns , data ) <EOL> def take_action_compute ( self , client , parsed_args ) : <EOL> attrs = _get_attrs_compute ( self . app . client_manager , parsed_args ) <EOL> obj = client . networks . create ( ** attrs ) <EOL> columns = _get_columns ( obj . _info ) <EOL> data = utils . get_dict_properties ( obj . _info , columns ) <EOL> return ( columns , data ) <EOL> class DeleteNetwork ( common . NetworkAndComputeCommand ) : <EOL> """<STR_LIT>""" <EOL> def update_parser_common ( self , parser ) : <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_network ( self , client , parsed_args ) : <EOL> for network in parsed_args . network : <EOL> obj = client . find_network ( network ) <EOL> client . delete_network ( obj ) <EOL> def take_action_compute ( self , client , parsed_args ) : <EOL> for network in parsed_args . network : <EOL> network = utils . find_resource ( <EOL> client . networks , <EOL> network , <EOL> ) <EOL> client . networks . delete ( network . id ) <EOL> class ListNetwork ( common . NetworkAndComputeLister ) : <EOL> """<STR_LIT>""" <EOL> def update_parser_common ( self , parser ) : <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_network ( self , client , parsed_args ) : <EOL> if parsed_args . long : <EOL> columns = ( <EOL> '<STR_LIT:id>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT:status>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> column_headers = ( <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> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> else : <EOL> columns = ( <EOL> '<STR_LIT:id>' , <EOL> '<STR_LIT:name>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> column_headers = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:Name>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> if parsed_args . external : <EOL> args = { '<STR_LIT>' : True } <EOL> else : <EOL> args = { } <EOL> data = client . networks ( ** args ) <EOL> return ( column_headers , <EOL> ( utils . get_item_properties ( <EOL> s , columns , <EOL> formatters = _formatters , <EOL> ) for s in data ) ) <EOL> def take_action_compute ( self , client , parsed_args ) : <EOL> columns = ( <EOL> '<STR_LIT:id>' , <EOL> '<STR_LIT:label>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> column_headers = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:Name>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> data = client . networks . list ( ) <EOL> return ( column_headers , <EOL> ( utils . get_item_properties ( <EOL> s , columns , <EOL> formatters = _formatters , <EOL> ) for s in data ) ) <EOL> class SetNetwork ( command . Command ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( SetNetwork , 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> admin_group = parser . add_mutually_exclusive_group ( ) <EOL> admin_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = None , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> admin_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> share_group = parser . add_mutually_exclusive_group ( ) <EOL> share_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = None , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> share_group . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> external_router_grp = parser . add_mutually_exclusive_group ( ) <EOL> external_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ) <EOL> external_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> default_router_grp = parser . add_mutually_exclusive_group ( ) <EOL> default_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> default_router_grp . add_argument ( <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> _add_provider_network_options ( parser ) <EOL> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> client = self . app . client_manager . network <EOL> obj = client . find_network ( parsed_args . network , ignore_missing = False ) <EOL> attrs = _get_attrs ( self . app . client_manager , parsed_args ) <EOL> if attrs == { } : <EOL> msg = "<STR_LIT>" <EOL> raise exceptions . CommandError ( msg ) <EOL> client . update_network ( obj , ** attrs ) <EOL> class ShowNetwork ( common . NetworkAndComputeShowOne ) : <EOL> """<STR_LIT>""" <EOL> def update_parser_common ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = "<STR_LIT>" , <EOL> help = _ ( "<STR_LIT>" ) <EOL> ) <EOL> return parser <EOL> def take_action_network ( self , client , parsed_args ) : <EOL> obj = client . find_network ( parsed_args . network , ignore_missing = False ) <EOL> columns = _get_columns ( obj ) <EOL> data = utils . get_item_properties ( obj , columns , formatters = _formatters ) <EOL> return ( columns , data ) <EOL> def take_action_compute ( self , client , parsed_args ) : <EOL> obj = utils . find_resource ( <EOL> client . networks , <EOL> parsed_args . network , <EOL> ) <EOL> columns = _get_columns ( obj . _info ) <EOL> data = utils . get_dict_properties ( obj . _info , columns ) <EOL> return ( columns , data ) </s>
