|
|
@@ -1,28 +1,22 @@
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
-using RackPeek.Domain.Resources.Hardware;
|
|
|
-using Spectre.Console;
|
|
|
-using Spectre.Console.Cli;
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
using RackPeek.Commands;
|
|
|
using RackPeek.Commands.Server;
|
|
|
using RackPeek.Commands.Server.Cpus;
|
|
|
-using RackPeek.Commands.Switches;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Reports;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Server;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Server.Cpu;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Switchs;
|
|
|
-using RackPeek.Commands.Server.Nics;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Reports;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Server;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Server.Cpu;
|
|
|
-using RackPeek.Domain.Resources.Hardware.Server.Nic;
|
|
|
using RackPeek.Commands.Server.Drives;
|
|
|
+using RackPeek.Commands.Server.Nics;
|
|
|
+using RackPeek.Commands.Switches;
|
|
|
+using RackPeek.Domain.Resources.Hardware;
|
|
|
using RackPeek.Domain.Resources.Hardware.Reports;
|
|
|
using RackPeek.Domain.Resources.Hardware.Server;
|
|
|
using RackPeek.Domain.Resources.Hardware.Server.Cpu;
|
|
|
using RackPeek.Domain.Resources.Hardware.Server.Drive;
|
|
|
+using RackPeek.Domain.Resources.Hardware.Server.Nic;
|
|
|
+using RackPeek.Domain.Resources.Hardware.Switchs;
|
|
|
using RackPeek.Yaml;
|
|
|
+using Spectre.Console;
|
|
|
+using Spectre.Console.Cli;
|
|
|
|
|
|
namespace RackPeek;
|
|
|
|
|
|
@@ -33,7 +27,7 @@ public static class Program
|
|
|
// Configuration
|
|
|
var configuration = new ConfigurationBuilder()
|
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
|
- .AddJsonFile("appsettings.json", optional: true)
|
|
|
+ .AddJsonFile("appsettings.json", true)
|
|
|
.Build();
|
|
|
|
|
|
// DI
|
|
|
@@ -45,7 +39,7 @@ public static class Program
|
|
|
services.AddScoped<IHardwareRepository>(_ =>
|
|
|
{
|
|
|
var path = configuration["HardwareFile"] ?? "hardware.yaml";
|
|
|
-
|
|
|
+
|
|
|
var collection = new YamlResourceCollection();
|
|
|
collection.LoadFiles([
|
|
|
"servers.yaml",
|
|
|
@@ -55,17 +49,17 @@ public static class Program
|
|
|
"ups.yaml",
|
|
|
"firewalls.yaml",
|
|
|
"laptops.yaml",
|
|
|
- "routers.yaml"]);
|
|
|
+ "routers.yaml"
|
|
|
+ ]);
|
|
|
|
|
|
return new YamlHardwareRepository(collection);
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
services.AddLogging(configure =>
|
|
|
configure
|
|
|
.AddSimpleConsole(opts => { opts.TimestampFormat = "yyyy-MM-dd HH:mm:ss "; }));
|
|
|
|
|
|
|
|
|
-
|
|
|
// Application
|
|
|
services.AddScoped<ServerHardwareReportUseCase>();
|
|
|
services.AddScoped<ServerReportCommand>();
|
|
|
@@ -77,27 +71,27 @@ public static class Program
|
|
|
services.AddScoped<UpsReportCommand>();
|
|
|
services.AddScoped<DesktopHardwareReportUseCase>();
|
|
|
services.AddScoped<DesktopReportCommand>();
|
|
|
-
|
|
|
+
|
|
|
services.AddScoped<AddServerUseCase>();
|
|
|
services.AddScoped<ServerAddCommand>();
|
|
|
-
|
|
|
+
|
|
|
services.AddScoped<DeleteServerUseCase>();
|
|
|
services.AddScoped<ServerDeleteCommand>();
|
|
|
|
|
|
services.AddScoped<DescribeServerUseCase>();
|
|
|
services.AddScoped<ServerDescribeCommand>();
|
|
|
-
|
|
|
+
|
|
|
services.AddScoped<GetServerUseCase>();
|
|
|
services.AddScoped<ServerGetByNameCommand>();
|
|
|
-
|
|
|
+
|
|
|
services.AddScoped<UpdateServerUseCase>();
|
|
|
services.AddScoped<ServerSetCommand>();
|
|
|
-
|
|
|
+
|
|
|
// CPU use cases
|
|
|
services.AddScoped<AddCpuUseCase>();
|
|
|
services.AddScoped<UpdateCpuUseCase>();
|
|
|
services.AddScoped<RemoveCpuUseCase>();
|
|
|
-
|
|
|
+
|
|
|
// Drive use cases
|
|
|
services.AddScoped<AddDrivesUseCase>();
|
|
|
services.AddScoped<UpdateDriveUseCase>();
|
|
|
@@ -108,7 +102,7 @@ public static class Program
|
|
|
services.AddScoped<ServerCpuAddCommand>();
|
|
|
services.AddScoped<ServerCpuSetCommand>();
|
|
|
services.AddScoped<ServerCpuRemoveCommand>();
|
|
|
-
|
|
|
+
|
|
|
// Switch commands
|
|
|
services.AddScoped<SwitchAddCommand>();
|
|
|
services.AddScoped<SwitchDeleteCommand>();
|
|
|
@@ -116,7 +110,7 @@ public static class Program
|
|
|
services.AddScoped<SwitchGetByNameCommand>();
|
|
|
services.AddScoped<SwitchGetCommand>();
|
|
|
services.AddScoped<SwitchSetCommand>();
|
|
|
-
|
|
|
+
|
|
|
// Switch Usecases
|
|
|
services.AddScoped<AddSwitchUseCase>();
|
|
|
services.AddScoped<DeleteSwitchUseCase>();
|
|
|
@@ -128,7 +122,7 @@ public static class Program
|
|
|
services.AddScoped<AddNicUseCase>();
|
|
|
services.AddScoped<UpdateNicUseCase>();
|
|
|
services.AddScoped<RemoveNicUseCase>();
|
|
|
-
|
|
|
+
|
|
|
// NIC commands
|
|
|
services.AddScoped<ServerNicAddCommand>();
|
|
|
services.AddScoped<ServerNicUpdateCommand>();
|
|
|
@@ -138,7 +132,7 @@ public static class Program
|
|
|
services.AddScoped<ServerDriveUpdateCommand>();
|
|
|
services.AddScoped<ServerDriveRemoveCommand>();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
// Spectre bootstrap
|
|
|
var registrar = new TypeRegistrar(services);
|
|
|
var app = new CommandApp(registrar);
|
|
|
@@ -153,10 +147,10 @@ public static class Program
|
|
|
config.AddBranch("servers", server =>
|
|
|
{
|
|
|
server.SetDescription("Manage servers");
|
|
|
-
|
|
|
+
|
|
|
server.AddCommand<ServerReportCommand>("summary")
|
|
|
.WithDescription("Show server hardware report");
|
|
|
-
|
|
|
+
|
|
|
server.AddCommand<ServerAddCommand>("add")
|
|
|
.WithDescription("Add a new server");
|
|
|
|
|
|
@@ -171,7 +165,7 @@ public static class Program
|
|
|
|
|
|
server.AddCommand<ServerDeleteCommand>("del")
|
|
|
.WithDescription("Delete a server");
|
|
|
-
|
|
|
+
|
|
|
server.AddBranch("cpu", cpu =>
|
|
|
{
|
|
|
cpu.SetDescription("Manage server CPUs");
|
|
|
@@ -185,7 +179,7 @@ public static class Program
|
|
|
cpu.AddCommand<ServerCpuRemoveCommand>("del")
|
|
|
.WithDescription("Remove a CPU from a server");
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
server.AddBranch("nic", nic =>
|
|
|
{
|
|
|
nic.SetDescription("Manage server NICs");
|
|
|
@@ -198,58 +192,58 @@ public static class Program
|
|
|
|
|
|
nic.AddCommand<ServerNicRemoveCommand>("del")
|
|
|
.WithDescription("Remove a NIC from a server");
|
|
|
- server.AddBranch("drive", drive =>
|
|
|
- {
|
|
|
- drive.SetDescription("Manage server drives");
|
|
|
+ server.AddBranch("drive", drive =>
|
|
|
+ {
|
|
|
+ drive.SetDescription("Manage server drives");
|
|
|
|
|
|
- drive.AddCommand<ServerDriveAddCommand>("add")
|
|
|
- .WithDescription("Add a drive to a server");
|
|
|
+ drive.AddCommand<ServerDriveAddCommand>("add")
|
|
|
+ .WithDescription("Add a drive to a server");
|
|
|
|
|
|
- drive.AddCommand<ServerDriveUpdateCommand>("set")
|
|
|
- .WithDescription("Update a drive on a server");
|
|
|
+ drive.AddCommand<ServerDriveUpdateCommand>("set")
|
|
|
+ .WithDescription("Update a drive on a server");
|
|
|
|
|
|
- drive.AddCommand<ServerDriveRemoveCommand>("del")
|
|
|
- .WithDescription("Remove a drive from a server");
|
|
|
+ drive.AddCommand<ServerDriveRemoveCommand>("del")
|
|
|
+ .WithDescription("Remove a drive from a server");
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
- });
|
|
|
+ config.AddBranch("switches", server =>
|
|
|
+ {
|
|
|
+ server.SetDescription("Manage switches");
|
|
|
|
|
|
- config.AddBranch("switches", server =>
|
|
|
- {
|
|
|
- server.SetDescription("Manage switches");
|
|
|
-
|
|
|
- server.AddCommand<SwitchReportCommand>("summary")
|
|
|
- .WithDescription("Show switch hardware report");
|
|
|
-
|
|
|
- server.AddCommand<SwitchAddCommand>("add")
|
|
|
- .WithDescription("Add a new switch");
|
|
|
+ server.AddCommand<SwitchReportCommand>("summary")
|
|
|
+ .WithDescription("Show switch hardware report");
|
|
|
|
|
|
- server.AddCommand<SwitchGetByNameCommand>("get")
|
|
|
- .WithDescription("List switches or get a switches by name");
|
|
|
+ server.AddCommand<SwitchAddCommand>("add")
|
|
|
+ .WithDescription("Add a new switch");
|
|
|
|
|
|
- server.AddCommand<SwitchDescribeCommand>("describe")
|
|
|
- .WithDescription("Show detailed information about a switch");
|
|
|
+ server.AddCommand<SwitchGetByNameCommand>("get")
|
|
|
+ .WithDescription("List switches or get a switches by name");
|
|
|
|
|
|
- server.AddCommand<SwitchSetCommand>("set")
|
|
|
- .WithDescription("Update switch properties");
|
|
|
+ server.AddCommand<SwitchDescribeCommand>("describe")
|
|
|
+ .WithDescription("Show detailed information about a switch");
|
|
|
|
|
|
- server.AddCommand<SwitchDeleteCommand>("del")
|
|
|
- .WithDescription("Delete a switch");
|
|
|
- });
|
|
|
-
|
|
|
- // ----------------------------
|
|
|
- // Reports (read-only summaries)
|
|
|
- // ----------------------------
|
|
|
- config.AddCommand<AccessPointReportCommand>("ap")
|
|
|
- .WithDescription("Show access point hardware report");
|
|
|
+ server.AddCommand<SwitchSetCommand>("set")
|
|
|
+ .WithDescription("Update switch properties");
|
|
|
+
|
|
|
+ server.AddCommand<SwitchDeleteCommand>("del")
|
|
|
+ .WithDescription("Delete a switch");
|
|
|
+ });
|
|
|
|
|
|
- config.AddCommand<DesktopReportCommand>("desktops")
|
|
|
- .WithDescription("Show desktop hardware report");
|
|
|
+ // ----------------------------
|
|
|
+ // Reports (read-only summaries)
|
|
|
+ // ----------------------------
|
|
|
+ config.AddCommand<AccessPointReportCommand>("ap")
|
|
|
+ .WithDescription("Show access point hardware report");
|
|
|
|
|
|
- config.AddCommand<UpsReportCommand>("ups")
|
|
|
- .WithDescription("Show UPS hardware report");
|
|
|
+ config.AddCommand<DesktopReportCommand>("desktops")
|
|
|
+ .WithDescription("Show desktop hardware report");
|
|
|
|
|
|
- config.ValidateExamples();
|
|
|
+ config.AddCommand<UpsReportCommand>("ups")
|
|
|
+ .WithDescription("Show UPS hardware report");
|
|
|
+
|
|
|
+ config.ValidateExamples();
|
|
|
+ });
|
|
|
});
|
|
|
|
|
|
return await app.RunAsync(args);
|