remote display fixes

This commit is contained in:
2025-08-31 21:56:00 -04:00
parent 40283c2577
commit 0fdfac9d11
2 changed files with 108 additions and 5 deletions

View File

@@ -126,9 +126,13 @@ class Program
case "network":
await HandleNetworkCommandsAsync(arguments);
break;
case "port":
await HandlePortCommandsAsync(arguments);
break;
case "port":
await HandlePortCommandsAsync(arguments);
break;
case "config":
await HandleConfigCommandsAsync(vmService, arguments);
break;
case "exit":
case "quit":
System.Console.WriteLine("Goodbye!");
@@ -1275,6 +1279,91 @@ class Program
portForwards.Add(portForward);
await SavePortForwardsAsync(portForwards);
}
static async Task HandleConfigCommandsAsync(VmManagementService vmService, string[] arguments)
{
if (arguments.Length < 3)
{
System.Console.WriteLine("Usage: config <vm-name> <setting> <value>");
System.Console.WriteLine("Settings:");
System.Console.WriteLine(" display <type> [port] - Set display type (gtk, vnc, spice)");
System.Console.WriteLine(" vga <type> - Set VGA type (std, virtio, qxl)");
System.Console.WriteLine(" memory <size> - Set memory size in GB");
System.Console.WriteLine(" cpu <cores> - Set CPU cores");
System.Console.WriteLine("Examples:");
System.Console.WriteLine(" config ubuntu-desktop display vnc 5900");
System.Console.WriteLine(" config ubuntu-desktop display gtk");
System.Console.WriteLine(" config ubuntu-desktop vga std");
return;
}
var vmName = arguments[0];
var setting = arguments[1].ToLower();
var value = arguments[2];
var config = vmService.GetVmConfiguration(vmName);
if (config == null)
{
System.Console.WriteLine($"VM '{vmName}' not found.");
return;
}
try
{
switch (setting)
{
case "display":
config.Display.Type = value;
if (arguments.Length > 3 && value == "vnc")
{
config.Display.SpicePort = int.Parse(arguments[3]);
}
System.Console.WriteLine($"Display type set to '{value}' for VM '{vmName}'");
break;
case "vga":
config.Display.Vga = value;
System.Console.WriteLine($"VGA type set to '{value}' for VM '{vmName}'");
break;
case "memory":
if (int.TryParse(value, out int memorySize))
{
config.Memory.Size = memorySize;
System.Console.WriteLine($"Memory set to {memorySize}GB for VM '{vmName}'");
}
else
{
System.Console.WriteLine("Invalid memory size. Please specify a number.");
}
break;
case "cpu":
if (int.TryParse(value, out int cpuCores))
{
config.Cpu.Cores = cpuCores;
System.Console.WriteLine($"CPU cores set to {cpuCores} for VM '{vmName}'");
}
else
{
System.Console.WriteLine("Invalid CPU cores. Please specify a number.");
}
break;
default:
System.Console.WriteLine($"Unknown setting '{setting}'");
break;
}
// Save the updated configuration
await vmService.UpdateVmConfigurationAsync(vmName, config);
System.Console.WriteLine($"Configuration updated successfully for VM '{vmName}'");
}
catch (Exception ex)
{
System.Console.WriteLine($"Error updating configuration: {ex.Message}");
}
}
}
public class PortForward