Add "router add port" to osc

This patch proposes the migration of port addition of
Neutron's "router-interface-add" to OSC's "router add port".

Change-Id: I3a8a76d384caa32975f8e77f50f3cf3c3be13786
Closes-Bug: #1546849
Depends-On: I9783bc4ccceae3d361dce52d51483ef2187920a9
Implements: blueprint neutron-client-advanced-router
This commit is contained in:
reedip 2016-02-18 17:12:05 +09:00 committed by Reedip
parent 752705ae30
commit 2e94f2803f
5 changed files with 95 additions and 3 deletions

View File

@ -4,6 +4,27 @@ router
Network v2 Network v2
router add port
---------------
Add a port to a router
.. program:: router add port
.. code:: bash
os router add port
<router>
<port>
.. _router_add_port:
.. describe:: <router>
Router to which port will be added (name or ID)
.. describe:: <port>
Port to be added (name or ID)
router create router create
------------- -------------
@ -16,7 +37,7 @@ Create new router
[--project <project> [--project-domain <project-domain>]] [--project <project> [--project-domain <project-domain>]]
[--enable | --disable] [--enable | --disable]
[--distributed] [--distributed]
[--availability-zone-hint <availability-zone>] [--availability-zone-hint <availability-zone>]
<name> <name>
.. option:: --project <project> .. option:: --project <project>
@ -146,4 +167,4 @@ Display router details
.. _router_show-router: .. _router_show-router:
.. describe:: <router> .. describe:: <router>
Router to display (name or ID) Router to display (name or ID)

View File

@ -82,6 +82,30 @@ def _get_attrs(client_manager, parsed_args):
return attrs return attrs
class AddPortToRouter(command.Command):
"""Add a port to a router"""
def get_parser(self, prog_name):
parser = super(AddPortToRouter, self).get_parser(prog_name)
parser.add_argument(
'router',
metavar='<router>',
help="Router to which port will be added (name or ID)",
)
parser.add_argument(
'port',
metavar='<port>',
help="Port to be added (name or ID)",
)
return parser
def take_action(self, parsed_args):
client = self.app.client_manager.network
port = client.find_port(parsed_args.port, ignore_missing=False)
client.router_add_interface(client.find_router(
parsed_args.router, ignore_missing=False), port_id=port.id)
class CreateRouter(command.ShowOne): class CreateRouter(command.ShowOne):
"""Create a new router""" """Create a new router"""
@ -318,4 +342,4 @@ class ShowRouter(command.ShowOne):
obj = client.find_router(parsed_args.router, ignore_missing=False) obj = client.find_router(parsed_args.router, ignore_missing=False)
columns = _get_columns(obj) columns = _get_columns(obj)
data = utils.get_item_properties(obj, columns, formatters=_formatters) data = utils.get_item_properties(obj, columns, formatters=_formatters)
return columns, data return columns, data

View File

@ -29,6 +29,47 @@ class TestRouter(network_fakes.TestNetworkV2):
self.network = self.app.client_manager.network self.network = self.app.client_manager.network
class TestAddPortToRouter(TestRouter):
'''Add port to Router '''
_port = network_fakes.FakePort.create_one_port()
_router = network_fakes.FakeRouter.create_one_router(
attrs={'port': _port.id})
def setUp(self):
super(TestAddPortToRouter, self).setUp()
self.network.router_add_interface = mock.Mock()
self.cmd = router.AddPortToRouter(self.app, self.namespace)
self.network.find_router = mock.Mock(return_value=self._router)
self.network.find_port = mock.Mock(return_value=self._port)
def test_add_port_no_option(self):
arglist = []
verifylist = []
# Missing required args should bail here
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
def test_add_port_required_options(self):
arglist = [
self._router.id,
self._router.port,
]
verifylist = [
('router', self._router.id),
('port', self._router.port),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.network.router_add_interface.assert_called_with(self._router, **{
'port_id': self._router.port,
})
self.assertIsNone(result)
class TestCreateRouter(TestRouter): class TestCreateRouter(TestRouter):
# The new router created. # The new router created.

View File

@ -0,0 +1,5 @@
---
features:
- |
Add ``router add port`` command
[Bug `1546849 <https://bugs.launchpad.net/bugs/1546849>`_]

View File

@ -338,6 +338,7 @@ openstack.network.v2 =
port_list = openstackclient.network.v2.port:ListPort port_list = openstackclient.network.v2.port:ListPort
port_show = openstackclient.network.v2.port:ShowPort port_show = openstackclient.network.v2.port:ShowPort
router_add_port = openstackclient.network.v2.router:AddPortToRouter
router_create = openstackclient.network.v2.router:CreateRouter router_create = openstackclient.network.v2.router:CreateRouter
router_delete = openstackclient.network.v2.router:DeleteRouter router_delete = openstackclient.network.v2.router:DeleteRouter
router_list = openstackclient.network.v2.router:ListRouter router_list = openstackclient.network.v2.router:ListRouter