# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 OpenStack Foundation
# All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import abc
import netaddr
import os
""" Wrapper around Linux implementation of Dnsmasq."""
plugin=None):
# overrides method in DhcpLocalProcess due to no namespace support
try:
except RuntimeError:
# We ignore local resolv.conf if dns servers are specified
# or if local resolution is explicitly disabled.
_no_resolv = (
cmd = [
'--no-hosts',
'--strict-order',
'--bind-interfaces',
'--except-interface=lo0',
'--pid-file=%s' % pid_file,
'--dhcp-match=set:ipxe,175',
]
possible_leases = 0
mode = None
# if a subnet is specified to have dhcp disabled
if not subnet.enable_dhcp:
continue
mode = 'static'
else:
# We need to also set the DUID for the DHCPv6 server to use
'-co', 'value', '-p', 'mac-address',
# format the MAC address
# IANA assigned ID for Oracle
enterprise_id = '111'
# Note(scollins) If the IPv6 attributes are not set, set it as
# static to preserve previous behavior
mode = 'static'
lease = 'infinite'
else:
# mode is optional and is not set - skip it
if mode:
else:
# Do not advertise unknown mtu
if mtu > 0:
# Cap the limit because creating lots of subnets can inflate
# this possible lease cap.
'--server=%s' % server
try:
except OSError:
else:
return cmd
"""Release a DHCP lease."""
# Note(SridharG) dhcp_release is only supported for IPv4
# addresses. For more details, please refer to man page.
return
if client_id:
# TODO(gmoodalb): need to complete this when we support metadata
# in neutron-dhcp-agent as-well for isolated subnets
pass
# TODO(gmoodalb): need to complete this when we support metadata
# in neutron-dhcp-agent as-well for isolated subnets
return False
"""Sets the default gateway for this dhcp namespace.
This method is idempotent and will only adjust the route if adjusting
it would change it from what it already is. This makes it safe to call
and avoids unnecessary perturbation of the system.
"""
pass
"""Set up the existing DHCP port, if there is one."""
# To avoid pylint thinking that port might be undefined after
# the following loop...
port = None
# Look for an existing DHCP port for this network.
if (port_device_id == device_id or
# If using gateway IPs on this port, we can skip the
# following code, whose purpose is just to review and
# update the Neutron-allocated IP addresses for the
# port.
return port
# Otherwise break out, as we now have the DHCP port
# whose subnets and addresses we need to review.
break
else:
return None
# Compare what the subnets should be against what is already
# on the port.
# If those differ, we need to call update.
# Collect the subnets and fixed IPs that the port already
# has, for subnets that are still in the DHCP-enabled set.
wanted_fixed_ips = []
# Add subnet IDs for new DHCP-enabled subnets.
for s in dhcp_enabled_subnet_ids - port_subnet_ids)
# Update the port to have the calculated subnets and fixed
# IPs. The Neutron server will allocate a fresh IP for
# each subnet that doesn't already have one.
'fixed_ips': wanted_fixed_ips}})
if not port:
raise exceptions.Conflict()
return port
"""Create and initialize a device for network's DHCP on this host."""
else:
try:
None))
except Exception:
with excutils.save_and_reraise_exception():
'network %s. Releasing port.'),
ip_cidrs = []
else:
# For each DHCP-enabled subnet, add that subnet's gateway
# IP address to the Linux device for the DHCP port.
if not subnet.enable_dhcp:
continue
if gateway:
return interface_name