# @author: Rossella Sblendido, Midokura Japan KK
-from midonetclient import midoapi_exceptions
+from midonetclient import exc
from webob import exc as w_exc
from neutron.common import exceptions as n_exc
try:
return fn(*args, **kwargs)
except (w_exc.HTTPException,
- midoapi_exceptions.MidoApiConnectionError) as ex:
+ exc.MidoApiConnectionError) as ex:
raise MidonetApiException(msg=ex)
return wrapped
raise MidonetResourceNotFound(resource_type='Bridge', id=id)
@handle_api_error
- def create_dhcp(self, bridge, gateway_ip, cidr):
+ def create_dhcp(self, bridge, gateway_ip, cidr, host_rts=None,
+ dns_servers=None):
"""Create a new DHCP entry
:param bridge: bridge object to add dhcp to
:param gateway_ip: IP address of gateway
:param cidr: subnet represented as x.x.x.x/y
+ :param host_rts: list of routes set in the host
+ :param dns_servers: list of dns servers
:returns: newly created dhcp
"""
LOG.debug(_("MidoClient.create_dhcp called: bridge=%(bridge)s, "
- "cidr=%(cidr)s, gateway_ip=%(gateway_ip)s"),
- {'bridge': bridge, 'cidr': cidr, 'gateway_ip': gateway_ip})
- net_addr, net_len = net_util.net_addr(cidr)
- return bridge.add_dhcp_subnet().default_gateway(
- gateway_ip).subnet_prefix(net_addr).subnet_length(
- net_len).create()
+ "cidr=%(cidr)s, gateway_ip=%(gateway_ip)s, "
+ "host_rts=%(host_rts)s, dns_servers=%(dns_servers)s"),
+ {'bridge': bridge, 'cidr': cidr, 'gateway_ip': gateway_ip,
+ 'host_rts': host_rts, 'dns_servers': dns_servers})
+ self.mido_api.add_bridge_dhcp(bridge, gateway_ip, cidr,
+ host_rts=host_rts,
+ dns_nservers=dns_servers)
@handle_api_error
def add_dhcp_host(self, bridge, cidr, ip, mac):
prefix, length = dst_ip.split("/")
routes = [{'destinationPrefix': prefix, 'destinationLength': length,
'gatewayAddr': gw_ip}]
+ cur_routes = subnet.get_opt121_routes()
+ if cur_routes:
+ routes = routes + cur_routes
subnet.opt121_routes(routes).update()
@handle_api_error
from midonetclient import api
from oslo.config import cfg
+from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import exceptions as n_exc
from neutron.common import rpc as n_rpc
"""
LOG.debug(_("MidonetPluginV2.create_subnet called: subnet=%r"), subnet)
- subnet_data = subnet["subnet"]
+ s = subnet["subnet"]
net = super(MidonetPluginV2, self).get_network(
context, subnet['subnet']['network_id'], fields=None)
subnet)
bridge = self.client.get_bridge(sn_entry['network_id'])
- gateway_ip = subnet_data['gateway_ip']
- cidr = subnet_data['cidr']
- self.client.create_dhcp(bridge, gateway_ip, cidr)
+ gateway_ip = s['gateway_ip']
+ cidr = s['cidr']
+ dns_nameservers = None
+ host_routes = None
+ if s['dns_nameservers'] is not attributes.ATTR_NOT_SPECIFIED:
+ dns_nameservers = s['dns_nameservers']
+
+ if s['host_routes'] is not attributes.ATTR_NOT_SPECIFIED:
+ host_routes = s['host_routes']
+
+ self.client.create_dhcp(bridge, gateway_ip, cidr,
+ host_rts=host_routes,
+ dns_servers=dns_nameservers)
# For external network, link the bridge to the provider router.
if net['router:external']:
# Create port chains
port_chains = {}
for d, name in _port_chain_names(
- new_port["id"]).iteritems():
+ new_port["id"]).iteritems():
port_chains[d] = self.client.create_chain(tenant_id,
name)
elif _is_dhcp_port(port_data):
# For DHCP port, add a metadata route
for cidr, ip in self._metadata_subnets(
- context, port_data["fixed_ips"]):
+ context, port_data["fixed_ips"]):
self.client.add_dhcp_route_option(bridge, cidr, ip,
METADATA_DEFAULT_IP)
tenant_id = r["tenant_id"]
if gw_updated:
if (l3_db.EXTERNAL_GW_INFO in r and
- r[l3_db.EXTERNAL_GW_INFO] is not None):
+ r[l3_db.EXTERNAL_GW_INFO] is not None):
# Gateway created
gw_port = self._get_port(context, r["gw_port_id"])
gw_ip = gw_port['fixed_ips'][0]['ip_address']
def test_create_dhcp(self):
bridge = mock.Mock()
- gw_call = mock.call.add_dhcp_subnet().default_gateway("192.168.1.1")
- subnet_prefix_call = gw_call.subnet_prefix("192.168.1.0")
- subnet_length_call = subnet_prefix_call.subnet_length(24)
- calls = [gw_call, subnet_prefix_call, subnet_length_call,
- subnet_length_call.create()]
+ gateway_ip = "192.168.1.1"
+ cidr = "192.168.1.0/24"
+ host_rts = [{'destination': '10.0.0.0/24', 'nexthop': '10.0.0.1'},
+ {'destination': '10.0.1.0/24', 'nexthop': '10.0.1.1'}]
+ dns_servers = ["8.8.8.8", "8.8.4.4"]
- self.client.create_dhcp(bridge, "192.168.1.1", "192.168.1.0/24")
- bridge.assert_has_calls(calls, any_order=True)
+ dhcp_call = mock.call.add_bridge_dhcp(bridge, gateway_ip, cidr,
+ host_rts=host_rts,
+ dns_servers=dns_servers)
+
+ self.client.create_dhcp(bridge, gateway_ip, cidr, host_rts=host_rts,
+ dns_servers=dns_servers)
+
+ bridge.assert_has_call(dhcp_call)
def test_add_dhcp_host(self):