Newer
Older
import ipaddress
from pydantic import BaseSettings
class V6ServiceNetwork(BaseSettings):
v4: ipaddress.IPv4Network
v6: ipaddress.IPv6Network
class V4HostAddress(BaseSettings):
v6: ipaddress.IPv6Address
class HostAddresses(BaseSettings):
v4: ipaddress.IPv4Address
v6: ipaddress.IPv6Address
def new_service_networks(service_type) -> ServiceNetworks:
v4_service_network = _ipam.allocate_service_ipv4_network(service_type=service_type)
v6_service_network = _ipam.allocate_service_ipv6_network(service_type=service_type)
v4=v4_service_network.v4,
v6=v6_service_network.v6)
def new_service_host(hostname, service_type, service_networks: ServiceNetworks) -> HostAddresses:
return _ipam.allocate_service_host(hostname=hostname, service_type=service_type, service_networks=service_networks)
hostname_A = 'newhost1'
hostname_B = 'newhost2'
lo1_service_networks = new_service_networks('LO')
new_service_host(hostname_A, 'LO', lo1_service_networks)
lo2_service_networks = new_service_networks('LO')
new_service_host(hostname_B, 'LO', lo2_service_networks)
trunk12_service_networks = new_service_networks('TRUNK')
new_service_host(hostname_A, 'TRUNK', trunk12_service_networks)
new_service_host(hostname_B, 'TRUNK', trunk12_service_networks)