hardware service works on linux

This commit is contained in:
Alex Bezdieniezhnykh
2025-05-31 17:48:26 +03:00
parent 42867560c3
commit 2584b4f125
4 changed files with 80 additions and 29 deletions
@@ -0,0 +1,51 @@
using System.Diagnostics;
using Azaion.CommonSecurity.DTO;
using MediatR;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Azaion.CommonSecurity.Services;
public class LoaderClient
{
private readonly IMediator _mediator;
private readonly ILogger<LoaderClient> _logger;
public LoaderClient(IMediator mediator, IOptions<LoaderClientConfig> config, ILogger<LoaderClient> logger)
{
_mediator = mediator;
_logger = logger;
try
{
using var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = SecurityConstants.LoaderPath,
Arguments = $"--port {config.Value.ZeroMqPort} --api {config.Value.ApiUrl}",
//RedirectStandardOutput = true,
//RedirectStandardError = true,
//CreateNoWindow = true
};
process.OutputDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.ErrorDataReceived += (_, e) => { if (e.Data != null) Console.WriteLine(e.Data); };
process.Start();
}
catch (Exception e)
{
Console.WriteLine(e);
//throw;
}
_requestAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqPort}";
_requestSocket.Connect(_requestAddress);
_subscriberAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqReceiverPort}";
_subscriberSocket.Connect(_subscriberAddress);
_subscriberSocket.Subscribe("");
_subscriberSocket.ReceiveReady += async (sender, e) => await ProcessClientCommand(sender, e);
_poller.Add(_subscriberSocket);
_poller.RunAsync();
}
}
-1
View File
@@ -1,5 +1,4 @@
cdef class HardwareService: cdef class HardwareService:
cdef bint is_windows
@staticmethod @staticmethod
cdef has_nvidia_gpu() cdef has_nvidia_gpu()
+9 -23
View File
@@ -1,20 +1,9 @@
import os
import subprocess import subprocess
import pynvml import pynvml
cdef class HardwareService: cdef class HardwareService:
"""Handles hardware information retrieval and hash generation."""
def __init__(self):
try:
res = subprocess.check_output("ver", shell=True).decode('utf-8')
if "Microsoft Windows" in res:
self.is_windows = True
else:
self.is_windows = False
except Exception:
print('Error during os type checking')
self.is_windows = False
@staticmethod @staticmethod
cdef has_nvidia_gpu(): cdef has_nvidia_gpu():
@@ -40,7 +29,7 @@ cdef class HardwareService:
pass pass
cdef str get_hardware_info(self): cdef str get_hardware_info(self):
if self.is_windows: if os.name == 'nt': # 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; "
@@ -51,20 +40,17 @@ cdef class HardwareService:
) )
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}' && "
"udevadm info --query=property --name=\"/dev/$(lsblk -no pkname \"$(findmnt -n -o SOURCE --target /)\")\" | grep -E 'ID_SERIAL=|ID_SERIAL_SHORT=' | cut -d'=' -f2- | head -n1 && " "cat /sys/block/sda/device/vpd_pg80 2>/dev/null || cat /sys/block/sda/device/serial 2>/dev/null"
) )
# in case of subprocess error do:
# cdef bytes os_command_bytes = os_command.encode('utf-8')
# and use os_command_bytes
result = subprocess.check_output(os_command, shell=True).decode('utf-8') result = subprocess.check_output(os_command, shell=True).decode('utf-8', errors='ignore')
lines = [line.strip() for line in result.splitlines() if line.strip()] lines = [line.replace(" ", " ").replace("Name=", "").strip('\x00\x14 \t\n\r\v\f') for line in result.splitlines() if line.strip()]
cdef str cpu = lines[0].replace("Name=", "").replace(" ", " ") cdef str cpu = lines[0]
cdef str gpu = lines[1].replace("Name=", "").replace(" ", " ") cdef str gpu = lines[1]
# could be multiple gpus # could be multiple gpus
len_lines = len(lines) len_lines = len(lines)
+20 -5
View File
@@ -1,5 +1,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.14.36127.28 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Annotator", "Azaion.Annotator\Azaion.Annotator.csproj", "{8E0809AF-2920-4267-B14D-84BAB334A46F}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Annotator", "Azaion.Annotator\Azaion.Annotator.csproj", "{8E0809AF-2920-4267-B14D-84BAB334A46F}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Test", "Azaion.Test\Azaion.Test.csproj", "{85359558-FB59-4542-A597-FD9E1B04C8E7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.Test", "Azaion.Test\Azaion.Test.csproj", "{85359558-FB59-4542-A597-FD9E1B04C8E7}"
@@ -24,19 +27,21 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.CommonSecurity", "Az
EndProject EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{CF141A48-8002-4006-81CF-6B85AE5B0B5F}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{CF141A48-8002-4006-81CF-6B85AE5B0B5F}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
build\requirements.txt = build\requirements.txt
build\cdn_manager.py = build\cdn_manager.py
build\downloader_config.yaml = build\downloader_config.yaml
build\build_cdn_manager.cmd = build\build_cdn_manager.cmd build\build_cdn_manager.cmd = build\build_cdn_manager.cmd
build\build_dotnet.cmd = build\build_dotnet.cmd build\build_dotnet.cmd = build\build_dotnet.cmd
build\init.cmd = build\init.cmd build\cdn_manager.py = build\cdn_manager.py
build\downloader_config.yaml = build\downloader_config.yaml
build\download_models.cmd = build\download_models.cmd build\download_models.cmd = build\download_models.cmd
build\publish.cmd = build\publish.cmd build\init.cmd = build\init.cmd
build\installer.full.iss = build\installer.full.iss build\installer.full.iss = build\installer.full.iss
build\installer.iterative.iss = build\installer.iterative.iss build\installer.iterative.iss = build\installer.iterative.iss
build\publish-full.cmd = build\publish-full.cmd build\publish-full.cmd = build\publish-full.cmd
build\publish.cmd = build\publish.cmd
build\requirements.txt = build\requirements.txt
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azaion.LoaderUI", "Azaion.LoaderUI\Azaion.LoaderUI.csproj", "{C96C142E-3ED3-4455-9C22-93A12022B8A9}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -81,9 +86,19 @@ Global
{E0C7176D-2E91-4928-B3C1-55CC91C8F77D}.Release|Any CPU.ActiveCfg = Release|Any CPU {E0C7176D-2E91-4928-B3C1-55CC91C8F77D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E0C7176D-2E91-4928-B3C1-55CC91C8F77D}.Release|Any CPU.Build.0 = Release|Any CPU {E0C7176D-2E91-4928-B3C1-55CC91C8F77D}.Release|Any CPU.Build.0 = Release|Any CPU
{E0C7176D-2E91-4928-B3C1-55CC91C8F77D}.Release|Any CPU.Deploy.0 = Release|Any CPU {E0C7176D-2E91-4928-B3C1-55CC91C8F77D}.Release|Any CPU.Deploy.0 = Release|Any CPU
{C96C142E-3ED3-4455-9C22-93A12022B8A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C96C142E-3ED3-4455-9C22-93A12022B8A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C96C142E-3ED3-4455-9C22-93A12022B8A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C96C142E-3ED3-4455-9C22-93A12022B8A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(NestedProjects) = preSolution GlobalSection(NestedProjects) = preSolution
{32C4747F-F700-44FD-B4ED-21B4A66B5FAB} = {C307BE2E-FFCC-4BD7-AD89-C82D40B65D03} {32C4747F-F700-44FD-B4ED-21B4A66B5FAB} = {C307BE2E-FFCC-4BD7-AD89-C82D40B65D03}
{A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E} = {C307BE2E-FFCC-4BD7-AD89-C82D40B65D03} {A2E3D3AE-5DB7-4342-BE20-88A9D1B0C05E} = {C307BE2E-FFCC-4BD7-AD89-C82D40B65D03}
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {788BD4AD-E4EC-43A1-85A0-AEC644BD8D48}
EndGlobalSection
EndGlobal EndGlobal