mirror of
https://github.com/azaion/ai-training.git
synced 2026-04-23 03:46:35 +00:00
make hardware_service works on linux
This commit is contained in:
+2
-2
@@ -60,7 +60,7 @@ class ApiClient:
|
|||||||
print(f"Upload fail: {e}")
|
print(f"Upload fail: {e}")
|
||||||
|
|
||||||
def load_bytes(self, filename, folder):
|
def load_bytes(self, filename, folder):
|
||||||
hardware = get_hardware_info()
|
hardware_str = get_hardware_info()
|
||||||
|
|
||||||
if self.token is None:
|
if self.token is None:
|
||||||
self.login()
|
self.login()
|
||||||
@@ -73,7 +73,7 @@ class ApiClient:
|
|||||||
payload = json.dumps(
|
payload = json.dumps(
|
||||||
{
|
{
|
||||||
"password": self.credentials.password,
|
"password": self.credentials.password,
|
||||||
"hardware": hardware.to_json_object(),
|
"hardware": hardware_str,
|
||||||
"fileName": filename
|
"fileName": filename
|
||||||
}, indent=4)
|
}, indent=4)
|
||||||
response = requests.post(url, data=payload, headers=headers, stream=True)
|
response = requests.post(url, data=payload, headers=headers, stream=True)
|
||||||
|
|||||||
+18
-48
@@ -1,65 +1,35 @@
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import psutil
|
|
||||||
|
|
||||||
|
|
||||||
class HardwareInfo:
|
|
||||||
def __init__(self, cpu, gpu, memory, mac_address):
|
|
||||||
self.cpu = cpu
|
|
||||||
self.gpu = gpu
|
|
||||||
self.memory = memory
|
|
||||||
self.mac_address = mac_address
|
|
||||||
|
|
||||||
def to_json_object(self):
|
|
||||||
return {
|
|
||||||
"CPU": self.cpu,
|
|
||||||
"GPU": self.gpu,
|
|
||||||
"MacAddress": self.mac_address,
|
|
||||||
"Memory": self.memory
|
|
||||||
}
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return f'CPU: {self.cpu}. GPU: {self.gpu}. Memory: {self.memory}. MAC Address: {self.mac_address}'
|
|
||||||
|
|
||||||
|
|
||||||
def get_mac_address(interface="Ethernet"):
|
|
||||||
addresses = psutil.net_if_addrs()
|
|
||||||
for interface_name, interface_info in addresses.items():
|
|
||||||
if interface_name == interface:
|
|
||||||
for addr in interface_info:
|
|
||||||
if addr.family == psutil.AF_LINK:
|
|
||||||
return addr.address.replace('-', '')
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def get_hardware_info():
|
def get_hardware_info():
|
||||||
res = subprocess.check_output("ver", shell=True).decode('utf-8')
|
if os.name == 'nt': # windows
|
||||||
if "Microsoft Windows" in res:
|
|
||||||
is_windows = True
|
|
||||||
else:
|
|
||||||
is_windows = False
|
|
||||||
|
|
||||||
if is_windows:
|
|
||||||
os_command = (
|
os_command = (
|
||||||
"powershell -Command \""
|
"powershell -Command \""
|
||||||
"Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; "
|
"Get-CimInstance -ClassName Win32_Processor | Select-Object -ExpandProperty Name | Write-Output; "
|
||||||
"Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; "
|
"Get-CimInstance -ClassName Win32_VideoController | Select-Object -ExpandProperty Name | Write-Output; "
|
||||||
"Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output"
|
"Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object -ExpandProperty TotalVisibleMemorySize | Write-Output; "
|
||||||
|
"(Get-Disk | Where-Object {$_.IsSystem -eq $true}).SerialNumber"
|
||||||
"\""
|
"\""
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
os_command = (
|
os_command = (
|
||||||
"/bin/bash -c \" lscpu | grep 'Model name:' | cut -d':' -f2 && "
|
"lscpu | grep 'Model name:' | cut -d':' -f2 && "
|
||||||
"lspci | grep VGA | cut -d':' -f3 && "
|
"lspci | grep VGA | cut -d':' -f3 && "
|
||||||
"free -g | grep Mem: | awk '{print $2}' && \""
|
"free -k | awk '/^Mem:/ {print $2}' && "
|
||||||
|
"cat /sys/block/sda/device/vpd_pg80 2>/dev/null || cat /sys/block/sda/device/serial 2>/dev/null"
|
||||||
)
|
)
|
||||||
result = subprocess.check_output(os_command, shell=True).decode('utf-8')
|
|
||||||
lines = [line.strip() for line in result.splitlines() if line.strip()]
|
|
||||||
|
|
||||||
cpu = lines[0].replace("Name=", "").replace(" ", " ")
|
result = subprocess.check_output(os_command, shell=True).decode('utf-8', errors='ignore')
|
||||||
gpu = lines[1].replace("Name=", "").replace(" ", " ")
|
lines = [line.replace(" ", " ").replace("Name=", "").strip('\x00\x14 \t\n\r\v\f') for line in result.splitlines() if line.strip()]
|
||||||
memory = lines[2].replace("TotalVisibleMemorySize=", "").replace(" ", " ")
|
|
||||||
mac_address = get_mac_address()
|
|
||||||
|
|
||||||
return HardwareInfo(cpu, gpu, memory, mac_address)
|
cpu = lines[0]
|
||||||
|
gpu = lines[1]
|
||||||
|
|
||||||
|
# could be multiple gpus, that's why take memory and drive from the 2 last lines
|
||||||
|
len_lines = len(lines)
|
||||||
|
memory = lines[len_lines - 2].replace("TotalVisibleMemorySize=", "")
|
||||||
|
drive_serial = lines[len_lines - 1]
|
||||||
|
|
||||||
|
res = f'CPU: {cpu}. GPU: {gpu}. Memory: {memory}. DriveSerial: {drive_serial}'
|
||||||
|
return res
|
||||||
|
|||||||
Reference in New Issue
Block a user