'Create/update DHCP port for the host if needed and return port.'

def setup_dhcp_port(self, network):

    device_id = self.get_device_id(network)
    dhcp_subnets = {subnet.id: subnet for subnet in network.subnets if subnet.enable_dhcp}
    for setup_method in (self._setup_existing_dhcp_port, self._setup_reserved_dhcp_port, self._setup_new_dhcp_port):
        dhcp_port = setup_method(network, device_id, dhcp_subnets)
        if dhcp_port:
            break
    else:
        raise exceptions.Conflict()
    if (not self.driver.use_gateway_ips):
        expected = set(dhcp_subnets)
        actual = {fip.subnet_id for fip in dhcp_port.fixed_ips}
        missing = (expected - actual)
        if missing:
            LOG.debug('Requested    DHCP    port    with    IPs    on    subnets    %(expected)s    but    only    got    IPs    on    subnets    %(actual)s.', {'expected': expected, 'actual': actual})
            raise exceptions.SubnetMismatchForPort(port_id=dhcp_port.id, subnet_id=list(missing)[0])
    fixed_ips = [dict(subnet_id=fixed_ip.subnet_id, ip_address=fixed_ip.ip_address, subnet=dhcp_subnets[fixed_ip.subnet_id]) for fixed_ip in dhcp_port.fixed_ips if (fixed_ip.subnet_id in dhcp_subnets)]
    ips = [(DictModel(item) if isinstance(item, dict) else item) for item in fixed_ips]
    dhcp_port.fixed_ips = ips
    return dhcp_port
