'Create and initialize a device for network\'s DHCP on this host.'

def setup(self, network):

    try:
        port = self.setup_dhcp_port(network)
    except Exception:
        with excutils.save_and_reraise_exception():
            self._cleanup_stale_devices(network, dhcp_port=None)
    self._update_dhcp_port(network, port)
    interface_name = self.get_interface_name(network, port)
    if network.namespace:
        ip_lib.IPWrapper().ensure_namespace(network.namespace)
    self.driver.configure_ipv6_ra(network.namespace, 'default', n_const.ACCEPT_RA_DISABLED)
    if ip_lib.ensure_device_is_ready(interface_name, namespace=network.namespace):
        LOG.debug('Reusing    existing    device:    %s.', interface_name)
    else:
        try:
            self.plug(network, port, interface_name)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.exception(_LE('Unable    to    plug    DHCP    port    for    network    %s.    Releasing    port.'), network.id)
                self.plugin.release_dhcp_port(network.id, port.device_id)
        self.fill_dhcp_udp_checksums(namespace=network.namespace)
    ip_cidrs = []
    for fixed_ip in port.fixed_ips:
        subnet = fixed_ip.subnet
        net = netaddr.IPNetwork(subnet.cidr)
        ip_cidr = ('%s/%s' % (fixed_ip.ip_address, net.prefixlen))
        ip_cidrs.append(ip_cidr)
    if self.driver.use_gateway_ips:
        for subnet in network.subnets:
            if (not subnet.enable_dhcp):
                continue
            gateway = subnet.gateway_ip
            if gateway:
                net = netaddr.IPNetwork(subnet.cidr)
                ip_cidrs.append(('%s/%s' % (gateway, net.prefixlen)))
    if (self.conf.force_metadata or self.conf.enable_isolated_metadata):
        ip_cidrs.append(METADATA_DEFAULT_CIDR)
    self.driver.init_l3(interface_name, ip_cidrs, namespace=network.namespace)
    self._set_default_route(network, interface_name)
    self._cleanup_stale_devices(network, port)
    return interface_name
