removed bridge subnet collisions
This commit is contained in:
parent
e47e058c3f
commit
3e777bde92
@ -136,7 +136,7 @@ class ProxmoxRunner:
|
|||||||
def build(self, bridge: structure.Bridge):
|
def build(self, bridge: structure.Bridge):
|
||||||
bridges, nodes = bridge_node_search(bridge, lambda x: self._create_bridge(x), lambda x: self._create_node(x))
|
bridges, nodes = bridge_node_search(bridge, lambda x: self._create_bridge(x), lambda x: self._create_node(x))
|
||||||
|
|
||||||
self._build_bridges()
|
self._build_bridges(bridges)
|
||||||
|
|
||||||
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
build_futures = [executor.submit(self._build_node, node) for node in nodes]
|
build_futures = [executor.submit(self._build_node, node) for node in nodes]
|
||||||
@ -177,10 +177,16 @@ class ProxmoxRunner:
|
|||||||
self._created_bridges.append(bridge_name)
|
self._created_bridges.append(bridge_name)
|
||||||
return bridge_name
|
return bridge_name
|
||||||
|
|
||||||
def _build_bridges(self):
|
def _build_bridges(self, bridges: List[structure.Bridge]):
|
||||||
network_task = self._proxmox.nodes(self._proxmox_node).network.put()
|
network_task = self._proxmox.nodes(self._proxmox_node).network.put()
|
||||||
self._await_task(network_task)
|
self._await_task(network_task)
|
||||||
|
|
||||||
|
existing = []
|
||||||
|
for bridge in bridges:
|
||||||
|
while True in [ipaddress.ip_network(bridge.get_network()).overlaps(x) for x in existing]:
|
||||||
|
bridge.new_network()
|
||||||
|
existing.append(bridge.get_network())
|
||||||
|
|
||||||
def _create_node(self, node: structure.Node) -> int:
|
def _create_node(self, node: structure.Node) -> int:
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -69,8 +69,7 @@ class Bridge:
|
|||||||
|
|
||||||
# Generate a random class c private range by default (10.0.0.0)
|
# Generate a random class c private range by default (10.0.0.0)
|
||||||
self.netmask = 24
|
self.netmask = 24
|
||||||
self._addr: ipaddress.ip_address = ipaddress.ip_address('10.0.0.0') + random.randint(0, 16777216)
|
self.new_network()
|
||||||
self._network_iterator = ipaddress.ip_network('{}/{}'.format(self._addr, self.netmask), False).hosts()
|
|
||||||
|
|
||||||
def get_interfaces(self) -> List[Interface]:
|
def get_interfaces(self) -> List[Interface]:
|
||||||
return self._interfaces
|
return self._interfaces
|
||||||
@ -88,9 +87,16 @@ class Bridge:
|
|||||||
def get_ip_address(self) -> ipaddress.ip_address:
|
def get_ip_address(self) -> ipaddress.ip_address:
|
||||||
return next(self._network_iterator)
|
return next(self._network_iterator)
|
||||||
|
|
||||||
def get_network(self) -> str:
|
def get_network(self) -> ipaddress.ip_network:
|
||||||
|
return ipaddress.ip_network('{}/{}'.format(self._addr, self.netmask), False)
|
||||||
|
|
||||||
|
def get_network_string(self) -> str:
|
||||||
return str(ipaddress.ip_network('{}/{}'.format(self._addr, self.netmask), False))
|
return str(ipaddress.ip_network('{}/{}'.format(self._addr, self.netmask), False))
|
||||||
|
|
||||||
|
def new_network(self):
|
||||||
|
self._addr: ipaddress.ip_address = ipaddress.ip_address('10.0.0.0') + random.randint(0, 16777216)
|
||||||
|
self._network_iterator = ipaddress.ip_network('{}/{}'.format(self._addr, self.netmask), False).hosts()
|
||||||
|
|
||||||
|
|
||||||
class Node:
|
class Node:
|
||||||
def __init__(self, interfaces: List[Interface], setup_params: Dict = None):
|
def __init__(self, interfaces: List[Interface], setup_params: Dict = None):
|
||||||
@ -291,7 +297,7 @@ class LocalPortal(Node):
|
|||||||
policy_routing = '\n\n'.join([policy_routing_string.format(
|
policy_routing = '\n\n'.join([policy_routing_string.format(
|
||||||
table_number=i + 10,
|
table_number=i + 10,
|
||||||
device='eth{}'.format(i),
|
device='eth{}'.format(i),
|
||||||
network=iface.get_bridge().get_network(),
|
network=iface.get_bridge().get_network_string(),
|
||||||
local_address=iface.get_address(),
|
local_address=iface.get_address(),
|
||||||
) for i, iface in enumerate(self.get_interfaces()[:-2])])
|
) for i, iface in enumerate(self.get_interfaces()[:-2])])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user