move link local address generation into the RUG

This works around the broken the netaddr implementation packaged with Ubuntu
which contains an algorithmic error.  Later versions of netaddr have
fixed the error, but Canonical has not backported it.
This commit is contained in:
Mark McClain 2012-12-17 12:13:06 -05:00
parent 094293b2ab
commit 650e1f1394
3 changed files with 31 additions and 4 deletions

View File

@ -245,6 +245,15 @@ class AkandaL3Manager(notification.NotificationMixin,
def _get_management_address(router):
prefix, prefix_len = cfg.CONF.management_prefix.split('/', 1)
eui = netaddr.EUI(router.management_port.mac_address)
return str(eui.ipv6_link_local()).replace('fe80::', prefix[:-1])
network = netaddr.IPNetwork(cfg.CONF.management_prefix)
tokens = ['%02x' % int(t, 16)
for t in router.management_port.mac_address.split(':')]
eui64 = int(
''.join(tokens[0:3] + ['ff', 'fe'] + tokens[3:6]),
16
)
# the bit inversion is required by the RFC
return str(netaddr.IPAddress(network.value + (eui64 ^ 0x0200000000000000)))

View File

@ -3,7 +3,7 @@ from setuptools import setup, find_packages
setup(
name='Akanda Router Update Generator',
version='0.1.2',
version='0.1.3',
description='A service that manages tenant Akanda router instances',
author='DreamHost',
author_email='dev-community@dreamhost.com',

18
test/unit/test_manager.py Normal file
View File

@ -0,0 +1,18 @@
import mock
import unittest2 as unittest
from akanda.rug import manager
class TestManager(unittest.TestCase):
def test_get_management_address(self):
with mock.patch.object(manager.cfg, 'CONF') as conf:
conf.management_prefix = 'fdca:3ba5:a17a:acda::/64'
router = mock.Mock()
router.management_port.mac_address = 'fa:16:3e:aa:dc:98'
self.assertEqual(
'fdca:3ba5:a17a:acda:f816:3eff:feaa:dc98',
manager._get_management_address(router)
)