Skip to content

Commit

Permalink
warnet: from_network starts with graph file then adds IPs from docker
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Oct 6, 2023
1 parent 95bde88 commit a6d9869
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
17 changes: 0 additions & 17 deletions src/warnet/tank.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,23 +84,6 @@ def from_graph_node(cls, index, warnet):
self.write_torrc()
return self

@classmethod
def from_docker_compose_service(cls, service, network):
rex = fr"{network}_{CONTAINER_PREFIX_BITCOIND}_([0-9]{{6}})"
match = re.match(rex, service["container_name"])
if match is None:
return None

self = cls()
self.index = int(match.group(1))
self.docker_network = network
self._ipv4 = service["networks"][self.docker_network]["ipv4_address"]
if "BITCOIN_VERSION" in service["build"]["args"]:
self.version = service["build"]["args"]["BITCOIN_VERSION"]
else:
self.version = f"{service['build']['args']['REPO']}#{service['build']['args']['BRANCH']}"
return self

@property
def suffix(self):
if self._suffix is None:
Expand Down
15 changes: 7 additions & 8 deletions src/warnet/warnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,17 @@ def from_network(cls, network_name):
self = cls(config_dir)
self.docker_network = network_name

# Get tank names, versions and IP addresses from docker-compose
# Start with graph file: get version, bitcoin conf, netem
self.graph = networkx.read_graphml(Path(self.config_dir / self.graph_name), node_type=int)
self.tanks_from_graph()

# Update with docker-compose file: get IP addresses
docker_compose_path = self.config_dir / "docker-compose.yml"
compose = None
with open(docker_compose_path, "r") as file:
compose = yaml.safe_load(file)
for service_name in compose["services"]:
tank = Tank.from_docker_compose_service(compose["services"][service_name], network_name)
if tank is not None:
self.tanks.append(tank)
for tank in self.tanks:
tank._ipv4 = compose["services"][tank.container_name]["networks"][self.docker_network]["ipv4_address"]

# Get network graph edges from graph file (required for network restarts)
self.graph = networkx.read_graphml(Path(self.config_dir / self.graph_name), node_type=int)

return self

Expand Down

0 comments on commit a6d9869

Please sign in to comment.