From 902e0195055099c9ab59567407e5e5a90e80e7e7 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Mon, 18 Apr 2022 10:59:35 +0200 Subject: Add utils modules * disk.py Disk discovery * fs.py Uses psutil to fetch fs usage information * menu.py ogBrowser menu generation * net.py: gets nic status information IP address, MAC address and ethernet speed. * probe.py: probes mountpoints for operating systems Uses hivexget command to try fetching Windows installation information. Looks for /etc/os-release for probing linux systems. --- src/utils/menu.py | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/utils/menu.py (limited to 'src/utils/menu.py') diff --git a/src/utils/menu.py b/src/utils/menu.py new file mode 100644 index 0000000..48e2641 --- /dev/null +++ b/src/utils/menu.py @@ -0,0 +1,58 @@ +# +# Copyright (C) 2022 Soleta Networks +# +# This program is free software: you can redistribute it and/or modify it under +# the terms of the GNU Affero General Public License as published by the +# Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +""" +Utility module for ogBrowser menu generation +""" + +import os +import socket + +from src.utils.net import getifaddr, getifhwaddr, ethtool + +MENU_TEMPLATE = """ +
+

+ + + + + +

Hostname IP MAC SPEED
{hostname} {ip} {mac} {speed}
+

+ +{boot_list} + +

Power Off

+
+""" + +MENU_OS_TEMPLATE = "

Boot {os} ({diskno}, {partno})

" + +def generate_menu(part_setup): + """ + Writes html menu to /opt/opengnsys/log/{ip}.info.html based on a partition + setup + """ + device = os.getenv('DEVICE') + if not device: + return False + + ip = getifaddr(device) + mac = getifhwaddr(device) + speed = ethtool(device) + hostname = socket.gethostname() + menufile = f'/opt/opengnsys/log/{ip}.info.html' + + l = [MENU_OS_TEMPLATE.format(diskno=part['disk'], partno=part['partition'], os=part['os']) + for part in part_setup if part['os']] + boot_list = '\n'.join(l) + + with open(menufile, 'w') as f: + f.write(MENU_TEMPLATE.format(hostname=hostname, ip=ip, mac=mac, speed=speed, boot_list=boot_list)) + return True -- cgit v1.2.3-18-g5258