using System.Text.Json.Serialization;
using Newtonsoft.Json;
namespace PSProxmoxVE.Core.Models.Vms;
///
/// Represents the configuration of a QEMU/KVM virtual machine,
/// as returned by the /nodes/{node}/qemu/{vmid}/config endpoint.
///
public class PveVmConfig
{
// -------------------------------------------------------------------------
// CPU / Memory
// -------------------------------------------------------------------------
///
/// Number of CPU cores per socket.
///
[JsonPropertyName("cores")]
[JsonProperty("cores")]
public int? Cores { get; set; }
///
/// Number of CPU sockets.
///
[JsonPropertyName("sockets")]
[JsonProperty("sockets")]
public int? Sockets { get; set; }
///
/// Memory size in megabytes.
///
[JsonPropertyName("memory")]
[JsonProperty("memory")]
public int? Memory { get; set; }
///
/// Emulated CPU type (e.g., "host", "x86-64-v2-AES").
///
[JsonPropertyName("cpu")]
[JsonProperty("cpu")]
public string? CpuType { get; set; }
// -------------------------------------------------------------------------
// Firmware / Machine
// -------------------------------------------------------------------------
///
/// BIOS implementation to use: "seabios" (default) or "ovmf" (UEFI).
///
[JsonPropertyName("bios")]
[JsonProperty("bios")]
public string? Bios { get; set; }
///
/// Emulated machine type (e.g., "q35", "i440fx").
///
[JsonPropertyName("machine")]
[JsonProperty("machine")]
public string? Machine { get; set; }
// -------------------------------------------------------------------------
// Boot / Args
// -------------------------------------------------------------------------
///
/// Boot order specification string.
///
[JsonPropertyName("boot")]
[JsonProperty("boot")]
public string? Boot { get; set; }
///
/// Arbitrary QEMU command-line arguments appended to the QEMU launch command.
///
[JsonPropertyName("args")]
[JsonProperty("args")]
public string? Args { get; set; }
// -------------------------------------------------------------------------
// Metadata
// -------------------------------------------------------------------------
///
/// Human-readable description or notes for the VM.
///
[JsonPropertyName("description")]
[JsonProperty("description")]
public string? Description { get; set; }
///
/// Semicolon-separated list of tags assigned to the VM.
///
[JsonPropertyName("tags")]
[JsonProperty("tags")]
public string? Tags { get; set; }
///
/// When set to 1, prevents the VM from being deleted or modified accidentally.
///
[JsonPropertyName("protection")]
[JsonProperty("protection")]
public int? Protection { get; set; }
///
/// NUMA topology enabled (1) or disabled (0).
///
[JsonPropertyName("numa")]
[JsonProperty("numa")]
public int? Numa { get; set; }
///
/// VirtIO balloon device target memory in MB. 0 disables ballooning.
///
[JsonPropertyName("balloon")]
[JsonProperty("balloon")]
public int? Balloon { get; set; }
///
/// Guest OS type hint (e.g., "l26" for Linux 2.6+, "win10").
///
[JsonPropertyName("ostype")]
[JsonProperty("ostype")]
public string? OsType { get; set; }
// -------------------------------------------------------------------------
// VirtIO disk slots (0–3, most commonly used)
// -------------------------------------------------------------------------
/// VirtIO disk slot 0 configuration string.
[JsonPropertyName("virtio0")]
[JsonProperty("virtio0")]
public string? Virtio0 { get; set; }
/// VirtIO disk slot 1 configuration string.
[JsonPropertyName("virtio1")]
[JsonProperty("virtio1")]
public string? Virtio1 { get; set; }
/// VirtIO disk slot 2 configuration string.
[JsonPropertyName("virtio2")]
[JsonProperty("virtio2")]
public string? Virtio2 { get; set; }
/// VirtIO disk slot 3 configuration string.
[JsonPropertyName("virtio3")]
[JsonProperty("virtio3")]
public string? Virtio3 { get; set; }
// -------------------------------------------------------------------------
// SCSI disk slots (0–7)
// -------------------------------------------------------------------------
/// SCSI disk slot 0 configuration string.
[JsonPropertyName("scsi0")]
[JsonProperty("scsi0")]
public string? Scsi0 { get; set; }
/// SCSI disk slot 1 configuration string.
[JsonPropertyName("scsi1")]
[JsonProperty("scsi1")]
public string? Scsi1 { get; set; }
/// SCSI disk slot 2 configuration string.
[JsonPropertyName("scsi2")]
[JsonProperty("scsi2")]
public string? Scsi2 { get; set; }
/// SCSI disk slot 3 configuration string.
[JsonPropertyName("scsi3")]
[JsonProperty("scsi3")]
public string? Scsi3 { get; set; }
/// SCSI disk slot 4 configuration string.
[JsonPropertyName("scsi4")]
[JsonProperty("scsi4")]
public string? Scsi4 { get; set; }
/// SCSI disk slot 5 configuration string.
[JsonPropertyName("scsi5")]
[JsonProperty("scsi5")]
public string? Scsi5 { get; set; }
/// SCSI disk slot 6 configuration string.
[JsonPropertyName("scsi6")]
[JsonProperty("scsi6")]
public string? Scsi6 { get; set; }
/// SCSI disk slot 7 configuration string.
[JsonPropertyName("scsi7")]
[JsonProperty("scsi7")]
public string? Scsi7 { get; set; }
// -------------------------------------------------------------------------
// IDE disk slots (0–3)
// -------------------------------------------------------------------------
/// IDE disk/CDROM slot 0 configuration string.
[JsonPropertyName("ide0")]
[JsonProperty("ide0")]
public string? Ide0 { get; set; }
/// IDE disk/CDROM slot 1 configuration string.
[JsonPropertyName("ide1")]
[JsonProperty("ide1")]
public string? Ide1 { get; set; }
/// IDE disk/CDROM slot 2 configuration string.
[JsonPropertyName("ide2")]
[JsonProperty("ide2")]
public string? Ide2 { get; set; }
/// IDE disk/CDROM slot 3 configuration string.
[JsonPropertyName("ide3")]
[JsonProperty("ide3")]
public string? Ide3 { get; set; }
// -------------------------------------------------------------------------
// SATA disk slots (0–5)
// -------------------------------------------------------------------------
/// SATA disk slot 0 configuration string.
[JsonPropertyName("sata0")]
[JsonProperty("sata0")]
public string? Sata0 { get; set; }
/// SATA disk slot 1 configuration string.
[JsonPropertyName("sata1")]
[JsonProperty("sata1")]
public string? Sata1 { get; set; }
/// SATA disk slot 2 configuration string.
[JsonPropertyName("sata2")]
[JsonProperty("sata2")]
public string? Sata2 { get; set; }
/// SATA disk slot 3 configuration string.
[JsonPropertyName("sata3")]
[JsonProperty("sata3")]
public string? Sata3 { get; set; }
/// SATA disk slot 4 configuration string.
[JsonPropertyName("sata4")]
[JsonProperty("sata4")]
public string? Sata4 { get; set; }
/// SATA disk slot 5 configuration string.
[JsonPropertyName("sata5")]
[JsonProperty("sata5")]
public string? Sata5 { get; set; }
// -------------------------------------------------------------------------
// Network interface slots (0–7)
// -------------------------------------------------------------------------
/// Network interface 0 configuration string (e.g., "virtio=XX:XX:XX:XX:XX:XX,bridge=vmbr0").
[JsonPropertyName("net0")]
[JsonProperty("net0")]
public string? Net0 { get; set; }
/// Network interface 1 configuration string.
[JsonPropertyName("net1")]
[JsonProperty("net1")]
public string? Net1 { get; set; }
/// Network interface 2 configuration string.
[JsonPropertyName("net2")]
[JsonProperty("net2")]
public string? Net2 { get; set; }
/// Network interface 3 configuration string.
[JsonPropertyName("net3")]
[JsonProperty("net3")]
public string? Net3 { get; set; }
/// Network interface 4 configuration string.
[JsonPropertyName("net4")]
[JsonProperty("net4")]
public string? Net4 { get; set; }
/// Network interface 5 configuration string.
[JsonPropertyName("net5")]
[JsonProperty("net5")]
public string? Net5 { get; set; }
/// Network interface 6 configuration string.
[JsonPropertyName("net6")]
[JsonProperty("net6")]
public string? Net6 { get; set; }
/// Network interface 7 configuration string.
[JsonPropertyName("net7")]
[JsonProperty("net7")]
public string? Net7 { get; set; }
// -------------------------------------------------------------------------
// Cloud-Init
// -------------------------------------------------------------------------
/// Cloud-Init default user name.
[JsonPropertyName("ciuser")]
[JsonProperty("ciuser")]
public string? CiUser { get; set; }
/// Cloud-Init default user password (hashed or plaintext depending on PVE version).
[JsonPropertyName("cipassword")]
[JsonProperty("cipassword")]
public string? CiPassword { get; set; }
/// URL-encoded SSH public keys injected by Cloud-Init.
[JsonPropertyName("sshkeys")]
[JsonProperty("sshkeys")]
public string? SshKeys { get; set; }
/// Cloud-Init IP configuration for interface 0.
[JsonPropertyName("ipconfig0")]
[JsonProperty("ipconfig0")]
public string? IpConfig0 { get; set; }
/// Cloud-Init IP configuration for interface 1.
[JsonPropertyName("ipconfig1")]
[JsonProperty("ipconfig1")]
public string? IpConfig1 { get; set; }
/// Cloud-Init IP configuration for interface 2.
[JsonPropertyName("ipconfig2")]
[JsonProperty("ipconfig2")]
public string? IpConfig2 { get; set; }
/// Cloud-Init IP configuration for interface 3.
[JsonPropertyName("ipconfig3")]
[JsonProperty("ipconfig3")]
public string? IpConfig3 { get; set; }
/// DNS nameserver(s) injected via Cloud-Init.
[JsonPropertyName("nameserver")]
[JsonProperty("nameserver")]
public string? Nameserver { get; set; }
/// DNS search domain injected via Cloud-Init.
[JsonPropertyName("searchdomain")]
[JsonProperty("searchdomain")]
public string? Searchdomain { get; set; }
///
public override string ToString()
{
var totalCores = (Cores ?? 1) * (Sockets ?? 1);
return $"Config | CPUs: {totalCores} ({Sockets ?? 1}S x {Cores ?? 1}C) | "
+ $"Memory: {Memory?.ToString() ?? "N/A"} MB | BIOS: {Bios ?? "seabios"} | "
+ $"Machine: {Machine ?? "default"} | OS: {OsType ?? "N/A"}";
}
}