Deprecate openstack-based code in DHCP
nsxlib code should not be aware of openstack structures. This logic will move to vmware-nsx codebase. Change-Id: I149dca673c7d450339bf8b92931aa7cef44743ff
This commit is contained in:
parent
6971dd9726
commit
0779c8ed40
@ -34,25 +34,22 @@ class TestNativeDhcp(nsxlib_testcase.NsxLibTestCase):
|
|||||||
tags=None, gateway_ip='2.2.2.2', cidr='5.5.0.0/24',
|
tags=None, gateway_ip='2.2.2.2', cidr='5.5.0.0/24',
|
||||||
port_ip='5.5.0.1', net_name='dummy',
|
port_ip='5.5.0.1', net_name='dummy',
|
||||||
net_id='dummy_uuid'):
|
net_id='dummy_uuid'):
|
||||||
net = {'name': net_name, 'id': net_id}
|
name = self.handler.build_server_name(net_name, net_id)
|
||||||
subnet = {'dns_nameservers': None,
|
|
||||||
'gateway_ip': gateway_ip,
|
|
||||||
'cidr': cidr,
|
|
||||||
'host_routes': []}
|
|
||||||
port = {'fixed_ips': [{'ip_address': port_ip}]}
|
|
||||||
if not tags:
|
if not tags:
|
||||||
tags = []
|
tags = []
|
||||||
if with_net_dns:
|
|
||||||
net['dns_domain'] = {'dns_domain': self.net_dns_domain}
|
dns_domain = None
|
||||||
subnet['dns_nameservers'] = [self.subnet_dns_nameserver]
|
dns_nameservers = None
|
||||||
if with_default_dns:
|
if with_default_dns:
|
||||||
result = self.handler.build_server_config(
|
dns_domain = self.default_dns_domain
|
||||||
net, subnet, port, tags,
|
dns_nameservers = [self.default_dns_nameserver]
|
||||||
default_dns_nameservers=[self.default_dns_nameserver],
|
if with_net_dns:
|
||||||
default_dns_domain=self.default_dns_domain)
|
dns_domain = self.net_dns_domain
|
||||||
else:
|
dns_nameservers = [self.subnet_dns_nameserver]
|
||||||
result = self.handler.build_server_config(net, subnet, port, tags)
|
|
||||||
return result
|
return self.handler.build_server(name, port_ip, cidr, gateway_ip,
|
||||||
|
dns_domain, dns_nameservers,
|
||||||
|
tags=tags)
|
||||||
|
|
||||||
def test_build_server_config_dns_from_net_no_defaults(self):
|
def test_build_server_config_dns_from_net_no_defaults(self):
|
||||||
# Verify that net/subnet dns params are used if exist
|
# Verify that net/subnet dns params are used if exist
|
||||||
|
@ -16,10 +16,16 @@
|
|||||||
import netaddr
|
import netaddr
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
from oslo_log import log
|
||||||
|
from oslo_log import versionutils
|
||||||
|
|
||||||
from vmware_nsxlib.v3 import constants
|
from vmware_nsxlib.v3 import constants
|
||||||
from vmware_nsxlib.v3 import utils
|
from vmware_nsxlib.v3 import utils
|
||||||
|
|
||||||
|
|
||||||
|
LOG = log.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class NsxLibNativeDhcp(utils.NsxLibApiBase):
|
class NsxLibNativeDhcp(utils.NsxLibApiBase):
|
||||||
|
|
||||||
def build_static_routes(self, gateway_ip, cidr, host_routes):
|
def build_static_routes(self, gateway_ip, cidr, host_routes):
|
||||||
@ -29,13 +35,15 @@ class NsxLibNativeDhcp(utils.NsxLibApiBase):
|
|||||||
# Add route for directly connected network.
|
# Add route for directly connected network.
|
||||||
static_routes = [{'network': cidr, 'next_hop': '0.0.0.0'}]
|
static_routes = [{'network': cidr, 'next_hop': '0.0.0.0'}]
|
||||||
# Copy routes from subnet host_routes attribute.
|
# Copy routes from subnet host_routes attribute.
|
||||||
for hr in host_routes:
|
if host_routes:
|
||||||
if hr['destination'] == constants.IPv4_ANY:
|
for hr in host_routes:
|
||||||
if not gateway_ip:
|
if hr['destination'] == constants.IPv4_ANY:
|
||||||
gateway_ip = hr['nexthop']
|
if not gateway_ip:
|
||||||
else:
|
gateway_ip = hr['nexthop']
|
||||||
static_routes.append({'network': hr['destination'],
|
else:
|
||||||
'next_hop': hr['nexthop']})
|
static_routes.append({'network': hr['destination'],
|
||||||
|
'next_hop': hr['nexthop']})
|
||||||
|
|
||||||
# If gateway_ip is defined, add default route via this gateway.
|
# If gateway_ip is defined, add default route via this gateway.
|
||||||
if gateway_ip:
|
if gateway_ip:
|
||||||
static_routes.append({'network': constants.IPv4_ANY,
|
static_routes.append({'network': constants.IPv4_ANY,
|
||||||
@ -46,6 +54,10 @@ class NsxLibNativeDhcp(utils.NsxLibApiBase):
|
|||||||
return utils.get_name_and_uuid(net_name or 'dhcpserver', net_id)
|
return utils.get_name_and_uuid(net_name or 'dhcpserver', net_id)
|
||||||
|
|
||||||
def build_server_domain_name(self, net_dns_domain, default_dns_domain):
|
def build_server_domain_name(self, net_dns_domain, default_dns_domain):
|
||||||
|
versionutils.report_deprecated_feature(
|
||||||
|
LOG,
|
||||||
|
'NsxLibQosNativeDhcp.build_server_domain_name is deprecated.')
|
||||||
|
|
||||||
if net_dns_domain:
|
if net_dns_domain:
|
||||||
if isinstance(net_dns_domain, six.string_types):
|
if isinstance(net_dns_domain, six.string_types):
|
||||||
domain_name = net_dns_domain
|
domain_name = net_dns_domain
|
||||||
@ -59,9 +71,52 @@ class NsxLibNativeDhcp(utils.NsxLibApiBase):
|
|||||||
domain_name = self.nsxlib_config.dns_domain
|
domain_name = self.nsxlib_config.dns_domain
|
||||||
return domain_name
|
return domain_name
|
||||||
|
|
||||||
|
def build_server(self, name, ip_address, cidr, gateway_ip,
|
||||||
|
dns_domain=None, dns_nameservers=None,
|
||||||
|
host_routes=None,
|
||||||
|
dhcp_profile_id=None,
|
||||||
|
tags=None):
|
||||||
|
|
||||||
|
# Prepare the configuration for a new logical DHCP server.
|
||||||
|
server_ip = "%s/%u" % (ip_address,
|
||||||
|
netaddr.IPNetwork(cidr).prefixlen)
|
||||||
|
|
||||||
|
if not dns_domain:
|
||||||
|
dns_domain = self.nsxlib_config.dns_domain
|
||||||
|
|
||||||
|
if not dns_nameservers:
|
||||||
|
dns_nameservers = self.nsxlib_config.dns_nameservers
|
||||||
|
|
||||||
|
if not utils.is_attr_set(gateway_ip):
|
||||||
|
gateway_ip = None
|
||||||
|
|
||||||
|
static_routes, gateway_ip = self.build_static_routes(
|
||||||
|
gateway_ip, cidr, host_routes)
|
||||||
|
|
||||||
|
options = {'option121': {'static_routes': static_routes}}
|
||||||
|
|
||||||
|
body = {'name': name,
|
||||||
|
'server_ip': server_ip,
|
||||||
|
'dns_nameservers': dns_nameservers,
|
||||||
|
'domain_name': dns_domain,
|
||||||
|
'gateway_ip': gateway_ip,
|
||||||
|
'options': options,
|
||||||
|
'tags': tags}
|
||||||
|
|
||||||
|
if dhcp_profile_id:
|
||||||
|
body['dhcp_profile_id'] = dhcp_profile_id
|
||||||
|
|
||||||
|
return body
|
||||||
|
|
||||||
def build_server_config(self, network, subnet, port, tags,
|
def build_server_config(self, network, subnet, port, tags,
|
||||||
default_dns_nameservers=None,
|
default_dns_nameservers=None,
|
||||||
default_dns_domain=None):
|
default_dns_domain=None):
|
||||||
|
|
||||||
|
versionutils.report_deprecated_feature(
|
||||||
|
LOG,
|
||||||
|
'NsxLibQosNativeDhcp.build_server_config is deprecated. '
|
||||||
|
'Please use build_server instead')
|
||||||
|
|
||||||
# Prepare the configuration for a new logical DHCP server.
|
# Prepare the configuration for a new logical DHCP server.
|
||||||
server_ip = "%s/%u" % (port['fixed_ips'][0]['ip_address'],
|
server_ip = "%s/%u" % (port['fixed_ips'][0]['ip_address'],
|
||||||
netaddr.IPNetwork(subnet['cidr']).prefixlen)
|
netaddr.IPNetwork(subnet['cidr']).prefixlen)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user