Example #1
0
def _find_vlan(vlan_type, vlan_spec):
    """Return a single public or private vlan matching spec"""
    log.debug("looking up %s vlan %s", vlan_type, vlan_spec)
    vlan_object_mask = build_vlan_object_mask()
    if vlan_type == 'public':
        # Lookup Public VLAN
        vlans = list(get_public_vlans(
            parse_vlan_spec(vlan_spec), vlan_object_mask))
    elif vlan_type == 'private':
        # Lookup Public VLAN
        vlans = list(get_private_vlans(
            parse_vlan_spec(vlan_spec), vlan_object_mask))
    else:
        raise TypeError("Unknown vlan type: %s" % (vlan_type))

    if len(vlans) < 1:
        print error("No vlans found matching spec: %s" % (vlan_spec))
        sys.exit(1)

    if len(vlans) > 1:
        print error("More then one vlan found matching spec: %s. "
                    "Refusing to continue." % (vlan_spec))
        sys.exit(1)

    return vlans[0]
Example #2
0
def _find_vlan(vlan_type, vlan_spec):
    """Return a single public or private vlan matching spec"""
    log.debug("looking up %s vlan %s", vlan_type, vlan_spec)
    vlan_object_mask = build_vlan_object_mask()
    if vlan_type == 'public':
        # Lookup Public VLAN
        vlans = list(
            get_public_vlans(parse_vlan_spec(vlan_spec), vlan_object_mask))
    elif vlan_type == 'private':
        # Lookup Public VLAN
        vlans = list(
            get_private_vlans(parse_vlan_spec(vlan_spec), vlan_object_mask))
    else:
        raise TypeError("Unknown vlan type: %s" % (vlan_type))

    if len(vlans) < 1:
        print error("No vlans found matching spec: %s" % (vlan_spec))
        sys.exit(1)

    if len(vlans) > 1:
        print error("More then one vlan found matching spec: %s. "
                    "Refusing to continue." % (vlan_spec))
        sys.exit(1)

    return vlans[0]
Example #3
0
def vlans(args):
    """Show VLANs

    Usage: slapi network vlans [options] [<vlan_spec>]

    Options:
        -p, --public                Filter for ublic VLANs
        -x, --private               Filter for private VLANs
        -l, --location LOCATION     Filter VLANs in LOCATION (e.g. dal05)
        -s, --subnets               Show subnets attached to VLANS
        -F, --format FORMAT
        -h, --help
    """
    # Parse vlan spec
    vlan_spec = parse_vlan_spec(args['<vlan_spec>'])
    object_mask = build_vlan_object_mask(
        include_subnets=(args['--subnets'] is True))

    # Parse args
    if args['--public']:
        # get public vlans
        vlanlist = get_public_vlans(vlan_spec, object_mask)
    elif args['--private']:
        # get private vlans
        vlanlist = get_private_vlans(vlan_spec, object_mask)
    else:
        # get all vlans
        vlanlist = get_vlans(vlan_spec, object_mask)

    # Filter vlans by location of primary router
    if args['--location'] is not None:
        filter_func = lambda vlan: vlan.primary_router.datacenter.name == args[
            '--location']
    else:
        filter_func = lambda vlan: True

    for vlan in filter(filter_func, vlanlist):
        print vlan.format()
Example #4
0
def vlans(args):
    """Show VLANs

    Usage: slapi network vlans [options] [<vlan_spec>]

    Options:
        -p, --public                Filter for ublic VLANs
        -x, --private               Filter for private VLANs
        -l, --location LOCATION     Filter VLANs in LOCATION (e.g. dal05)
        -s, --subnets               Show subnets attached to VLANS
        -F, --format FORMAT
        -h, --help
    """
    # Parse vlan spec
    vlan_spec = parse_vlan_spec(args['<vlan_spec>'])
    object_mask = build_vlan_object_mask(
        include_subnets=(args['--subnets'] is True))

    # Parse args
    if args['--public']:
        # get public vlans
        vlanlist = get_public_vlans(vlan_spec, object_mask)
    elif args['--private']:
        # get private vlans
        vlanlist = get_private_vlans(vlan_spec, object_mask)
    else:
        # get all vlans
        vlanlist = get_vlans(vlan_spec, object_mask)

    # Filter vlans by location of primary router
    if args['--location'] is not None:
        filter_func = lambda vlan: vlan.primary_router.datacenter.name == args['--location']
    else:
        filter_func = lambda vlan: True

    for vlan in filter(filter_func, vlanlist):
        print vlan.format()