diff options
author | Zuul <zuul@review.opendev.org> | 2023-05-02 15:49:07 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2023-05-02 15:49:07 +0000 |
commit | d342171f9eefc16760ce80fb5bebe3aa2f461d21 (patch) | |
tree | 0be5e070c77cc9177bac803f1a85a9e12c84c813 /neutronclient/osc/v2/dynamic_routing | |
parent | 52653c95e050437b27492404649e42d01b79732b (diff) | |
parent | 0b271d3b8cd1b28e745dd3d1b066c8dc084ef748 (diff) | |
download | python-neutronclient-master.tar.gz |
Diffstat (limited to 'neutronclient/osc/v2/dynamic_routing')
-rw-r--r-- | neutronclient/osc/v2/dynamic_routing/bgp_dragent.py | 89 | ||||
-rw-r--r-- | neutronclient/osc/v2/dynamic_routing/bgp_peer.py | 38 | ||||
-rw-r--r-- | neutronclient/osc/v2/dynamic_routing/bgp_speaker.py | 92 |
3 files changed, 107 insertions, 112 deletions
diff --git a/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py b/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py index 0250229..4af2008 100644 --- a/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py +++ b/neutronclient/osc/v2/dynamic_routing/bgp_dragent.py @@ -15,7 +15,6 @@ from osc_lib.command import command from osc_lib import utils from neutronclient._i18n import _ -from neutronclient.osc.v2.dynamic_routing import constants def _format_alive_state(item): @@ -45,11 +44,9 @@ class AddBgpSpeakerToDRAgent(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - client.add_bgp_speaker_to_dragent( - parsed_args.dragent_id, {'bgp_speaker_id': speaker_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id + client.add_bgp_speaker_to_dragent(parsed_args.dragent_id, speaker_id) class RemoveBgpSpeakerFromDRAgent(command.Command): @@ -62,9 +59,8 @@ class RemoveBgpSpeakerFromDRAgent(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id client.remove_bgp_speaker_from_dragent(parsed_args.dragent_id, speaker_id) @@ -92,18 +88,30 @@ class ListDRAgentsHostingBgpSpeaker(command.Lister): return parser def take_action(self, parsed_args): - search_opts = {} - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - search_opts['bgp_speaker'] = speaker_id - data = client.list_dragents_hosting_bgp_speaker(**search_opts) - headers = ('ID', 'Host', 'State', 'Alive') - columns = ('id', 'host', 'admin_state_up', 'alive') - return (headers, - (utils.get_dict_properties( - s, columns, formatters=_formatters, - ) for s in data['agents'])) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id + data = client.get_bgp_dragents_hosting_speaker(speaker_id) + columns = ( + 'id', + 'agent_type', + 'host', + 'availability_zone', + 'is_alive', + 'is_admin_state_up', + 'binary' + ) + column_headers = ( + 'ID', + 'Agent Type', + 'Host', + 'Availability Zone', + 'Alive', + 'State', + 'Binary' + ) + return (column_headers, + (utils.get_item_properties( + s, columns,) for s in data)) class ListDRAgent(command.Lister): @@ -123,20 +131,31 @@ class ListDRAgent(command.Lister): return parser def take_action(self, parsed_args): - search_opts = {} - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network if parsed_args.bgp_speaker is not None: - search_opts = {} - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - search_opts['bgp_speaker'] = speaker_id - data = client.list_dragents_hosting_bgp_speaker(**search_opts) + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker).id + data = client.get_bgp_dragents_hosting_speaker(speaker_id) else: attrs = {'agent_type': 'BGP dynamic routing agent'} - data = client.list_agents(**attrs) - headers = ('ID', 'Host', 'State', 'Alive') - columns = ('id', 'host', 'admin_state_up', 'alive') - return (headers, - (utils.get_dict_properties( - s, columns, formatters=_formatters, - ) for s in data['agents'])) + data = client.agents(**attrs) + columns = ( + 'id', + 'agent_type', + 'host', + 'availability_zone', + 'is_alive', + 'is_admin_state_up', + 'binary' + ) + column_headers = ( + 'ID', + 'Agent Type', + 'Host', + 'Availability Zone', + 'Alive', + 'State', + 'Binary' + ) + return (column_headers, + (utils.get_item_properties( + s, columns,) for s in data)) diff --git a/neutronclient/osc/v2/dynamic_routing/bgp_peer.py b/neutronclient/osc/v2/dynamic_routing/bgp_peer.py index c8e602e..0610a3a 100644 --- a/neutronclient/osc/v2/dynamic_routing/bgp_peer.py +++ b/neutronclient/osc/v2/dynamic_routing/bgp_peer.py @@ -13,7 +13,6 @@ from osc_lib.command import command from osc_lib import utils -from osc_lib.utils import columns as column_util from neutronclient._i18n import _ from neutronclient.common import exceptions @@ -96,11 +95,10 @@ class CreateBgpPeer(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {constants.BGP_PEER: attrs} - obj = client.create_bgp_peer(body)[constants.BGP_PEER] - columns, display_columns = column_util.get_columns(obj) + obj = client.create_bgp_peer(**attrs) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data @@ -118,9 +116,8 @@ class DeleteBgpPeer(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] + client = self.app.client_manager.network + id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] client.delete_bgp_peer(id) @@ -128,13 +125,11 @@ class ListBgpPeer(command.Lister): _description = _("List BGP peers") def take_action(self, parsed_args): - data = self.app.client_manager.neutronclient.list_bgp_peers() + data = self.app.client_manager.network.bgp_peers(retrieve_all=True) headers = ('ID', 'Name', 'Peer IP', 'Remote AS') columns = ('id', 'name', 'peer_ip', 'remote_as') return (headers, - (utils.get_dict_properties( - s, columns, - ) for s in data[constants.BGP_PEERS])) + (utils.get_dict_properties(s, columns,) for s in data)) class SetBgpPeer(command.Command): @@ -158,13 +153,10 @@ class SetBgpPeer(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] + client = self.app.client_manager.network + id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {} - body[constants.BGP_PEER] = attrs - client.update_bgp_peer(id, body) + client.update_bgp_peer(id, **attrs) class ShowBgpPeer(command.ShowOne): @@ -180,10 +172,10 @@ class ShowBgpPeer(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] - obj = client.show_bgp_peer(id)[constants.BGP_PEER] - columns, display_columns = column_util.get_columns(obj) + client = self.app.client_manager.network + id = client.find_bgp_peer(parsed_args.bgp_peer, + ignore_missing=False).id + obj = client.get_bgp_peer(id) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data diff --git a/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py b/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py index 171d7f4..76d8340 100644 --- a/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py +++ b/neutronclient/osc/v2/dynamic_routing/bgp_speaker.py @@ -13,7 +13,6 @@ from osc_lib.command import command from osc_lib import utils -from osc_lib.utils import columns as column_util from neutronclient._i18n import _ from neutronclient.osc import utils as nc_osc_utils @@ -87,12 +86,12 @@ class AddNetworkToSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - net_id = client.find_resource('network', - parsed_args.network)['id'] - client.add_network_to_bgp_speaker(speaker_id, {'network_id': net_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker, + ignore_missing=False).id + net_id = client.find_network(parsed_args.network, + ignore_missing=False).id + client.add_gateway_network_to_speaker(speaker_id, net_id) class AddPeerToSpeaker(command.Command): @@ -111,12 +110,10 @@ class AddPeerToSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - peer_id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] - client.add_peer_to_bgp_speaker(speaker_id, {'bgp_peer_id': peer_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + peer_id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] + client.add_bgp_peer_to_speaker(speaker_id, peer_id) class CreateBgpSpeaker(command.ShowOne): @@ -145,12 +142,10 @@ class CreateBgpSpeaker(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {} - body[constants.BGP_SPEAKER] = attrs - obj = client.create_bgp_speaker(body)[constants.BGP_SPEAKER] - columns, display_columns = column_util.get_columns(obj) + obj = client.create_bgp_speaker(**attrs) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data @@ -168,9 +163,8 @@ class DeleteBgpSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] + client = self.app.client_manager.network + id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] client.delete_bgp_speaker(id) @@ -186,16 +180,16 @@ class ListBgpSpeaker(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient + client = self.app.client_manager.network if parsed_args.agent is not None: - data = client.list_bgp_speaker_on_dragent(parsed_args.agent) + data = client.get_bgp_speakers_hosted_by_dragent(parsed_args.agent) else: - data = client.list_bgp_speakers() + data = client.bgp_speakers(retrieve_all=True) headers = ('ID', 'Name', 'Local AS', 'IP Version') columns = ('id', 'name', 'local_as', 'ip_version') return (headers, (utils.get_dict_properties(s, columns) - for s in data[constants.BGP_SPEAKERS])) + for s in data)) class ListRoutesAdvertisedBySpeaker(command.Lister): @@ -211,10 +205,9 @@ class ListRoutesAdvertisedBySpeaker(command.Lister): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - data = client.list_route_advertised_from_bgp_speaker(speaker_id) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + data = client.get_advertised_routes_of_speaker(speaker_id) headers = ('Destination', 'Nexthop') columns = ('destination', 'next_hop') return (headers, (utils.get_dict_properties(s, columns) @@ -237,13 +230,10 @@ class RemoveNetworkFromSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - net_id = client.find_resource('network', - parsed_args.network)['id'] - client.remove_network_from_bgp_speaker(speaker_id, - {'network_id': net_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + net_id = client.find_network(parsed_args.network)['id'] + client.remove_gateway_network_from_speaker(speaker_id, net_id) class RemovePeerFromSpeaker(command.Command): @@ -262,13 +252,10 @@ class RemovePeerFromSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - speaker_id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - peer_id = client.find_resource(constants.BGP_PEER, - parsed_args.bgp_peer)['id'] - client.remove_peer_from_bgp_speaker(speaker_id, - {'bgp_peer_id': peer_id}) + client = self.app.client_manager.network + speaker_id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] + peer_id = client.find_bgp_peer(parsed_args.bgp_peer)['id'] + client.remove_bgp_peer_from_speaker(speaker_id, peer_id) class SetBgpSpeaker(command.Command): @@ -290,13 +277,10 @@ class SetBgpSpeaker(command.Command): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] + client = self.app.client_manager.network + id = client.find_bgp_speaker(parsed_args.bgp_speaker)['id'] attrs = _get_attrs(self.app.client_manager, parsed_args) - body = {} - body[constants.BGP_SPEAKER] = attrs - client.update_bgp_speaker(id, body) + client.update_bgp_speaker(id, **attrs) class ShowBgpSpeaker(command.ShowOne): @@ -312,10 +296,10 @@ class ShowBgpSpeaker(command.ShowOne): return parser def take_action(self, parsed_args): - client = self.app.client_manager.neutronclient - id = client.find_resource(constants.BGP_SPEAKER, - parsed_args.bgp_speaker)['id'] - obj = client.show_bgp_speaker(id)[constants.BGP_SPEAKER] - columns, display_columns = column_util.get_columns(obj) + client = self.app.client_manager.network + id = client.find_bgp_speaker(parsed_args.bgp_speaker, + ignore_missing=False).id + obj = client.get_bgp_speaker(id) + display_columns, columns = nc_osc_utils._get_columns(obj) data = utils.get_dict_properties(obj, columns) return display_columns, data |