73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
from getmac import get_mac_address as gma
|
|
import socket
|
|
import yaml
|
|
import os
|
|
import psutil
|
|
|
|
class MachineData():
|
|
|
|
def get_ip_address(self):
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
|
s.connect(("8.8.8.8", 80))
|
|
return s.getsockname()[0]
|
|
|
|
def __init__(self):
|
|
self.mac_address = gma()
|
|
self.ip_address = str(self.get_ip_address())
|
|
self.hostname = socket.gethostname()
|
|
self.client_version = "v0.0.1alpha"
|
|
self.cpu_count = os.cpu_count()
|
|
self.ram_size = (psutil.virtual_memory().total / 1024) / 1024
|
|
|
|
try:
|
|
with open("config.yml", "r") as stream:
|
|
try:
|
|
config_file = yaml.safe_load(stream)
|
|
except Exception as e:
|
|
print(e)
|
|
except FileNotFoundError as e:
|
|
print(str(e))
|
|
exit(-1)
|
|
config = config_file
|
|
|
|
try:
|
|
server_url_override = os.environ.get("VALHALLA_SERVER_URL")
|
|
server_port_override = os.environ.get("VALHALLA_SERVER_PORT")
|
|
server_password_override = os.environ.get("VALHALLA_SERVER_PASSWORD")
|
|
server_access_username_override = os.environ.get(
|
|
"VALHALLA_SERVER_ACCESS_USERNAME")
|
|
client_logging_override = os.environ.get("VALHALLA_CLIENT_LOGLEVEL")
|
|
|
|
if server_port_override:
|
|
config["server_port"] = server_port_override
|
|
|
|
if server_url_override:
|
|
config["server_url"] = server_url_override
|
|
|
|
if server_password_override:
|
|
config["server_password"] = server_password_override
|
|
|
|
if server_access_username_override:
|
|
config["server_access_username"] = server_access_username_override
|
|
|
|
if client_logging_override:
|
|
config["client_loglevel"] = client_logging_override
|
|
|
|
self.server_url = config["server_url"]
|
|
self.server_port = config["server_port"]
|
|
self.server_password = config["server_password"]
|
|
self.server_access_username = config["server_access_username"]
|
|
self.client_loglevel = config["client_loglevel"]
|
|
except KeyError as ke:
|
|
print(str(ke))
|
|
pass
|
|
except TypeError as te:
|
|
print(str(te))
|
|
pass
|
|
except Exception as e:
|
|
print(str(e))
|
|
exit(-1)
|
|
|
|
class VirtualmachineConfig():
|
|
def __init__(cpu_count: int, memory_size: int, ):
|