Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add inquirer option to set pullPolicy #639

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 67 additions & 82 deletions src/warnet/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def custom_graph(
fork_obs_query_interval: int,
caddy: bool,
logging: bool,
force_pull: bool,
):
try:
datadir.mkdir(parents=False, exist_ok=False)
Expand Down Expand Up @@ -83,6 +84,10 @@ def custom_graph(
# Configure logging
defaults_yaml_content["collectLogs"] = logging

# Set pullPolicy
if force_pull:
defaults_yaml_content["image"]["pullPolicy"] = "Always"

with open(os.path.join(datadir, "node-defaults.yaml"), "w") as f:
yaml.dump(defaults_yaml_content, f, default_flow_style=False, sort_keys=False)

Expand All @@ -93,110 +98,90 @@ def custom_graph(

def inquirer_create_network(project_path: Path):
# Custom network configuration
questions = [
inquirer.Text(
"network_name",
message=click.style("Enter your network name", fg="blue", bold=True),
validate=lambda _, x: len(x) > 0,
),
inquirer.List(
"nodes",
message=click.style("How many nodes would you like?", fg="blue", bold=True),
choices=["8", "12", "20", "50", "other"],
default="12",
network_name = inquirer.text(
message=click.style("Enter your network name", fg="blue", bold=True),
validate=lambda _, x: len(x) > 0,
)
nodes = inquirer.list_input(
message=click.style("How many nodes would you like?", fg="blue", bold=True),
choices=["8", "12", "20", "50", "other"],
default="12",
)
if nodes == "other":
nodes = inquirer.text(
message=click.style("Enter the number of nodes", fg="blue", bold=True),
validate=lambda _, x: int(x) > 0,
)
connections = inquirer.list_input(
message=click.style(
"How many connections would you like each node to have?",
fg="blue",
bold=True,
),
inquirer.List(
"connections",
message=click.style(
"How many connections would you like each node to have?",
fg="blue",
bold=True,
),
choices=["0", "1", "2", "8", "12", "other"],
default="8",
choices=["0", "1", "2", "8", "12", "other"],
default="8",
)
if connections == "other":
connections = inquirer.text(
message=click.style("Enter the number of connections", fg="blue", bold=True),
validate=lambda _, x: int(x) >= 0,
)
version = inquirer.list_input(
message=click.style(
"Which version would you like nodes to run by default?", fg="blue", bold=True
),
inquirer.List(
"version",
message=click.style(
"Which version would you like nodes to run by default?", fg="blue", bold=True
),
choices=SUPPORTED_TAGS,
default=DEFAULT_TAG,
choices=SUPPORTED_TAGS,
default=DEFAULT_TAG,
)
force_pull = inquirer.confirm(
message=click.style(
"Would you like to force-pull bitcoin node images from dockerhub?", fg="blue", bold=True
),
]

net_answers = inquirer.prompt(questions)
if net_answers is None:
click.secho("Setup cancelled by user.", fg="yellow")
return False
default=False,
)

if net_answers["nodes"] == "other":
custom_nodes = inquirer.prompt(
[
inquirer.Text(
"nodes",
message=click.style("Enter the number of nodes", fg="blue", bold=True),
validate=lambda _, x: int(x) > 0,
)
]
)
if custom_nodes is None:
click.secho("Setup cancelled by user.", fg="yellow")
return False
net_answers["nodes"] = custom_nodes["nodes"]

if net_answers["connections"] == "other":
custom_connections = inquirer.prompt(
[
inquirer.Text(
"connections",
message=click.style("Enter the number of connections", fg="blue", bold=True),
validate=lambda _, x: int(x) >= 0,
)
]
)
if custom_connections is None:
click.secho("Setup cancelled by user.", fg="yellow")
return False
net_answers["connections"] = custom_connections["connections"]
fork_observer = click.prompt(
click.style(
"\nWould you like to enable fork-observer on the network?", fg="blue", bold=True
# Inquire about fork observer
fork_observer = inquirer.confirm(
message=click.style(
"Would you like to enable fork-observer on the network?", fg="blue", bold=True
),
type=bool,
default=True,
)
fork_observer_query_interval = 20
if fork_observer:
fork_observer_query_interval = click.prompt(
click.style(
"\nHow often would you like fork-observer to query node status (seconds)?",
fg="blue",
bold=True,
),
type=int,
default=20,
fork_observer_query_interval = int(
inquirer.text(
message=click.style(
"How often would you like fork-observer to query node status (seconds)?",
fg="blue",
bold=True,
),
validate=lambda _, x: int(x) > 0,
default=fork_observer_query_interval,
)
)

logging = click.prompt(
click.style(
"\nWould you like to enable grafana logging on the network?", fg="blue", bold=True
# Inquire about logging
logging = inquirer.confirm(
message=click.style(
"Would you like to enable grafana logging on the network?", fg="blue", bold=True
),
type=bool,
default=False,
)

caddy = fork_observer | logging
custom_network_path = project_path / "networks" / net_answers["network_name"]
custom_network_path = project_path / "networks" / network_name
click.secho("\nGenerating custom network...", fg="yellow", bold=True)
custom_graph(
int(net_answers["nodes"]),
int(net_answers["connections"]),
net_answers["version"],
int(nodes),
int(connections),
version,
custom_network_path,
fork_observer,
fork_observer_query_interval,
caddy,
logging,
force_pull,
)
return custom_network_path

Expand Down
4 changes: 3 additions & 1 deletion test/graph_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ def directory_exists(self):
self.sut.sendline("")
self.sut.expect("version", timeout=10)
self.sut.sendline("")
self.sut.expect("force-pull", timeout=10)
self.sut.sendline("")
self.sut.expect("enable fork-observer", timeout=10)
self.sut.sendline("")
self.sut.expect("seconds", timeout=10)
self.sut.expect("query node status", timeout=10)
self.sut.sendline("")
self.sut.expect("enable grafana", timeout=10)
self.sut.sendline("")
Expand Down