summaryrefslogtreecommitdiff
path: root/nova/network/manager.py
diff options
context:
space:
mode:
authorAlvaro Lopez Garcia <aloga@ifca.unican.es>2013-07-17 13:20:33 +0200
committerAlvaro Lopez Garcia <aloga@ifca.unican.es>2013-08-27 13:49:49 +0200
commitec4a9490047106b36c8a6bdf91fc7579b84868dd (patch)
tree313b15625c09b538eebe64ceba8c24f40442e3c8 /nova/network/manager.py
parent8c10cd17e474b4d124288d7cd182710ebc7209c0 (diff)
downloadnova-ec4a9490047106b36c8a6bdf91fc7579b84868dd.tar.gz
Fix network creation in Vlan mode
- If "vlan" is specified when creating a network, we honour the option. - If it is not specified, the Vlan number is calculated as follows: CONF.vlan_start + num_existing_networks + index_of_requested_network - If the above vlan is in use, try to get the next free vlan. Fixes bug 1194835 Fixes bug 1169026 Change-Id: Id4476c14f9dadcf498a499534337477b3f64f604
Diffstat (limited to 'nova/network/manager.py')
-rw-r--r--nova/network/manager.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/nova/network/manager.py b/nova/network/manager.py
index 33e0c625ca..8273cba70e 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -1094,6 +1094,7 @@ class NetworkManager(manager.Manager):
nets = self.db.network_get_all(context)
except exception.NoNetworksFound:
nets = []
+ num_used_nets = len(nets)
used_subnets = [netaddr.IPNetwork(net['cidr']) for net in nets]
def find_next(subnet):
@@ -1166,9 +1167,17 @@ class NetworkManager(manager.Manager):
net['netmask_v6'] = str(subnet_v6._prefixlen)
- if kwargs.get('vpn', False):
- # this bit here is for vlan-manager
- vlan = kwargs['vlan_start'] + index
+ if CONF.network_manager == 'nova.network.manager.VlanManager':
+ vlan = kwargs.get('vlan', None)
+ if not vlan:
+ index_vlan = index + num_used_nets
+ vlan = kwargs['vlan_start'] + index_vlan
+ used_vlans = [x['vlan'] for x in nets]
+ if vlan in used_vlans:
+ # That vlan is used, try to get another one
+ used_vlans.sort()
+ vlan = used_vlans[-1] + 1
+
net['vpn_private_address'] = str(subnet_v4[2])
net['dhcp_start'] = str(subnet_v4[3])
net['vlan'] = vlan
@@ -1176,7 +1185,8 @@ class NetworkManager(manager.Manager):
# NOTE(vish): This makes ports unique across the cloud, a more
# robust solution would be to make them uniq per ip
- net['vpn_public_port'] = kwargs['vpn_start'] + index
+ index_vpn = index + num_used_nets
+ net['vpn_public_port'] = kwargs['vpn_start'] + index_vpn
# None if network with cidr or cidr_v6 already exists
network = self.db.network_create_safe(context, net)