ohcldiag-dev: add GUID-based VM identification#3753
Open
moor-coding wants to merge 3 commits into
Open
Conversation
…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
smalis-msft
reviewed
Jun 16, 2026
| VmId::HyperV(name) => name, | ||
| #[cfg(windows)] | ||
| VmId::HyperVId(_) => { | ||
| anyhow::bail!( |
Contributor
There was a problem hiding this comment.
Is this something that could be supported with more work? Or is there some fundamental limitation here?
smalis-msft
approved these changes
Jun 16, 2026
Contributor
There was a problem hiding this comment.
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) fromhyperv:-prefixed or bare inputs. - Construct clients via
DiagClient::from_hyperv_idwhen a GUID is provided, and plumb GUID support through vsock-related paths. - Add a Windows-only
guiddependency forohcldiag-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 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.
tjones60
reviewed
Jun 16, 2026
| &String::from_utf8(output.stdout)? | ||
| } | ||
| ComPortAccessInfo::IdAndPortNumber(id, num) => { | ||
| let output = Command::new("powershell.exe") |
Contributor
There was a problem hiding this comment.
nit: We could use the powershell command builder here and above
tjones60
reviewed
Jun 16, 2026
| .output() | ||
| .context("failed to query VM com port")?; | ||
|
|
||
| if !output.status.success() { |
Contributor
There was a problem hiding this comment.
nit: some opportunities to reduce duplicate code in these two paths (name vs id)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
VmId::HyperVId(Guid)variant for GUID-based VM identificationhyperv:prefix or bare inputDiagClient::from_hyperv_idguiddependency toohcldiag-dev(Windows only)