Skip to content

Commit

Permalink
ipv4: update from cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
pinheadmz committed Aug 20, 2024
1 parent cf7c11b commit 0c2275f
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/warnet/backend/kubernetes_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,8 @@ def create_pod_object(
),
)

def get_ipv4(self, pod_name: str, service_type: ServiceType) -> str | None:
def get_ipv4(self, index: int, service_type: ServiceType) -> str | None:
pod_name = self.get_pod_name(index, service_type)
pod = self.get_pod(pod_name)
if pod:
return pod.status.pod_ip
Expand Down
1 change: 1 addition & 0 deletions src/warnet/cln.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, warnet, tank, backend: KubernetesBackend, options):
self.image = options["ln_image"]
self.cb = options["cb_image"]
self.ln_config = options["ln_config"]
self.ipv4 = None
self.rpc_port = 10009
self.impl = "cln"

Expand Down
1 change: 1 addition & 0 deletions src/warnet/lnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self, warnet, tank, backend: KubernetesBackend, options):
self.image = options["ln_image"]
self.cb = options["cb_image"]
self.ln_config = options["ln_config"]
self.ipv4 = None
self.rpc_port = 10009
self.impl = "lnd"

Expand Down
6 changes: 3 additions & 3 deletions src/warnet/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ def scenario_log(self, proc):
for line in proc.stdout:
self.scenario_logger.info(line.decode().rstrip())

def get_warnet(self, network: str) -> Warnet:
def get_warnet(self, network: str, refresh=False) -> Warnet:
"""
Will get a warnet from the cache if it exists.
Otherwise it will create the network using from_network() and save it
to the cache before returning it.
"""
if network in self.warnets:
if network in self.warnets and not refresh:
return self.warnets[network]
wn = Warnet.from_network(network)
if isinstance(wn, Warnet):
Expand Down Expand Up @@ -515,7 +515,7 @@ def network_info(self, network: str = "warnet") -> dict:
"""
Get info about a warnet network named <network>
"""
wn = self.get_warnet(network)
wn = self.get_warnet(network, refresh=True)
return wn._warnet_dict_representation()

def network_status(self, network: str = "warnet") -> list[dict]:
Expand Down
1 change: 0 additions & 1 deletion src/warnet/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import functools
import ipaddress
import json
import logging
import os
Expand Down
12 changes: 10 additions & 2 deletions src/warnet/warnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,20 @@ def _warnet_dict_representation(self) -> dict:
tank_headers = [
"Index",
"Version",
"IPv4",
"bitcoin conf",
"tc_netem",
"LN",
"LN Image",
"LN IPv4",
]
has_ln = any(tank.lnnode and tank.lnnode.impl for tank in self.tanks)
tanks = []
for tank in self.tanks:
tank_data = [
tank.index,
tank.version if tank.version else tank.image,
tank.ipv4,
tank.bitcoin_config,
tank.netem,
]
Expand All @@ -73,11 +76,13 @@ def _warnet_dict_representation(self) -> dict:
[
tank.lnnode.impl if tank.lnnode else "",
tank.lnnode.image if tank.lnnode else "",
tank.lnnode.ipv4 if tank.lnnode else "",
]
)
tanks.append(tank_data)
if not has_ln:
tank_headers.remove("LN")
tank_headers.remove("LN IPv4")

repr["tank_headers"] = tank_headers
repr["tanks"] = tanks
Expand Down Expand Up @@ -133,8 +138,11 @@ def from_network(cls, network_name):
if "services" in self.graph.graph:
self.services = self.graph.graph["services"].split()
for tank in self.tanks:
pod_name = self.container_interface.get_pod_name(tank.index, ServiceType.BITCOIN)
tank.ipv4 = self.container_interface.get_ipv4(pod_name, ServiceType.BITCOIN)
tank.ipv4 = self.container_interface.get_ipv4(tank.index, ServiceType.BITCOIN)
if tank.lnnode:
tank.lnnode.ipv4 = self.container_interface.get_ipv4(
tank.index, ServiceType.LIGHTNING
)
return self

def tanks_from_graph(self):
Expand Down

0 comments on commit 0c2275f

Please sign in to comment.