Enable user to configure base mac address.
In addition to this enable the user to configure the amount of retries to generate a unique MAC address Change-Id: Ic109ae65993141c6dc7d63f394066a31e79e2b4c
This commit is contained in:
parent
6edab9de81
commit
f54a788cae
@ -23,3 +23,10 @@ core_plugin = quantum.plugins.sample.SamplePlugin.FakePlugin
|
||||
|
||||
# Paste configuration file
|
||||
api_paste_config = api-paste.ini
|
||||
|
||||
# Base MAC address. The first 3 bytes will remain unchanged. The
|
||||
# lower 3 bytes will be randomly generated.
|
||||
# base_mac = fa:16:3e:00:00:00
|
||||
|
||||
# Maximum amount of retries to generate a unique MAC address
|
||||
# mac_generation_retries = 16
|
||||
|
@ -39,6 +39,8 @@ bind_opts = [
|
||||
cfg.StrOpt('api_extensions_path', default=""),
|
||||
cfg.StrOpt('core_plugin',
|
||||
default='quantum.plugins.sample.SamplePlugin.FakePlugin'),
|
||||
cfg.StrOpt('base_mac', default="fa:16:3e:00:00:00"),
|
||||
cfg.IntOpt('mac_generation_retries', default=16)
|
||||
]
|
||||
|
||||
# Register the configuration options
|
||||
|
@ -24,6 +24,7 @@ from quantum.api.v2 import router as api_router
|
||||
from quantum.common import exceptions as q_exc
|
||||
from quantum.db import api as db
|
||||
from quantum.db import models_v2
|
||||
from quantum.openstack.common import cfg
|
||||
from quantum import quantum_plugin_base_v2
|
||||
|
||||
|
||||
@ -132,11 +133,11 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
|
||||
|
||||
@staticmethod
|
||||
def _generate_mac(context, network_id):
|
||||
# TODO(garyk) read from configuration file (CONF)
|
||||
max_retries = 16
|
||||
base_mac = cfg.CONF.base_mac.split(':')
|
||||
max_retries = cfg.CONF.mac_generation_retries
|
||||
for i in range(max_retries):
|
||||
# TODO(garyk) read base mac from configuration file (CONF)
|
||||
mac = [0xfa, 0x16, 0x3e, random.randint(0x00, 0x7f),
|
||||
mac = [int(base_mac[0], 16), int(base_mac[1], 16),
|
||||
int(base_mac[2], 16), random.randint(0x00, 0x7f),
|
||||
random.randint(0x00, 0xff), random.randint(0x00, 0xff)]
|
||||
mac_address = ':'.join(map(lambda x: "%02x" % x, mac))
|
||||
if QuantumDbPluginV2._check_unique_mac(context, network_id,
|
||||
|
@ -61,6 +61,7 @@ class QuantumDbPluginV2TestCase(unittest.TestCase):
|
||||
config.parse(args=args)
|
||||
# Update the plugin
|
||||
cfg.CONF.set_override('core_plugin', plugin)
|
||||
cfg.CONF.set_override('base_mac', "12:34:56:78:90:ab")
|
||||
self.api = APIRouter()
|
||||
|
||||
def tearDown(self):
|
||||
@ -267,10 +268,8 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
|
||||
with self.port() as port:
|
||||
mac = port['port']['mac_address']
|
||||
# check that MAC address matches base MAC
|
||||
# TODO(garyk) read base mac from configuration file (CONF)
|
||||
base_mac = [0xfa, 0x16, 0x3e]
|
||||
base_mac_address = ':'.join(map(lambda x: "%02x" % x, base_mac))
|
||||
self.assertTrue(mac.startswith(base_mac_address))
|
||||
base_mac = cfg.CONF.base_mac[0:2]
|
||||
self.assertTrue(mac.startswith(base_mac))
|
||||
kwargs = {"mac_address": mac}
|
||||
net_id = port['port']['network_id']
|
||||
res = self._create_port(fmt, net_id=net_id, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user