mirror of
https://github.com/Cian-H/I-Form_Server_Node_Deployer.git
synced 2025-12-23 06:32:08 +00:00
First prototype of GUI
This commit is contained in:
@@ -39,6 +39,7 @@ mkdocs-material = "^9.4.8"
|
|||||||
|
|
||||||
[tool.poetry.group.gui.dependencies]
|
[tool.poetry.group.gui.dependencies]
|
||||||
flet = "^0.11.0"
|
flet = "^0.11.0"
|
||||||
|
psutil = "^5.9.6"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
11
src/node_deployer_gui/__main__.py
Normal file
11
src/node_deployer_gui/__main__.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import flet as ft
|
||||||
|
|
||||||
|
from . import gui
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
ft.app(target=gui.main)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
37
src/node_deployer_gui/disk_dropdown.py
Normal file
37
src/node_deployer_gui/disk_dropdown.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import flet as ft
|
||||||
|
import psutil
|
||||||
|
from typing import Tuple
|
||||||
|
|
||||||
|
|
||||||
|
def get_disk_options() -> list[ft.dropdown.Option]:
|
||||||
|
physical_disks = list(filter(lambda x: "loop" not in x.device, psutil.disk_partitions()))
|
||||||
|
disks = [
|
||||||
|
ft.dropdown.Option(
|
||||||
|
key=disk.device,
|
||||||
|
text=f"{disk.device} ({disk.mountpoint})",
|
||||||
|
)
|
||||||
|
for disk in physical_disks
|
||||||
|
]
|
||||||
|
return disks
|
||||||
|
|
||||||
|
|
||||||
|
def disk_dropdown(**kwargs) -> Tuple[ft.Dropdown, ft.Row]:
|
||||||
|
dropdown = ft.Dropdown(
|
||||||
|
options=get_disk_options(),
|
||||||
|
**kwargs,
|
||||||
|
)
|
||||||
|
|
||||||
|
def refresh_dropdown(_):
|
||||||
|
dropdown.options = get_disk_options()
|
||||||
|
dropdown.update()
|
||||||
|
|
||||||
|
refresh_button = ft.IconButton(
|
||||||
|
icon="refresh",
|
||||||
|
tooltip="Refresh disk list",
|
||||||
|
on_click=refresh_dropdown,
|
||||||
|
)
|
||||||
|
element = ft.Row(
|
||||||
|
controls=[dropdown, refresh_button],
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
|
)
|
||||||
|
return dropdown, element
|
||||||
@@ -1,17 +1,89 @@
|
|||||||
|
from telnetlib import IP
|
||||||
import flet as ft
|
import flet as ft
|
||||||
|
from httpx import get
|
||||||
|
from node_deployer.create_disk import IPAddress, create_ignition_disk
|
||||||
|
import ipaddress
|
||||||
|
|
||||||
|
from .disk_dropdown import disk_dropdown
|
||||||
|
|
||||||
|
|
||||||
def main(page: ft.Page) -> None:
|
def main(page: ft.Page) -> None:
|
||||||
page.title = "I-Form Server Node Deployer"
|
page.title = "I-Form Server Node Deployer"
|
||||||
|
page.vertical_alignment = ft.MainAxisAlignment.CENTER
|
||||||
|
|
||||||
#TODO: change this test code to the actual gui
|
#TODO: Add a confirmation before actually writing to the disk
|
||||||
# Should basically be a simple wrapper around the node_deployer.py CLI
|
#TODO: Add a private password field
|
||||||
# Should have a file browser for selecting files
|
#TODO: Add a guard against invalid values
|
||||||
# Should have a selector for choosing the disk to write to
|
#TODO: Guard should trigger highlighting of the invalid fields
|
||||||
# Should have checks to ensure valid input
|
#TODO: Add a progress bar
|
||||||
# Should have a progress bar or similar to show progress
|
#TODO: Finalise arrangement of fields
|
||||||
# Intended to be idiot-proof, so anyone can use it
|
|
||||||
# Needs solid error handling and bulletproof documentation/testing
|
disk, dd_element = disk_dropdown(tooltip="Select the disk to write to", label="Disk")
|
||||||
|
hostname = ft.TextField(value="host", label="Hostname", text_align=ft.TextAlign.LEFT)
|
||||||
|
password = ft.TextField(label="Password", text_align=ft.TextAlign.LEFT)
|
||||||
|
switch_ip = ft.TextField(label="Switch IP", text_align=ft.TextAlign.LEFT)
|
||||||
|
switch_port = ft.TextField(label="Switch Port", value="4789", text_align=ft.TextAlign.LEFT)
|
||||||
|
swarm_token = ft.TextField(label="Swarm Token", text_align=ft.TextAlign.LEFT)
|
||||||
|
|
||||||
|
def get_disk() -> str:
|
||||||
|
return disk.value if disk.value is not None else ""
|
||||||
|
|
||||||
|
def get_hostname() -> str:
|
||||||
|
return hostname.value if hostname.value is not None else ""
|
||||||
|
|
||||||
|
def get_password() -> str:
|
||||||
|
return password.value if password.value is not None else ""
|
||||||
|
|
||||||
|
def get_switch_ip() -> IPAddress:
|
||||||
|
return ipaddress.ip_address(switch_ip.value if switch_ip.value is not None else "0.0.0.0")
|
||||||
|
|
||||||
|
def get_switch_port() -> int:
|
||||||
|
return int(switch_port.value if switch_port.value is not None else "0")
|
||||||
|
|
||||||
|
def get_swarm_token() -> str:
|
||||||
|
return swarm_token.value if swarm_token.value is not None else ""
|
||||||
|
|
||||||
|
def trigger_disk_creation(_):
|
||||||
|
raise NotImplementedError
|
||||||
|
create_ignition_disk(
|
||||||
|
disk=get_disk(),
|
||||||
|
hostname=get_hostname(),
|
||||||
|
password=get_password(),
|
||||||
|
switch_ip=get_switch_ip(),
|
||||||
|
switch_port=get_switch_port(),
|
||||||
|
swarm_token=get_swarm_token(),
|
||||||
|
)
|
||||||
|
|
||||||
ft.app(target=main)
|
disk_row = ft.Row(
|
||||||
|
controls=[
|
||||||
|
dd_element,
|
||||||
|
ft.FilledButton(
|
||||||
|
text="Create Ignition Disk",
|
||||||
|
on_click=trigger_disk_creation,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
|
)
|
||||||
|
|
||||||
|
node_row = ft.Row(
|
||||||
|
controls=[
|
||||||
|
hostname,
|
||||||
|
password,
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
|
)
|
||||||
|
|
||||||
|
switch_row = ft.Row(
|
||||||
|
controls=[
|
||||||
|
switch_ip,
|
||||||
|
switch_port,
|
||||||
|
],
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER
|
||||||
|
)
|
||||||
|
|
||||||
|
page.add(
|
||||||
|
ft.Column(
|
||||||
|
[disk_row, node_row, switch_row, swarm_token],
|
||||||
|
alignment=ft.MainAxisAlignment.CENTER,
|
||||||
|
)
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user