<s> from __future__ import print_function <EOL> from neutronclient . _i18n import _ <EOL> from neutronclient . common import utils <EOL> from neutronclient . common import validators <EOL> from neutronclient . neutron import v2_0 as neutronv20 <EOL> from neutronclient . neutron . v2_0 . bgp import peer as bgp_peer <EOL> MIN_AS_NUM = <NUM_LIT:1> <EOL> MAX_AS_NUM = <NUM_LIT> <EOL> def get_network_id ( client , id_or_name ) : <EOL> return neutronv20 . find_resourceid_by_name_or_id ( client , <EOL> '<STR_LIT>' , <EOL> id_or_name ) <EOL> def get_bgp_speaker_id ( client , id_or_name ) : <EOL> return neutronv20 . find_resourceid_by_name_or_id ( client , <EOL> '<STR_LIT>' , <EOL> id_or_name ) <EOL> def validate_speaker_attributes ( parsed_args ) : <EOL> validators . validate_int_range ( parsed_args , '<STR_LIT>' , <EOL> MIN_AS_NUM , MAX_AS_NUM ) <EOL> def add_common_arguments ( parser ) : <EOL> utils . add_boolean_argument ( <EOL> parser , '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> utils . add_boolean_argument ( <EOL> parser , '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> def args2body_common_arguments ( body , parsed_args ) : <EOL> neutronv20 . update_dict ( parsed_args , body , <EOL> [ '<STR_LIT:name>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] ) <EOL> class ListSpeakers ( neutronv20 . ListCommand ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> list_columns = [ '<STR_LIT:id>' , '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> pagination_support = True <EOL> sorting_support = True <EOL> class ShowSpeaker ( neutronv20 . ShowCommand ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> class CreateSpeaker ( neutronv20 . CreateCommand ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> def add_known_arguments ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT:name>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> required = True , <EOL> help = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) % { '<STR_LIT>' : MIN_AS_NUM , <EOL> '<STR_LIT>' : MAX_AS_NUM } ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> type = int , choices = [ <NUM_LIT:4> , <NUM_LIT:6> ] , <EOL> default = <NUM_LIT:4> , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> add_common_arguments ( parser ) <EOL> def args2body ( self , parsed_args ) : <EOL> body = { } <EOL> validate_speaker_attributes ( parsed_args ) <EOL> body [ '<STR_LIT>' ] = parsed_args . local_as <EOL> body [ '<STR_LIT>' ] = parsed_args . ip_version <EOL> args2body_common_arguments ( body , parsed_args ) <EOL> return { self . resource : body } <EOL> class UpdateSpeaker ( neutronv20 . UpdateCommand ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> def add_known_arguments ( self , parser ) : <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> add_common_arguments ( parser ) <EOL> def args2body ( self , parsed_args ) : <EOL> body = { } <EOL> args2body_common_arguments ( body , parsed_args ) <EOL> return { self . resource : body } <EOL> class DeleteSpeaker ( neutronv20 . DeleteCommand ) : <EOL> """<STR_LIT>""" <EOL> resource = '<STR_LIT>' <EOL> class AddPeerToSpeaker ( neutronv20 . NeutronCommand ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( AddPeerToSpeaker , 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> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> neutron_client = self . get_client ( ) <EOL> _speaker_id = get_bgp_speaker_id ( neutron_client , <EOL> parsed_args . bgp_speaker ) <EOL> _peer_id = bgp_peer . get_bgp_peer_id ( neutron_client , <EOL> parsed_args . bgp_peer ) <EOL> neutron_client . add_peer_to_bgp_speaker ( _speaker_id , <EOL> { '<STR_LIT>' : _peer_id } ) <EOL> print ( _ ( '<STR_LIT>' ) % <EOL> { '<STR_LIT>' : parsed_args . bgp_peer , <EOL> '<STR_LIT>' : parsed_args . bgp_speaker } , <EOL> file = self . app . stdout ) <EOL> class RemovePeerFromSpeaker ( neutronv20 . NeutronCommand ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( RemovePeerFromSpeaker , 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> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> neutron_client = self . get_client ( ) <EOL> _speaker_id = get_bgp_speaker_id ( neutron_client , <EOL> parsed_args . bgp_speaker ) <EOL> _peer_id = bgp_peer . get_bgp_peer_id ( neutron_client , <EOL> parsed_args . bgp_peer ) <EOL> neutron_client . remove_peer_from_bgp_speaker ( _speaker_id , <EOL> { '<STR_LIT>' : _peer_id } ) <EOL> print ( _ ( '<STR_LIT>' ) % <EOL> { '<STR_LIT>' : parsed_args . bgp_peer , <EOL> '<STR_LIT>' : parsed_args . bgp_speaker } , <EOL> file = self . app . stdout ) <EOL> class AddNetworkToSpeaker ( neutronv20 . NeutronCommand ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( AddNetworkToSpeaker , 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> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> neutron_client = self . get_client ( ) <EOL> _speaker_id = get_bgp_speaker_id ( neutron_client , <EOL> parsed_args . bgp_speaker ) <EOL> _net_id = get_network_id ( neutron_client , <EOL> parsed_args . network ) <EOL> neutron_client . add_network_to_bgp_speaker ( _speaker_id , <EOL> { '<STR_LIT>' : _net_id } ) <EOL> print ( _ ( '<STR_LIT>' ) % <EOL> { '<STR_LIT>' : parsed_args . network , '<STR_LIT>' : parsed_args . bgp_speaker } , <EOL> file = self . app . stdout ) <EOL> class RemoveNetworkFromSpeaker ( neutronv20 . NeutronCommand ) : <EOL> """<STR_LIT>""" <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( RemoveNetworkFromSpeaker , 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> return parser <EOL> def take_action ( self , parsed_args ) : <EOL> neutron_client = self . get_client ( ) <EOL> _speaker_id = get_bgp_speaker_id ( neutron_client , <EOL> parsed_args . bgp_speaker ) <EOL> _net_id = get_network_id ( neutron_client , <EOL> parsed_args . network ) <EOL> neutron_client . remove_network_from_bgp_speaker ( _speaker_id , <EOL> { '<STR_LIT>' : _net_id } ) <EOL> print ( _ ( '<STR_LIT>' ) % <EOL> { '<STR_LIT>' : parsed_args . network , '<STR_LIT>' : parsed_args . bgp_speaker } , <EOL> file = self . app . stdout ) <EOL> class ListRoutesAdvertisedBySpeaker ( neutronv20 . ListCommand ) : <EOL> """<STR_LIT>""" <EOL> list_columns = [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> resource = '<STR_LIT>' <EOL> pagination_support = True <EOL> sorting_support = True <EOL> def get_parser ( self , prog_name ) : <EOL> parser = super ( ListRoutesAdvertisedBySpeaker , <EOL> self ) . get_parser ( prog_name ) <EOL> parser . add_argument ( <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> return parser <EOL> def call_server ( self , neutron_client , search_opts , parsed_args ) : <EOL> _speaker_id = get_bgp_speaker_id ( neutron_client , <EOL> parsed_args . bgp_speaker ) <EOL> data = neutron_client . list_route_advertised_from_bgp_speaker ( <EOL> _speaker_id , ** search_opts ) <EOL> return data </s>
