예제 #1
0
def set_route():
    # Get routes, confirm entry does not exist
    routes = netinfo.route_info()

    # If no tools exist and empty dict is returned
    if 'ipv4' not in routes:
        return

    # We only care about IPv4
    routes = routes['ipv4']

    # Searchable list
    dests = []

    # Parse each route into a more searchable format
    for route in routes:
        dests.append(route['destination'])

    gw_present = '100.64.0.0' in dests or '100.64.0.0/10' in dests
    dest_present = '169.254.169.254' in dests

    # If not IPv6 only (No link local)
    # or the route is already present
    if not gw_present or dest_present:
        return

    # Set metadata route
    if subp.which('ip'):
        subp.subp([
            'ip', 'route', 'add', '169.254.169.254/32', 'dev',
            net.find_fallback_nic()
        ])
    elif subp.which('route'):
        subp.subp(['route', 'add', '-net', '169.254.169.254/32', '100.64.0.1'])
예제 #2
0
파일: vultr.py 프로젝트: delphix/cloud-init
def check_route(url):
    # Get routes, confirm entry exists
    routes = netinfo.route_info()

    # If no tools exist and empty dict is returned
    if "ipv4" not in routes:
        return False

    # Parse each route into a more searchable format
    for route in routes["ipv4"]:
        if route.get("destination", None) in url:
            return True

    return False
예제 #3
0
def set_route():
    # Get routes, confirm entry does not exist
    routes = netinfo.route_info()

    # If no tools exist and empty dict is returned
    if "ipv4" not in routes:
        return

    # We only care about IPv4
    routes = routes["ipv4"]

    # Searchable list
    dests = []

    # Parse each route into a more searchable format
    for route in routes:
        dests.append(route["destination"])

    gw_present = "100.64.0.0" in dests or "100.64.0.0/10" in dests
    dest_present = "169.254.169.254" in dests

    # If not IPv6 only (No link local)
    # or the route is already present
    if not gw_present or dest_present:
        return

    # Set metadata route
    if subp.which("ip"):
        subp.subp([
            "ip",
            "route",
            "add",
            "169.254.169.254/32",
            "dev",
            net.find_fallback_nic(),
        ])
    elif subp.which("route"):
        subp.subp(["route", "add", "-net", "169.254.169.254/32", "100.64.0.1"])