فهرست منبع

Merge pull request #188 from Timmoth/Server-Summary-Fix

Server Summary Fix
Tim Jones 1 ماه پیش
والد
کامیت
4251ebde24

+ 21 - 2
RackPeek.Domain/Resources/Servers/ServerHardwareReport.cs

@@ -1,4 +1,5 @@
 using RackPeek.Domain.Persistence;
+using RackPeek.Domain.Resources.SubResources;
 
 namespace RackPeek.Domain.Resources.Servers;
 
@@ -20,8 +21,25 @@ public record ServerHardwareRow(
     int GpuCount,
     int TotalGpuVramGb,
     string GpuSummary,
-    bool Ipmi
+    bool Ipmi, 
+    IReadOnlyList<Nic> Nics
+)
+{        
+public string NicSummary =>
+string.Join(", ",
+    (Nics ?? [])
+    .SelectMany(n =>
+    {
+        var ports = n.Ports ?? 1;
+        var speed = n.Speed ?? 0;
+        return Enumerable.Repeat(speed, ports);
+    })
+    .GroupBy(speed => speed)
+    .OrderByDescending(g => g.Key)
+    .Select(g => $"{g.Count()}×{g.Key}G")
+    .DefaultIfEmpty("none")
 );
+}
 
 public class ServerHardwareReportUseCase(IResourceCollection repository) : IUseCase
 {
@@ -81,7 +99,8 @@ public class ServerHardwareReportUseCase(IResourceCollection repository) : IUseC
                 gpuCount,
                 totalGpuVram,
                 gpuSummary,
-                server.Ipmi ?? false
+                server.Ipmi ?? false,
+                server.Nics ?? new List<Nic>()
             );
         }).ToList();
 

+ 1 - 1
Shared.Rcl/Commands/Servers/Nics/ServerNicAddCommand.cs

@@ -10,7 +10,7 @@ public class ServerNicAddSettings : ServerNameSettings
 {
     [CommandOption("--type <TYPE>")] public string Type { get; set; }
 
-    [CommandOption("--speed <SPEED>")] public int Speed { get; set; }
+    [CommandOption("--speed <SPEED>")] public double Speed { get; set; }
 
     [CommandOption("--ports <PORTS>")] public int Ports { get; set; }
 }

+ 1 - 1
Shared.Rcl/Commands/Servers/Nics/ServerNicUpdateCommand.cs

@@ -12,7 +12,7 @@ public class ServerNicUpdateSettings : ServerNameSettings
 
     [CommandOption("--type <TYPE>")] public string Type { get; set; }
 
-    [CommandOption("--speed <SPEED>")] public int Speed { get; set; }
+    [CommandOption("--speed <SPEED>")] public double Speed { get; set; }
 
     [CommandOption("--ports <PORTS>")] public int Ports { get; set; }
 }

+ 1 - 1
Shared.Rcl/Commands/Servers/ServerReportCommand.cs

@@ -40,7 +40,7 @@ public class ServerReportCommand(ILogger<ServerReportCommand> logger, IServicePr
                 $"{s.TotalCores}/{s.TotalThreads}",
                 $"{s.RamGb} GB",
                 $"{s.TotalStorageGb} GB (SSD {s.SsdStorageGb} / HDD {s.HddStorageGb})",
-                $"{s.TotalNicPorts}×{s.MaxNicSpeedGb}G",
+                s.NicSummary,
                 s.GpuCount == 0
                     ? "[grey]none[/]"
                     : $"{s.GpuSummary} ({s.TotalGpuVramGb} GB VRAM)",

+ 16 - 8
Tests/EndToEnd/ServerTests/ServerWorkflowTests.cs

@@ -87,6 +87,14 @@ public class ServerWorkflowTests(TempYamlCliFixture fs, ITestOutputHelper output
             "--ports", "2"
         );
         Assert.Equal("NIC added to 'srv01'.\n", output);
+        
+        (output, yaml) = await ExecuteAsync(
+            "servers", "nic", "add", "srv01",
+            "--type", "RJ45",
+            "--speed", "2.5",
+            "--ports", "2"
+        );
+        Assert.Equal("NIC added to 'srv01'.\n", output);
 
         // Get server
         (output, yaml) = await ExecuteAsync("servers", "get", "srv01");
@@ -101,14 +109,14 @@ public class ServerWorkflowTests(TempYamlCliFixture fs, ITestOutputHelper output
         (output, yaml) = await ExecuteAsync("servers", "summary");
         
         Assert.Equal("""
-                     ╭───────┬───────────┬───────┬────────┬────────────┬───────┬────────────┬──────╮
-                     │ Name  │ CPU        │ C/T   │ RAM    │ Storage    │ NICs  │ GPUs       │ IPMI │
-                     ├───────┼───────────┼───────┼────────┼────────────┼───────┼────────────┼──────┤
-                     │ srv01 │ 1× Intel   │ 12/24 │ 128 GB │ 1024 GB    │ 2×10G │ 1× NVIDIA  │ yes  │
-                     │       │ Xeon       │       │        │ (SSD 1024  │       │ A2000 (6   │      │
-                     │       │ Silver     │       │        │ / HDD 0)   │       │ GB VRAM)   │      │
-                     │       │ 4310       │       │        │           │            │      │
-                     ╰───────┴───────────┴───────┴────────┴────────────┴───────┴────────────┴──────╯
+                     ╭───────┬───────────┬───────┬────────┬───────────┬───────────┬──────────┬──────╮
+                     │ Name  │ CPU       │ C/T   │ RAM    │ Storage   │ NICs      │ GPUs     │ IPMI │
+                     ├───────┼───────────┼───────┼────────┼───────────┼───────────┼──────────┼──────┤
+                     │ srv01 │ 1× Intel  │ 12/24 │ 128 GB │ 1024 GB   │ 2×10G,    │ 1×       │ yes  │
+                     │       │ Xeon      │       │        │ (SSD 1024 │ 2×2.5G    │ NVIDIA   │      │
+                     │       │ Silver    │       │        │ / HDD 0)  │           │ A2000 (6 │      │
+                     │       │ 4310      │       │        │           │           │ GB VRAM) │      │
+                     ╰───────┴───────────┴───────┴────────┴───────────┴───────────┴──────────┴──────╯
                      
                      """, output);