Browse Source

Firewall, Router and Switch Port Commands added

James 2 months ago
parent
commit
7f072706fe

+ 29 - 0
RackPeek/Commands/Firewalls/Ports/FirewallPortAddCommand.cs

@@ -0,0 +1,29 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Firewalls.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Firewalls.Ports;
+
+public class FirewallPortAddSettings : FirewallNameSettings
+{
+    [CommandOption("--type")] public string? Type { get; set; }
+    [CommandOption("--speed")] public double? Speed { get; set; }
+    [CommandOption("--count")] public int? Count { get; set; }
+}
+
+public class FirewallPortAddCommand(IServiceProvider sp)
+    : AsyncCommand<FirewallPortAddSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, FirewallPortAddSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<AddFirewallPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Type, s.Speed, s.Count);
+
+        AnsiConsole.MarkupLine($"[green]Port added to firewall '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 27 - 0
RackPeek/Commands/Firewalls/Ports/FirewallPortRemoveCommand.cs

@@ -0,0 +1,27 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Firewalls.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Firewalls.Ports;
+
+public class FirewallPortRemoveSettings : FirewallNameSettings
+{
+    [CommandOption("--index <INDEX>")] public int Index { get; set; }
+}
+
+public class FirewallPortRemoveCommand(IServiceProvider sp)
+    : AsyncCommand<FirewallPortRemoveSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, FirewallPortRemoveSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<RemoveFirewallPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Index);
+
+        AnsiConsole.MarkupLine($"[green]Port {s.Index} removed from firewall '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 30 - 0
RackPeek/Commands/Firewalls/Ports/FirewallPortUpdateCommand.cs

@@ -0,0 +1,30 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Firewalls.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Firewalls.Ports;
+
+public class FirewallPortUpdateSettings : FirewallNameSettings
+{
+    [CommandOption("--index <INDEX>")] public int Index { get; set; }
+    [CommandOption("--type")] public string? Type { get; set; }
+    [CommandOption("--speed")] public double? Speed { get; set; }
+    [CommandOption("--count")] public int? Count { get; set; }
+}
+
+public class FirewallPortUpdateCommand(IServiceProvider sp)
+    : AsyncCommand<FirewallPortUpdateSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, FirewallPortUpdateSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<UpdateFirewallPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Index, s.Type, s.Speed, s.Count);
+
+        AnsiConsole.MarkupLine($"[green]Port {s.Index} updated on firewall '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 29 - 0
RackPeek/Commands/Routers/Ports/RouterPortAddCommand.cs

@@ -0,0 +1,29 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Routers.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Routers.Ports;
+
+public class RouterPortAddSettings : RouterNameSettings
+{
+    [CommandOption("--type")] public string? Type { get; set; }
+    [CommandOption("--speed")] public double? Speed { get; set; }
+    [CommandOption("--count")] public int? Count { get; set; }
+}
+
+public class RouterPortAddCommand(IServiceProvider sp)
+    : AsyncCommand<RouterPortAddSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, RouterPortAddSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<AddRouterPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Type, s.Speed, s.Count);
+
+        AnsiConsole.MarkupLine($"[green]Port added to router '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 27 - 0
RackPeek/Commands/Routers/Ports/RouterPortRemoveCommand.cs

@@ -0,0 +1,27 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Routers.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Routers.Ports;
+
+public class RouterPortRemoveSettings : RouterNameSettings
+{
+    [CommandOption("--index <INDEX>")] public int Index { get; set; }
+}
+
+public class RouterPortRemoveCommand(IServiceProvider sp)
+    : AsyncCommand<RouterPortRemoveSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, RouterPortRemoveSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<RemoveRouterPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Index);
+
+        AnsiConsole.MarkupLine($"[green]Port {s.Index} removed from router '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 30 - 0
RackPeek/Commands/Routers/Ports/RouterPortUpdateCommand.cs

@@ -0,0 +1,30 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Routers.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Routers.Ports;
+
+public class RouterPortUpdateSettings : RouterNameSettings
+{
+    [CommandOption("--index <INDEX>")] public int Index { get; set; }
+    [CommandOption("--type")] public string? Type { get; set; }
+    [CommandOption("--speed")] public double? Speed { get; set; }
+    [CommandOption("--count")] public int? Count { get; set; }
+}
+
+public class RouterPortUpdateCommand(IServiceProvider sp)
+    : AsyncCommand<RouterPortUpdateSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, RouterPortUpdateSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<UpdateRouterPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Index, s.Type, s.Speed, s.Count);
+
+        AnsiConsole.MarkupLine($"[green]Port {s.Index} updated on router '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 37 - 0
RackPeek/Commands/Switches/Ports/SwitchPortAddCommand.cs

@@ -0,0 +1,37 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Switches.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Switches.Ports;
+
+public class SwitchPortAddSettings : SwitchNameSettings
+{
+    [CommandOption("--type")]
+    [Description("The port type (e.g., rj45, sfp+).")]
+    public string? Type { get; set; }
+
+    [CommandOption("--speed")]
+    [Description("The port speed (e.g., 1, 2.5, 10).")]
+    public double? Speed { get; set; }
+
+    [CommandOption("--count")]
+    [Description("Number of ports of this type.")]
+    public int? Count { get; set; }
+}
+
+public class SwitchPortAddCommand(IServiceProvider sp)
+    : AsyncCommand<SwitchPortAddSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, SwitchPortAddSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<AddSwitchPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Type, s.Speed, s.Count);
+
+        AnsiConsole.MarkupLine($"[green]Port added to switch '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 28 - 0
RackPeek/Commands/Switches/Ports/SwitchPortRemoveCommand.cs

@@ -0,0 +1,28 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Switches.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Switches.Ports;
+
+public class SwitchPortRemoveSettings : SwitchNameSettings
+{
+    [CommandOption("--index <INDEX>")]
+    public int Index { get; set; }
+}
+
+public class SwitchPortRemoveCommand(IServiceProvider sp)
+    : AsyncCommand<SwitchPortRemoveSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, SwitchPortRemoveSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<RemoveSwitchPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Index);
+
+        AnsiConsole.MarkupLine($"[green]Port {s.Index} removed from switch '{s.Name}'.[/]");
+        return 0;
+    }
+}

+ 37 - 0
RackPeek/Commands/Switches/Ports/SwitchPortUpdateCommand.cs

@@ -0,0 +1,37 @@
+using Spectre.Console.Cli;
+using System.ComponentModel;
+using Microsoft.Extensions.DependencyInjection;
+using RackPeek.Domain.Resources.Hardware.Switches.Ports;
+using Spectre.Console;
+
+namespace RackPeek.Commands.Switches.Ports;
+
+public class SwitchPortUpdateSettings : SwitchNameSettings
+{
+    [CommandOption("--index <INDEX>")]
+    public int Index { get; set; }
+
+    [CommandOption("--type")]
+    public string? Type { get; set; }
+
+    [CommandOption("--speed")]
+    public double? Speed { get; set; }
+
+    [CommandOption("--count")]
+    public int? Count { get; set; }
+}
+
+public class SwitchPortUpdateCommand(IServiceProvider sp)
+    : AsyncCommand<SwitchPortUpdateSettings>
+{
+    public override async Task<int> ExecuteAsync(CommandContext ctx, SwitchPortUpdateSettings s, CancellationToken ct)
+    {
+        using var scope = sp.CreateScope();
+        var useCase = scope.ServiceProvider.GetRequiredService<UpdateSwitchPortUseCase>();
+
+        await useCase.ExecuteAsync(s.Name, s.Index, s.Type, s.Speed, s.Count);
+
+        AnsiConsole.MarkupLine($"[green]Port {s.Index} updated on switch '{s.Name}'.[/]");
+        return 0;
+    }
+}