Restore import of config
This commit is contained in:
@@ -46,6 +46,9 @@ Enter choice (1 or 2):
|
|||||||
qemu-vm> create my-first-vm
|
qemu-vm> create my-first-vm
|
||||||
# Follow the interactive prompts
|
# Follow the interactive prompts
|
||||||
|
|
||||||
|
# Import a VM from configuration file
|
||||||
|
qemu-vm> import examples/sample-vm-config.json my-imported-vm
|
||||||
|
|
||||||
# Start the VM
|
# Start the VM
|
||||||
qemu-vm> start my-first-vm
|
qemu-vm> start my-first-vm
|
||||||
|
|
||||||
@@ -198,6 +201,7 @@ qemu-vm> upnp mappings
|
|||||||
|---------|-------------|---------|
|
|---------|-------------|---------|
|
||||||
| `help` | Show all commands | `help` |
|
| `help` | Show all commands | `help` |
|
||||||
| `create` | Create new VM | `create my-vm` |
|
| `create` | Create new VM | `create my-vm` |
|
||||||
|
| `import` | Import VM from config | `import config.json my-vm` |
|
||||||
| `start` | Start VM | `start my-vm` |
|
| `start` | Start VM | `start my-vm` |
|
||||||
| `stop` | Stop VM | `stop my-vm` |
|
| `stop` | Stop VM | `stop my-vm` |
|
||||||
| `status` | Show VM status | `status my-vm` |
|
| `status` | Show VM status | `status my-vm` |
|
||||||
|
@@ -102,6 +102,9 @@ class Program
|
|||||||
case "delete":
|
case "delete":
|
||||||
await DeleteVmAsync(vmService, arguments);
|
await DeleteVmAsync(vmService, arguments);
|
||||||
break;
|
break;
|
||||||
|
case "import":
|
||||||
|
await ImportVmAsync(vmService, arguments);
|
||||||
|
break;
|
||||||
case "status":
|
case "status":
|
||||||
await ShowVmStatusAsync(vmService, arguments);
|
await ShowVmStatusAsync(vmService, arguments);
|
||||||
break;
|
break;
|
||||||
@@ -144,6 +147,7 @@ class Program
|
|||||||
System.Console.WriteLine("Available commands:");
|
System.Console.WriteLine("Available commands:");
|
||||||
System.Console.WriteLine(" list - List all VMs");
|
System.Console.WriteLine(" list - List all VMs");
|
||||||
System.Console.WriteLine(" create <name> - Create a new VM (interactive)");
|
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(" start <name> - Start a VM");
|
||||||
System.Console.WriteLine(" stop <name> [--force] - Stop a VM");
|
System.Console.WriteLine(" stop <name> [--force] - Stop a VM");
|
||||||
System.Console.WriteLine(" pause <name> - Pause 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 = "")
|
static string GetUserInput(string prompt, string defaultValue = "")
|
||||||
{
|
{
|
||||||
System.Console.Write(prompt);
|
System.Console.Write(prompt);
|
||||||
|
@@ -3,79 +3,38 @@
|
|||||||
"description": "Ubuntu Desktop VM for development",
|
"description": "Ubuntu Desktop VM for development",
|
||||||
"cpu": {
|
"cpu": {
|
||||||
"cores": 4,
|
"cores": 4,
|
||||||
"sockets": 1,
|
"model": "host",
|
||||||
"threads": 1,
|
"sockets": 1
|
||||||
"model": "qemu64",
|
|
||||||
"enableKvm": true
|
|
||||||
},
|
},
|
||||||
"memory": {
|
"memory": {
|
||||||
"size": 8192,
|
"sizeGB": 8
|
||||||
"unit": "M"
|
|
||||||
},
|
},
|
||||||
"storage": {
|
"storage": {
|
||||||
"disks": [
|
"disks": [
|
||||||
{
|
{
|
||||||
"path": "C:\\Users\\mahes\\Disks\\ubuntu-desktop.qcow2",
|
"path": "ubuntu-desktop.qcow2",
|
||||||
"size": 50,
|
|
||||||
"format": "qcow2",
|
"format": "qcow2",
|
||||||
"interface": "virtio",
|
"sizeGB": 50,
|
||||||
"cache": "writeback",
|
|
||||||
"isBoot": true
|
"isBoot": true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"path": "C:\\Users\\mahes\\Disks\\ubuntu-data.qcow2",
|
"path": "ubuntu-data.qcow2",
|
||||||
"size": 100,
|
|
||||||
"format": "qcow2",
|
"format": "qcow2",
|
||||||
"interface": "virtio",
|
"sizeGB": 100,
|
||||||
"cache": "writeback",
|
|
||||||
"isBoot": false
|
"isBoot": false
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"cdrom": "C:\\Users\\mahes\\Downloads\\ubuntu-24.04.3-desktop-amd64.iso"
|
"cdrom": {
|
||||||
|
"path": "ubuntu-24.04.3-desktop-amd64.iso",
|
||||||
|
"isBoot": true
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"network": {
|
"network": {
|
||||||
"interfaces": [
|
"backend": "user",
|
||||||
{
|
"device": "e1000"
|
||||||
"type": "bridge",
|
|
||||||
"model": "virtio-net-pci",
|
|
||||||
"mac": "52:54:00:12:34:56",
|
|
||||||
"bridge": "virbr0"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"bridge": "virbr0"
|
|
||||||
},
|
},
|
||||||
"display": {
|
"display": {
|
||||||
"type": "gtk",
|
"type": "gtk",
|
||||||
"vga": "virtio",
|
"vga": "virtio"
|
||||||
"resolution": "1920x1080",
|
}
|
||||||
"enableSpice": true,
|
|
||||||
"spicePort": 5930
|
|
||||||
},
|
|
||||||
"boot": {
|
|
||||||
"order": ["c", "d", "n"],
|
|
||||||
"kernel": null,
|
|
||||||
"initrd": null,
|
|
||||||
"cmdline": null
|
|
||||||
},
|
|
||||||
"advanced": {
|
|
||||||
"enableAudio": true,
|
|
||||||
"enableUsb": true,
|
|
||||||
"enableBalloon": true,
|
|
||||||
"enableVirtioRng": true,
|
|
||||||
"enableVirtioFs": false,
|
|
||||||
"sharedFolders": [
|
|
||||||
{
|
|
||||||
"hostPath": "C:\\Users\\mahes\\Shared",
|
|
||||||
"guestPath": "/mnt/shared",
|
|
||||||
"readOnly": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"extraArgs": [
|
|
||||||
"-enable-kvm",
|
|
||||||
"-cpu",
|
|
||||||
"host"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"created": "2024-01-01T10:00:00Z",
|
|
||||||
"lastModified": "2024-01-01T10:00:00Z"
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user