Exemplo n.º 1
0
def build_service_single_qset(service):
    """
    Filter and return the objects associated with a service. Pull in all
    objects the service depends upon.
    """
    dependencies = _get_deps(service, [service])
    dependencies.append(service)

    service_q = objects_to_Q(dependencies)

    system_q = Q(pk__lte=-1)  # by default match nothing
    for s in dependencies:
        system_q = system_q | objects_to_Q(s.systems.all())

    allocation_q = Q(pk__lte=-1)  # by default match nothing
    for s in dependencies:
        allocation_q = allocation_q | objects_to_Q(s.allocations.all())

    # Get necessary services
    result = []
    for name, Klass in searchables:
        if name == 'SERVICE':
            result.append(service_q)
        elif name == 'SYS':
            result.append(system_q)
        elif name == 'ALLOCATION':
            result.append(allocation_q)
        else:
            result.append(None)
    return result
Exemplo n.º 2
0
        * Site
    """
    ip_type, Klass = resolve_ip_type(ip_str)

    NetworkCls = ipaddr.IPv4Network if ip_type == "4" else ipaddr.IPv6Network
    try:
        ip = NetworkCls(ip_str).network
        network_str = str(NetworkCls(ip_str))
    except ipaddr.AddressValueError:
        raise BadDirective("{0} isn't a valid " "IP address.".format(ip_str))
    except ipaddr.NetmaskValueError, e:
        raise BadDirective("The netmask '{0}' doesn't make any sense.".format(e))

    try:
        network = Network.objects.get(network_str=network_str)
        network_q = objects_to_Q([network])
        site = network.site
        vlan = network.vlan
    except Network.DoesNotExist:
        parents, children = calc_networks_str(str(NetworkCls(ip_str)), ip_type)
        network_q = objects_to_Q(parents) | objects_to_Q(children)

        # Find the site. This will be the site of the smallest network that is
        # in parents or if there are no parents, the largest child.
        site = None
        vlan = None
        for parent in reversed(parents):
            if parent.site:
                site = parent.site
                vlan = parent.vlan
                break
Exemplo n.º 3
0
    NetworkCls = ipaddr.IPv4Network if ip_type == '4' else ipaddr.IPv6Network
    try:
        ip = NetworkCls(ip_str).network
        network_str = str(NetworkCls(ip_str))
    except ipaddr.AddressValueError:
        raise BadDirective("{0} isn't a valid "
                           "IP address.".format(ip_str))
    except ipaddr.NetmaskValueError, e:
        raise BadDirective(
            "The netmask '{0}' doesn't make any sense.".format(e)
        )

    try:
        network = Network.objects.get(network_str=network_str)
        network_q = objects_to_Q([network])
        site = network.site
        vlan = network.vlan
    except Network.DoesNotExist:
        parents, children = calc_networks_str(str(NetworkCls(ip_str)), ip_type)
        network_q = objects_to_Q(parents) | objects_to_Q(children)

        # Find the site. This will be the site of the smallest network that is
        # in parents or if there are no parents, the largest child.
        site = None
        vlan = None
        for parent in reversed(parents):
            if parent.site:
                site = parent.site
                vlan = parent.vlan
                break