Module paracrine.helpers.network

Expand source code
from typing import Dict

from .config import host, network_config, other_config, servers


def networks_by_interface(h):
    return dict([(intf["ifname"], intf) for intf in network_config(h["name"])])


def get_ipv4(network):
    addrs = network["addr_info"]
    for addr in addrs:
        if addr["family"] == "inet" and addr["local"] != "":
            return addr["local"]
    return None


def external_ip(h):
    return other_config(h["name"])["external_ip"]


def external_ips():
    return dict([(h["name"], external_ip(h)) for h in servers()])


def wireguard_ips() -> Dict[str, str]:
    return dict([(h["name"], h["wireguard_ip"]) for h in servers()])


def wireguard_ip():
    return host()["wireguard_ip"]


def ips_for_network(net):
    return [
        x for x in [get_ipv4(intf) for (name, intf) in net.items()] if x is not None
    ]


def ips(h):
    network = networks_by_interface(h)
    return ips_for_network(network)

Functions

def external_ip(h)
Expand source code
def external_ip(h):
    return other_config(h["name"])["external_ip"]
def external_ips()
Expand source code
def external_ips():
    return dict([(h["name"], external_ip(h)) for h in servers()])
def get_ipv4(network)
Expand source code
def get_ipv4(network):
    addrs = network["addr_info"]
    for addr in addrs:
        if addr["family"] == "inet" and addr["local"] != "":
            return addr["local"]
    return None
def ips(h)
Expand source code
def ips(h):
    network = networks_by_interface(h)
    return ips_for_network(network)
def ips_for_network(net)
Expand source code
def ips_for_network(net):
    return [
        x for x in [get_ipv4(intf) for (name, intf) in net.items()] if x is not None
    ]
def networks_by_interface(h)
Expand source code
def networks_by_interface(h):
    return dict([(intf["ifname"], intf) for intf in network_config(h["name"])])
def wireguard_ip()
Expand source code
def wireguard_ip():
    return host()["wireguard_ip"]
def wireguard_ips() ‑> Dict[str, str]
Expand source code
def wireguard_ips() -> Dict[str, str]:
    return dict([(h["name"], h["wireguard_ip"]) for h in servers()])