Add get_neutron_port_name
This patch adds get_neutron_port_name to generate the Neutron port name. Change-Id: I31928ba344ba14c8a0e8d77e74f035494fd30fcb Signed-off-by: Taku Fukushima <f.tac.mac@gmail.com>
This commit is contained in:
parent
6787e0e2fa
commit
15b3cfa3d9
@ -29,3 +29,11 @@ class TestKuryrUtils(base.TestKuryrBase):
|
||||
sandbox_key = utils.get_sandbox_key(fake_container_id)
|
||||
expected = '/'.join([utils.DOCKER_NETNS_BASE, fake_container_id[:12]])
|
||||
self.assertEqual(expected, sandbox_key)
|
||||
|
||||
def test_get_port_name(self):
|
||||
fake_docker_endpoint_id = hashlib.sha256(
|
||||
str(random.getrandbits(256))).hexdigest()
|
||||
generated_neutron_port_name = utils.get_neutron_port_name(
|
||||
fake_docker_endpoint_id)
|
||||
self.assertTrue(utils.PORT_POSTFIX in generated_neutron_port_name)
|
||||
self.assertTrue(fake_docker_endpoint_id in generated_neutron_port_name)
|
||||
|
@ -23,6 +23,7 @@ from werkzeug import exceptions as w_exceptions
|
||||
|
||||
|
||||
DOCKER_NETNS_BASE = '/var/run/docker/netns'
|
||||
PORT_POSTFIX = 'port'
|
||||
|
||||
|
||||
def get_neutron_client_simple(url, token):
|
||||
@ -90,3 +91,12 @@ def get_sandbox_key(container_id):
|
||||
:returns: the constructed sandbox key as string
|
||||
"""
|
||||
return os.path.join(DOCKER_NETNS_BASE, container_id[:12])
|
||||
|
||||
|
||||
def get_neutron_port_name(docker_endpoint_id):
|
||||
"""Returns a Neutron port name.
|
||||
|
||||
:param docker_endpoint_id: the EndpointID
|
||||
:returns: the Neutron port name formatted appropriately
|
||||
"""
|
||||
return '-'.join([docker_endpoint_id, PORT_POSTFIX])
|
||||
|
Loading…
x
Reference in New Issue
Block a user