DhcpReservationCapture

Post-provisioning capture of (mac, ip, hostname) per VM into DhcpReservationFileStore. MAC comes from qm config <vmid> (parsed from the netN: virtio=AA:BB:... line); IP is the address already discovered by DiscoverVmIpViaQmAgent. Best-effort: any failure is logged and swallowed so VM provisioning itself never breaks on a reservation capture error. Call after a successful VM provision step; the next OpnsenseConvergeBridge run will pick the entry up and push it to OPNsense.

public static class DhcpReservationCapture

1. Methods

1.1. ExtractFirstMac(string)

Pure parser: extracts the first AA:BB:CC:DD:EE:FF from a qm config output’s netN: model=MAC,bridge=... line. Returns null when no match. Case-insensitive input, output is uppercase (mirrors qm output).

public static string ExtractFirstMac(string qmConfigOutput)
Table 1. Parameters
Name Type Description

qmConfigOutput

string

Returns: string

1.2. TryCapture(Host, int, NETSetupConfig, string, IPAddress, ILogger)

Captures a reservation for vmId using its already-discovered ip. Returns the reservation when persisted, null when capture failed (MAC missing, file write error, etc.). Safe to call multiple times - Upsert(ConfigName, DhcpReservation) keys by MAC.

public static DhcpReservation TryCapture(Host proxmoxHost, int vmId, NETSetupConfig config, string hostname, IPAddress ip, ILogger logger)
Table 2. Parameters
Name Type Description

proxmoxHost

Host

vmId

int

config

NETSetupConfig

hostname

string

ip

IPAddress

logger

ILogger

Returns: DhcpReservation

1.3. TryGetVmMac(int, ILogger)

Runs qm config <vmId> on the local Proxmox host and parses the first NIC MAC. Returns null when the command fails or no MAC line is present.

public static string TryGetVmMac(int vmId, ILogger logger)
Table 3. Parameters
Name Type Description

vmId

int

logger

ILogger

Returns: string