Merge "Add/Remove port interface to a router"
This commit is contained in:
@@ -1090,11 +1090,41 @@ class Proxy(proxy.BaseProxy):
|
||||
"""
|
||||
return self._update(_router.Router, router, **attrs)
|
||||
|
||||
def router_add_interface(self, router, subnet_id):
|
||||
router.add_interface(self.session, subnet_id)
|
||||
def router_add_interface(self, router, subnet_id=None, port_id=None):
|
||||
"""Add Interface to a router
|
||||
|
||||
def router_remove_interface(self, router, subnet_id):
|
||||
router.remove_interface(self.session, subnet_id)
|
||||
:param router: Either the router ID or an instance of
|
||||
:class:`~openstack.network.v2.router.Router`
|
||||
:param subnet_id: ID of the subnet
|
||||
:param port_id: ID of the port
|
||||
:returns: Router with updated interface
|
||||
:rtype: :class: `~openstack.network.v2.router.Router`
|
||||
"""
|
||||
|
||||
body = {}
|
||||
if port_id:
|
||||
body = {'port_id': port_id}
|
||||
else:
|
||||
body = {'subnet_id': subnet_id}
|
||||
return router.add_interface(self.session, **body)
|
||||
|
||||
def router_remove_interface(self, router, subnet_id=None, port_id=None):
|
||||
"""Remove Interface from a router
|
||||
|
||||
:param router: Either the router ID or an instance of
|
||||
:class:`~openstack.network.v2.router.Router`
|
||||
:param subnet: ID of the subnet
|
||||
:param port: ID of the port
|
||||
:returns: Router with updated interface
|
||||
:rtype: :class: `~openstack.network.v2.router.Router`
|
||||
"""
|
||||
|
||||
body = {}
|
||||
if port_id:
|
||||
body = {'port_id': port_id}
|
||||
else:
|
||||
body = {'subnet_id': subnet_id}
|
||||
return router.remove_interface(self.session, **body)
|
||||
|
||||
def create_security_group(self, **attrs):
|
||||
"""Create a new security group from attributes
|
||||
|
@@ -55,30 +55,28 @@ class Router(resource.Resource):
|
||||
# The extra routes configuration for the router.
|
||||
routes = resource.prop('routes', type=list)
|
||||
|
||||
def add_interface(self, session, subnet_id):
|
||||
def add_interface(self, session, **body):
|
||||
"""Add an internal interface to a logical router.
|
||||
|
||||
:param session: The session to communicate through.
|
||||
:type session: :class:`~openstack.session.Session`
|
||||
:param str subnet_id: The ID of a subnet to add.
|
||||
:param dict body : The body requested to be updated on the outer
|
||||
|
||||
:returns: The body of the response as a dictionary.
|
||||
"""
|
||||
body = {'subnet_id': subnet_id}
|
||||
url = utils.urljoin(self.base_path, self.id, 'add_router_interface')
|
||||
resp = session.put(url, endpoint_filter=self.service, json=body)
|
||||
return resp.json()
|
||||
|
||||
def remove_interface(self, session, subnet_id):
|
||||
def remove_interface(self, session, **body):
|
||||
"""Remove an internal interface from a logical router.
|
||||
|
||||
:param session: The session to communicate through.
|
||||
:type session: :class:`~openstack.session.Session`
|
||||
:param str subnet_id: The ID of a subnet to remove.
|
||||
:param dict body : The body requested to be updated on the outer
|
||||
|
||||
:returns: The body of the response as a dictionary.
|
||||
"""
|
||||
body = {'subnet_id': subnet_id}
|
||||
url = utils.urljoin(self.base_path, self.id, 'remove_router_interface')
|
||||
resp = session.put(url, endpoint_filter=self.service, json=body)
|
||||
return resp.json()
|
||||
|
@@ -95,32 +95,63 @@ class TestRouter(testtools.TestCase):
|
||||
self.assertEqual(EXAMPLE_WITH_OPTIONAL['availability_zones'],
|
||||
sot.availability_zones)
|
||||
|
||||
def test_add_interface(self):
|
||||
def test_add_interface_subnet(self):
|
||||
# Add subnet to a router
|
||||
sot = router.Router(EXAMPLE)
|
||||
response = mock.Mock()
|
||||
response.body = {"subnet_id": "3", "port_id": "2"}
|
||||
response.json = mock.Mock(return_value=response.body)
|
||||
sess = mock.Mock()
|
||||
sess.put = mock.Mock(return_value=response)
|
||||
|
||||
self.assertEqual(response.body, sot.add_interface(sess, '3'))
|
||||
body = {"subnet_id": "3"}
|
||||
self.assertEqual(response.body, sot.add_interface(sess, **body))
|
||||
|
||||
url = 'routers/IDENTIFIER/add_router_interface'
|
||||
body = {"subnet_id": "3"}
|
||||
sess.put.assert_called_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
||||
def test_remove_interface(self):
|
||||
def test_add_interface_port(self):
|
||||
# Add port to a router
|
||||
sot = router.Router(EXAMPLE)
|
||||
response = mock.Mock()
|
||||
response.body = {"subnet_id": "3", "port_id": "3"}
|
||||
response.json = mock.Mock(return_value=response.body)
|
||||
sess = mock.Mock()
|
||||
sess.put = mock.Mock(return_value=response)
|
||||
|
||||
body = {"port_id": "3"}
|
||||
self.assertEqual(response.body, sot.add_interface(sess, **body))
|
||||
|
||||
url = 'routers/IDENTIFIER/add_router_interface'
|
||||
sess.put.assert_called_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
||||
def test_remove_interface_subnet(self):
|
||||
# Remove subnet from a router
|
||||
sot = router.Router(EXAMPLE)
|
||||
response = mock.Mock()
|
||||
response.body = {"subnet_id": "3", "port_id": "2"}
|
||||
response.json = mock.Mock(return_value=response.body)
|
||||
sess = mock.Mock()
|
||||
sess.put = mock.Mock(return_value=response)
|
||||
|
||||
self.assertEqual(response.body, sot.remove_interface(sess, '3'))
|
||||
body = {"subnet_id": "3"}
|
||||
self.assertEqual(response.body, sot.remove_interface(sess, **body))
|
||||
|
||||
url = 'routers/IDENTIFIER/remove_router_interface'
|
||||
sess.put.assert_called_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
||||
def test_remove_interface_port(self):
|
||||
# Remove port from a router
|
||||
sot = router.Router(EXAMPLE)
|
||||
response = mock.Mock()
|
||||
response.body = {"subnet_id": "3", "port_id": "3"}
|
||||
response.json = mock.Mock(return_value=response.body)
|
||||
sess = mock.Mock()
|
||||
sess.put = mock.Mock(return_value=response)
|
||||
body = {"port_id": "3"}
|
||||
self.assertEqual(response.body, sot.remove_interface(sess, **body))
|
||||
|
||||
url = 'routers/IDENTIFIER/remove_router_interface'
|
||||
body = {"subnet_id": "3"}
|
||||
sess.put.assert_called_with(url, endpoint_filter=sot.service,
|
||||
json=body)
|
||||
|
Reference in New Issue
Block a user