QmGuestAgentExtensions

Proxmox qemu-guest-agent IP discovery. Polls the corsinvest API for guest-reported network interfaces, filters ipv4 addresses, excluding loopback (127.0.0.0/8) and link-local (169.254.0.0/16). Throws NETSetupException on timeout.

public static class QmGuestAgentExtensions

1. Fields

1.1. DefaultPollInterval

Default poll interval between guest-agent queries.

public static readonly TimeSpan DefaultPollInterval

2. Methods

2.1. DiscoverVmIpViaQmAgent(Host, int, TimeSpan, ILogger)

Polls host for vmId’s first usable ipv4 until deadline.

public static IPAddress DiscoverVmIpViaQmAgent(this Host host, int vmId, TimeSpan deadline, ILogger logger)
Table 1. Parameters
Name Type Description

host

Host

vmId

int

deadline

TimeSpan

logger

ILogger

Returns: IPAddress

2.2. ParseHostNameFromJson(string)

Pure parser for guest-get-host-name JSON. Returns null on parse failure.

public static string ParseHostNameFromJson(string json)
Table 2. Parameters
Name Type Description

json

string

Returns: string

2.3. PollForIp(Func<string>, int, TimeSpan, TimeSpan, ILogger)

Polling loop seam used for testing. fetchJson returns the current guest-agent JSON (or null if unavailable). Polls every DefaultPollInterval until first usable ipv4 or deadline. Throws on timeout.

public static IPAddress PollForIp(Func<string> fetchJson, int vmId, TimeSpan deadline, TimeSpan pollInterval, ILogger logger)
Table 3. Parameters
Name Type Description

fetchJson

Func<string>

vmId

int

deadline

TimeSpan

pollInterval

TimeSpan

logger

ILogger

Returns: IPAddress

2.4. TryGetGuestHostName(Host, int, ILogger)

Single-shot guest-hostname probe via qemu-guest-agent. Returns null when the agent is unreachable or the call fails — caller treats null as "unknown" (e.g. still on installer ISO, agent not yet up, etc.). Used to detect an already-installed VM: the live NixOS installer ISO reports hostname "nixos", an installed system reports its networking.hostName (machine.Name).

public static string TryGetGuestHostName(this Host host, int vmId, ILogger logger)
Table 4. Parameters
Name Type Description

host

Host

vmId

int

logger

ILogger

Returns: string

2.5. TrySelectFirstUsableIpv4(string, IPAddress?)

Pure parser: extracts the first usable ipv4 from a corsinvest agent/network-get-interfaces JSON payload. Returns false when no usable address is present. Excludes loopback and link-local.

public static bool TrySelectFirstUsableIpv4(string json, out IPAddress? address)
Table 5. Parameters
Name Type Description

json

string

address

IPAddress?

Returns: bool