@page "/subnets"
@using RackPeek.Domain.Persistence
@using RackPeek.Domain.Resources
@using RackPeek.Domain.Resources.SystemResources
@inject IResourceCollection ResourceCollection
Subnet Browser
@if (_grouped is not null && _grouped.Any())
{
var nextFreeIp = GetNextFreeIp();
var nextFreePort = GetNextFreePort();
next free ip:
@nextFreeIp
next free port:
@nextFreePort
}
@if (_grouped is null)
{
loading…
}
else if (!_grouped.Any())
{
no matching IPs found
}
else
{
@foreach (var subnetGroup in _grouped.OrderBy(x => IpToSortable(x.Key.Replace(".x", ".0"))))
{
@{
var addresses = subnetGroup.Value.Count;
var services = subnetGroup.Value
.SelectMany(x => x.Value)
.Count(x => x.Item1 is Service);
// /24 assumption (x subnet)
const int subnetCapacity = 256;
var percentFull = (int)Math.Round((double)addresses / subnetCapacity * 100);
}
@subnetGroup.Key
(@addresses addresses,
@services services,
@percentFull% full)
@foreach (var ipGroup in subnetGroup.Value.OrderBy(x => IpToSortable(x.Key)))
{
├─ @ipGroup.Key
@foreach (var (resource, _) in ipGroup.Value)
{
var url = GetResourceUrl(resource);
var port = resource is Service
{
Network.Port: not null
} service
? service.Network!.Port
: null;
var typeName = resource.GetType().Name.Replace("Resource", "");
@resource.Name
@if (port.HasValue)
{
:@port
}
(@typeName)
}
}
}
}
@code {
private string _filter = string.Empty;
private IReadOnlyList<(Resource resource, string ip)> _all = [];
private Dictionary