Skip to content

ohcldiag-dev: add GUID-based VM identification#3753

Open
moor-coding wants to merge 3 commits into
microsoft:mainfrom
moor-coding:ohcldiag-guid
Open

ohcldiag-dev: add GUID-based VM identification#3753
moor-coding wants to merge 3 commits into
microsoft:mainfrom
moor-coding:ohcldiag-guid

Conversation

@moor-coding

Copy link
Copy Markdown
Contributor

Summary

Add support for identifying VMs by GUID in ohcldiag-dev, in addition to the existing name-based lookup.

Motivation

When working with VMs programmatically or when multiple VMs share similar names, identifying by GUID is more reliable. This is especially useful for automation and tooling scenarios.

Changes

  • Add VmId::HyperVId(Guid) variant for GUID-based VM identification
  • Parse GUIDs (with or without braces) from the hyperv: prefix or bare input
  • Route GUID-based IDs through DiagClient::from_hyperv_id
  • Handle GUID variant in serial, vsock, and crash dump code paths
  • Add guid dependency to ohcldiag-dev (Windows only)

…s trace

- Add VmId::HyperVId variant for direct GUID-based VM connections
- Parse GUID from CLI argument (with or without braces, with hyperv: prefix)
- Route HyperVId through all match arms (serial, vsock, connect)
- Add trace line logging VTL2 settings blob receipt with byte count in GET client
Copilot AI review requested due to automatic review settings June 16, 2026 17:09
@moor-coding moor-coding requested a review from a team as a code owner June 16, 2026 17:09
Comment thread openhcl/ohcldiag-dev/src/main.rs Outdated
VmId::HyperV(name) => name,
#[cfg(windows)]
VmId::HyperVId(_) => {
anyhow::bail!(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that could be supported with more work? Or is there some fundamental limitation here?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends openhcl/ohcldiag-dev VM targeting on Windows to support GUID-based Hyper-V identification (in addition to name-based lookup), routing GUIDs through DiagClient::from_hyperv_id and updating relevant Hyper-V code paths.

Changes:

  • Add a Windows-only VmId::HyperVId(guid::Guid) variant and parse GUIDs (optionally braced) from hyperv:-prefixed or bare inputs.
  • Construct clients via DiagClient::from_hyperv_id when a GUID is provided, and plumb GUID support through vsock-related paths.
  • Add a Windows-only guid dependency for ohcldiag-dev.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
openhcl/ohcldiag-dev/src/main.rs Adds GUID VM ID variant + parsing and uses GUIDs in Hyper-V client/vsock paths; updates serial handling logic.
openhcl/ohcldiag-dev/Cargo.toml Adds Windows-only dependency on guid.
Cargo.lock Records the new resolved dependency on guid.

Comment on lines +359 to +369
// Strip optional "hyperv:" prefix for all Hyper-V variants.
let s = s.strip_prefix("hyperv:").unwrap_or(s);

// Try parsing as a GUID first (with or without braces).
if let Ok(guid) = s.parse::<guid::Guid>() {
return Ok(Self::HyperVId(guid));
}

if !pal::windows::fs::is_unix_socket(s.as_ref()).unwrap_or(false) {
return Ok(Self::HyperV(s.to_owned()));
}
Comment thread openhcl/ohcldiag-dev/src/main.rs Outdated
Comment on lines +673 to +677
VmId::HyperVId(_) => {
anyhow::bail!(
"--serial requires a VM name, not a GUID. Use a named VM instead."
)
}
#[cfg(windows)]
HyperV(String),
#[cfg(windows)]
HyperVId(guid::Guid),
Add IdAndPortNumber variant to ComPortAccessInfo that uses
Get-VMComPort -VMId instead of -VMName, removing the bail
for GUID-based VMs in the --serial path.
&String::from_utf8(output.stdout)?
}
ComPortAccessInfo::IdAndPortNumber(id, num) => {
let output = Command::new("powershell.exe")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could use the powershell command builder here and above

.output()
.context("failed to query VM com port")?;

if !output.status.success() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: some opportunities to reduce duplicate code in these two paths (name vs id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants