def _is_port_physnet_allowed(port, physnets):
    """Check whether a port's physical network is allowed for a VIF.

    Supports VIFs on networks with no physical network configuration by
    allowing all ports regardless of their physical network. This will be the
    case when the port is not a neutron port because we're in standalone mode
    or not using neutron.

    Allows ports with physical_network=None to ensure backwards compatibility
    and provide support for simple deployments with no physical network
    configuration in ironic.

    When the physnets set is not empty and the port's physical_network field is
    not None, the port's physical_network field must be present in the physnets
    set.

    :param port: A Port object to check.
    :param physnets: Set of physical networks on which the VIF may be
        attached. This is governed by the segments of the VIF's network. An
        empty set indicates that the ports' physical networks should be
        ignored.
    :returns: True if the port's physical network is allowed, False otherwise.
    """
    return (not physnets
            or port.physical_network is None
            or port.physical_network in physnets)