Fully working locally

This commit is contained in:
Cian Hughes
2023-10-24 15:31:36 +01:00
parent 4cf0e4267c
commit 2a8d3c21fe
10 changed files with 620 additions and 228 deletions

69
main.py
View File

@@ -1,16 +1,18 @@
import json
import ipaddress
import typer
import json
from typing import Annotated
from automated_webapp import json_to_img
import typer
from autoignition import json_to_img
from debug import debug_mode
MAX_PORT: int = 65535
def load_template() -> dict:
with open("templates/fuel-ignition.json", "r") as f:
with open("templates/fuelignition.json", "r") as f:
out = json.load(f)
return out
@@ -49,7 +51,7 @@ def apply_ignition_settings(
"data_content": swarm_script,
},
]
ignition_config["systemd"] = ignition_config.get("systemd", {})
ignition_config["systemd"]["units"] = ignition_config["systemd"].get("units", [])
ignition_config["systemd"]["units"] += [
@@ -63,28 +65,8 @@ def apply_ignition_settings(
return ignition_config
def main(
hostname: Annotated[
str, typer.Option(help="Hostname for the new node", prompt=True)
],
password: Annotated[
str,
typer.Option(
help="Password for the root user on the new node",
prompt=True,
confirmation_prompt=True,
hide_input=True,
),
],
switch_ip_address: Annotated[
str, typer.Option(help="IP address of the switch to connect to", prompt=True)
],
switch_port: Annotated[
int, typer.Option(help="Port on the switch to connect to", prompt=True)
],
swarm_token: Annotated[
str, typer.Option(help="Swarm token for connecting to the swarm", prompt=True)
],
def create_img(
hostname: str, password: str, switch_ip_address: str, switch_port: str, swarm_token: str
) -> None:
switch_ip_address = ipaddress.ip_address(switch_ip_address)
if switch_port > MAX_PORT:
@@ -109,11 +91,38 @@ def main(
)
# export ignition configuration
with open("build/fuel-ignition.json", "w") as f:
with open("build/fuelignition.json", "w") as f:
json.dump(ignition_config, f, indent=4)
# convert ignition configuration to image
json_to_img("build/fuel-ignition.json", "build/ignition.img")
json_to_img("build/fuelignition.json", "build/ignition.img")
def main(
hostname: Annotated[str, typer.Option(help="Hostname for the new node", prompt=True)],
password: Annotated[
str,
typer.Option(
help="Password for the root user on the new node",
prompt=True,
confirmation_prompt=True,
hide_input=True,
),
],
switch_ip_address: Annotated[
str, typer.Option(help="IP address of the switch to connect to", prompt=True)
],
switch_port: Annotated[int, typer.Option(help="Port on the switch to connect to", prompt=True)],
swarm_token: Annotated[
str, typer.Option(help="Swarm token for connecting to the swarm", prompt=True)
],
debug: Annotated[bool, typer.Option(help="Enable debug mode")] = False,
) -> None:
debug_mode(debug)
f = create_img
if debug:
f = ss(f) # noqa: F821, # type: ignore #? ss is installed in debug_mode
f(hostname, password, switch_ip_address, switch_port, swarm_token)
if __name__ == "__main__":