Skip to content

Commit 0ae986b

Browse files
committed
refactor network.py
1 parent 8d61293 commit 0ae986b

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

src/warnet/network.py

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,21 @@
11
import json
22
import shutil
3-
from importlib.resources import files
43
from pathlib import Path
54

65
from rich import print
76

87
from .bitcoin import _rpc
8+
from .constants import (
9+
LOGGING_HELM_COMMANDS,
10+
NETWORK_DIR,
11+
SCENARIOS_DIR,
12+
)
913
from .k8s import get_mission
1014
from .process import stream_command
1115

12-
WAR_MANIFESTS_FILES = files("resources.manifests")
13-
WAR_NETWORK_FILES = files("resources.networks")
14-
WAR_SCENARIOS_FILES = files("resources.scenarios")
15-
16-
WAR_NETWORK_DIR = WAR_NETWORK_FILES.name
17-
WAR_SCENARIOS_DIR = WAR_SCENARIOS_FILES.name
18-
19-
DEFAULT_NETWORK = Path("6_node_bitcoin")
20-
NETWORK_FILE = "network.yaml"
21-
DEFAULTS_FILE = "node-defaults.yaml"
22-
HELM_COMMAND = "helm upgrade --install --create-namespace"
23-
BITCOIN_CHART_LOCATION = str(files("resources.charts").joinpath("bitcoincore"))
24-
FORK_OBSERVER_CHART = str(files("resources.charts").joinpath("fork-observer"))
25-
2616

2717
def setup_logging_helm() -> bool:
28-
helm_commands = [
29-
"helm repo add grafana https://grafana.github.io/helm-charts",
30-
"helm repo add prometheus-community https://prometheus-community.github.io/helm-charts",
31-
"helm repo update",
32-
f"helm upgrade --install --namespace warnet-logging --create-namespace --values {WAR_MANIFESTS_FILES}/loki_values.yaml loki grafana/loki --version 5.47.2",
33-
"helm upgrade --install --namespace warnet-logging promtail grafana/promtail",
34-
"helm upgrade --install --namespace warnet-logging prometheus prometheus-community/kube-prometheus-stack --namespace warnet-logging --set grafana.enabled=false",
35-
f"helm upgrade --install --namespace warnet-logging loki-grafana grafana/grafana --values {WAR_MANIFESTS_FILES}/grafana_values.yaml",
36-
]
37-
38-
for command in helm_commands:
18+
for command in LOGGING_HELM_COMMANDS:
3919
if not stream_command(command):
4020
print(f"Failed to run Helm command: {command}")
4121
return False
@@ -67,8 +47,8 @@ def copy_network_defaults(directory: Path):
6747
"""Create the project structure for a warnet project's network"""
6848
copy_defaults(
6949
directory,
70-
WAR_NETWORK_DIR,
71-
WAR_NETWORK_FILES.joinpath(),
50+
NETWORK_DIR.name,
51+
NETWORK_DIR,
7252
["node-defaults.yaml", "__pycache__", "__init__.py"],
7353
)
7454

@@ -77,8 +57,8 @@ def copy_scenario_defaults(directory: Path):
7757
"""Create the project structure for a warnet project's scenarios"""
7858
copy_defaults(
7959
directory,
80-
WAR_SCENARIOS_DIR,
81-
WAR_SCENARIOS_FILES.joinpath(),
60+
SCENARIOS_DIR.name,
61+
SCENARIOS_DIR,
8262
["__init__.py", "__pycache__", "commander.py"],
8363
)
8464

0 commit comments

Comments
 (0)