Honor uuid parameter passed to nova-network create

The nova api for creating nova-network networks has an optional
request parameter "id" which maps to the string uuid for the
network to create. The nova-manage network create command represents
it as the option --uuid. The parameter is currently being ignored
by the nova-network manager. This change sets the uuid when creating
the network if it has been specified.

Closes-Bug: #1441931

Change-Id: Ib29e632b09905f557a7a6910d58207ed91cdc047
This commit is contained in:
melanie witt 2015-04-09 02:42:01 +00:00
parent 3d30835623
commit 7d88028f74
2 changed files with 17 additions and 0 deletions

View File

@ -1311,6 +1311,9 @@ class NetworkManager(manager.Manager):
subnets = itertools.izip_longest(subnets_v4, subnets_v6)
for index, (subnet_v4, subnet_v6) in enumerate(subnets):
net = objects.Network(context=context)
uuid = kwargs.get('uuid')
if uuid:
net.uuid = uuid
net.bridge = bridge
net.bridge_interface = bridge_interface
net.multi_host = multi_host

View File

@ -2265,6 +2265,20 @@ class CommonNetworkTestCase(test.TestCase):
'fd00::/48', None, None, None, None, None]
self.assertTrue(manager.create_networks(*args))
def test_create_networks_with_uuid(self):
cidr = '192.168.0.0/24'
uuid = FAKEUUID
manager = fake_network.FakeNetworkManager()
self.stubs.Set(manager, '_create_fixed_ips',
self.fake_create_fixed_ips)
args = [self.context.elevated(), 'foo', cidr, None, 1, 256,
'fd00::/48', None, None, None, None, None]
kwargs = {'uuid': uuid}
nets = manager.create_networks(*args, **kwargs)
self.assertEqual(1, len(nets))
net = nets[0]
self.assertEqual(uuid, net['uuid'])
@mock.patch('nova.db.network_get_all')
def test_create_networks_cidr_already_used(self, get_all):
manager = fake_network.FakeNetworkManager()