Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Get-CmiInstance to detect Hyper-V availability #13596

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pkg/minikube/registry/drvs/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,19 @@ func status() registry.State {
ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second)
defer cancel()

cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-Wmiobject Win32_ComputerSystem).HypervisorPresent")
cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-CimInstance Win32_ComputerSystem).HypervisorPresent")
Copy link
Member

Choose a reason for hiding this comment

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

will this work on Old windows versions ?

how about we put the old way as Fail Over option ? if this fails lets try the old way (maybe someone with old windows) ?

Copy link
Member Author

@NikhilSharmaWe NikhilSharmaWe Feb 10, 2022

Choose a reason for hiding this comment

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

I think that will be a nice addition
Should add it and you can review the changes for further improvements ?

Copy link
Member

Choose a reason for hiding this comment

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

Any computer running Windows 7 or greater and Server 2008 SP2 and greater can AND should use PSRemoting instead of WMI. Cim has been supported for a very long time so I don't think we have to worry too much about having a fail over option. But I'm not against it either.

out, err := cmd.CombinedOutput()

if err != nil {
errorMessage := fmt.Errorf("%s failed:\n%s", strings.Join(cmd.Args, " "), out)
fixMessage := "Start PowerShell as an Administrator"
return registry.State{Installed: false, Running: true, Error: errorMessage, Fix: fixMessage, Doc: docURL}
cimError := fmt.Errorf("%s failed:\n%s ", strings.Join(cmd.Args, " "), out)
cmd := exec.CommandContext(ctx, path, "-NoProfile", "-NonInteractive", "@(Get-Wmiobject Win32_ComputerSystem).HypervisorPresent")
out, err := cmd.CombinedOutput()
if err != nil {
wmiError:= fmt.Errorf("%s failed:\n%s ", strings.Join(cmd.Args, " "), out)
errorMessage := fmt.Errorf("%s\n%s", cimError, wmiError)
fixMessage := "Start PowerShell as an Administrator"
return registry.State{Installed: false, Running: true, Error: errorMessage, Fix: fixMessage, Doc: docURL}
}
}

// Get-Wmiobject does not return an error code for false
Expand Down