Restore import of config
This commit is contained in:
@@ -102,6 +102,9 @@ class Program
|
||||
case "delete":
|
||||
await DeleteVmAsync(vmService, arguments);
|
||||
break;
|
||||
case "import":
|
||||
await ImportVmAsync(vmService, arguments);
|
||||
break;
|
||||
case "status":
|
||||
await ShowVmStatusAsync(vmService, arguments);
|
||||
break;
|
||||
@@ -144,6 +147,7 @@ class Program
|
||||
System.Console.WriteLine("Available commands:");
|
||||
System.Console.WriteLine(" list - List all VMs");
|
||||
System.Console.WriteLine(" create <name> - Create a new VM (interactive)");
|
||||
System.Console.WriteLine(" import <path> [name] - Import VM from configuration file");
|
||||
System.Console.WriteLine(" start <name> - Start a VM");
|
||||
System.Console.WriteLine(" stop <name> [--force] - Stop a VM");
|
||||
System.Console.WriteLine(" pause <name> - Pause a VM");
|
||||
@@ -760,6 +764,49 @@ class Program
|
||||
}
|
||||
}
|
||||
|
||||
static async Task ImportVmAsync(VmManagementService vmService, string[] arguments)
|
||||
{
|
||||
if (arguments.Length == 0)
|
||||
{
|
||||
System.Console.WriteLine("Usage: import <config-file-path> [new-vm-name]");
|
||||
System.Console.WriteLine("Example: import examples/sample-vm-config.json my-imported-vm");
|
||||
return;
|
||||
}
|
||||
|
||||
var configPath = arguments[0];
|
||||
var newName = arguments.Length > 1 ? arguments[1] : null;
|
||||
|
||||
try
|
||||
{
|
||||
System.Console.WriteLine($"Importing VM configuration from: {configPath}");
|
||||
|
||||
var importedConfig = await vmService.ImportVmConfigurationAsync(configPath, newName);
|
||||
|
||||
System.Console.WriteLine($"Successfully imported VM '{importedConfig.Name}'");
|
||||
System.Console.WriteLine($"Description: {importedConfig.Description}");
|
||||
System.Console.WriteLine($"CPU: {importedConfig.Cpu.Cores} cores");
|
||||
System.Console.WriteLine($"Memory: {importedConfig.Memory.Size}{importedConfig.Memory.Unit}");
|
||||
|
||||
if (importedConfig.Storage.Disks.Any())
|
||||
{
|
||||
System.Console.WriteLine("Disks:");
|
||||
foreach (var disk in importedConfig.Storage.Disks)
|
||||
{
|
||||
System.Console.WriteLine($" - {disk.Path} ({disk.Size}GB, {disk.Format})");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
System.Console.WriteLine($"Error: Configuration file '{configPath}' not found");
|
||||
System.Console.WriteLine("Make sure the file path is correct and the file exists.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Console.WriteLine($"Error importing VM: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
static string GetUserInput(string prompt, string defaultValue = "")
|
||||
{
|
||||
System.Console.Write(prompt);
|
||||
|
Reference in New Issue
Block a user