Add ip_version for NeutronNetwork subnet
Change-Id: I84791c93319dbd70fde436cc538b0e776e2a2a6d
This commit is contained in:
parent
b40e458c5f
commit
81acfe0f17
|
@ -23,6 +23,10 @@ Properties:
|
|||
name:
|
||||
Contract: $.string().notNull()
|
||||
|
||||
ipVersion:
|
||||
Contract: $.int()
|
||||
Default: 4
|
||||
|
||||
externalRouterId:
|
||||
Contract: $.string()
|
||||
Usage: InOut
|
||||
|
@ -58,14 +62,14 @@ Methods:
|
|||
- $netExplorer: $._getNetExplorer()
|
||||
- If: len($.dnsNameservers) = 0
|
||||
Then:
|
||||
- $.dnsNameservers: $netExplorer.getDefaultDns()
|
||||
- $.dnsNameservers: $netExplorer.getDefaultDns($.ipVersion)
|
||||
- $template: $._createNetwork()
|
||||
- If: $.autoUplink and (not bool($.externalRouterId))
|
||||
Then:
|
||||
- $.externalRouterId: $netExplorer.getDefaultRouter()
|
||||
- If: $.autogenerateSubnet and (not bool($.subnetCidr))
|
||||
Then:
|
||||
- $.subnetCidr: $netExplorer.getAvailableCidr($.externalRouterId, id($))
|
||||
- $.subnetCidr: $netExplorer.getAvailableCidr($.externalRouterId, id($), $.ipVersion)
|
||||
|
||||
- $template: $template.mergeWith($._createSubnet())
|
||||
- If: $.externalRouterId != null
|
||||
|
@ -105,7 +109,7 @@ Methods:
|
|||
type: 'OS::Neutron::Subnet'
|
||||
properties:
|
||||
network: { get_resource: $._getNetworkName() }
|
||||
ip_version: 4
|
||||
ip_version: $.ipVersion
|
||||
dns_nameservers: $.dnsNameservers
|
||||
cidr: $.subnetCidr
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ from netaddr.strategy import ipv4
|
|||
import neutronclient.v2_0.client as nclient
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log as logging
|
||||
from oslo_utils import netutils
|
||||
from oslo_utils import uuidutils
|
||||
import tenacity
|
||||
|
||||
|
@ -107,7 +108,7 @@ class NetworkExplorer(object):
|
|||
router_id = routers[0]['id']
|
||||
return router_id
|
||||
|
||||
def get_available_cidr(self, router_id, net_id):
|
||||
def get_available_cidr(self, router_id, net_id, ip_version=4):
|
||||
"""Uses hash of network IDs to minimize the collisions
|
||||
|
||||
Different nets will attempt to pick different cidrs out of available
|
||||
|
@ -117,6 +118,11 @@ class NetworkExplorer(object):
|
|||
taken_cidrs = self._get_cidrs_taken_by_router(router_id)
|
||||
id_hash = hash(net_id)
|
||||
num_fails = 0
|
||||
available_ipv6_cidrs = []
|
||||
if ip_version == 6:
|
||||
for cidr in self._available_cidrs:
|
||||
available_ipv6_cidrs.append(cidr.ipv6())
|
||||
self._available_cidrs = available_ipv6_cidrs
|
||||
while num_fails < len(self._available_cidrs):
|
||||
cidr = self._available_cidrs[
|
||||
(id_hash + num_fails) % len(self._available_cidrs)]
|
||||
|
@ -127,8 +133,18 @@ class NetworkExplorer(object):
|
|||
return str(cidr)
|
||||
return None
|
||||
|
||||
def get_default_dns(self):
|
||||
return self._settings.default_dns
|
||||
def get_default_dns(self, ip_version=4):
|
||||
dns_list = self._settings.default_dns
|
||||
valid_dns = []
|
||||
for ip in dns_list:
|
||||
if ip_version == 6 and netutils.is_valid_ipv6(ip):
|
||||
valid_dns.append(ip)
|
||||
elif ip_version == 4 and netutils.is_valid_ipv4(ip):
|
||||
valid_dns.append(ip)
|
||||
else:
|
||||
LOG.warning('{0} is not a vaild IPV{1} address, '
|
||||
'ingore...'.format(ip, ip_version))
|
||||
return valid_dns
|
||||
|
||||
def get_external_network_id_for_router(self, router_id):
|
||||
router = self._client.show_router(router_id).get('router')
|
||||
|
|
Loading…
Reference in New Issue