4
0
Эх сурвалжийг харах

numeric IP address ordering + System IP address used in SSH / Hosts file export (#251)

Tim Jones 3 долоо хоног өмнө
parent
commit
0fc2ba1f72

+ 6 - 0
RackPeek.Domain/UseCases/Hosts/SshExportOptions.cs

@@ -1,6 +1,7 @@
 using System.Text;
 using RackPeek.Domain.Persistence;
 using RackPeek.Domain.Resources;
+using RackPeek.Domain.Resources.SystemResources;
 
 namespace RackPeek.Domain.UseCases.Hosts;
 
@@ -66,6 +67,11 @@ public static class HostsFileGenerator {
     }
 
     private static string? GetAddress(Resource r) {
+        if (r is SystemResource { Ip: not null } system &&
+            !string.IsNullOrWhiteSpace(system!.Ip)) {
+            return system.Ip;
+        }
+
         if (r.Labels.TryGetValue("ip", out var ip) && !string.IsNullOrWhiteSpace(ip))
             return ip;
 

+ 6 - 0
RackPeek.Domain/UseCases/SSH/SshConfigGenerator.cs

@@ -1,5 +1,6 @@
 using System.Text;
 using RackPeek.Domain.Resources;
+using RackPeek.Domain.Resources.SystemResources;
 
 namespace RackPeek.Domain.UseCases.SSH;
 
@@ -58,6 +59,11 @@ public static class SshConfigGenerator {
     }
 
     private static string? GetAddress(Resource r) {
+        if (r is SystemResource { Ip: not null } system &&
+            !string.IsNullOrWhiteSpace(system!.Ip)) {
+            return system.Ip;
+        }
+
         if (r.Labels.TryGetValue("ip", out var ip) && !string.IsNullOrWhiteSpace(ip))
             return ip;
 

+ 17 - 2
Shared.Rcl/SubnetBrowser.razor

@@ -61,7 +61,7 @@
         <div class="space-y-6"
              data-testid="subnet-browser-list">
 
-            @foreach (var subnetGroup in _grouped.OrderBy(x => x.Key))
+            @foreach (var subnetGroup in _grouped.OrderBy(x => IpToSortable(x.Key.Replace(".x", ".0"))))  
             {
                 <div data-testid=@($"subnet-group-{subnetGroup.Key.Replace('.', '-')}")>
 
@@ -90,7 +90,7 @@
                     </div>
 
                     <ul class="ml-2 border-l border-zinc-800 pl-4 space-y-3">
-                        @foreach (var ipGroup in subnetGroup.Value.OrderBy(x => x.Key))
+                        @foreach (var ipGroup in subnetGroup.Value.OrderBy(x => IpToSortable(x.Key)))
                         {
                             <li>
 
@@ -304,5 +304,20 @@
 
         return -1;
     }
+    
+    private static uint IpToSortable(string ip)
+    {
+        var parts = ip.Split('.')
+            .Select(p => byte.TryParse(p, out var b) ? b : (byte)0)
+            .ToArray();
+
+        if (parts.Length != 4)
+            return 0;
+
+        return ((uint)parts[0] << 24)
+               | ((uint)parts[1] << 16)
+               | ((uint)parts[2] << 8)
+               | parts[3];
+    }
 
 }