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

hyperv added to virtualization helper #14359

Merged
merged 1 commit into from May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions chef-utils/lib/chef-utils/dsl/virtualization.rb
Expand Up @@ -184,6 +184,17 @@ def openvz_host?(node = __getnode)
node.dig("virtualization", "system") == "openvz" && node.dig("virtualization", "role") == "host"
end

# Determine if the current node is running under Microsoft Hyper-v.
#
# @param [Chef::Node] node
# @since 18.5
#
# @return [Boolean]
#
def hyperv?(node = __getnode)
node.dig("virtualization", "system") == "hyperv" && node.dig("virtualization", "role") == "guest"
end

# Determine if the current node is running under any virtualization environment
#
# @param [Chef::Node] node
Expand Down
3 changes: 3 additions & 0 deletions chef-utils/spec/unit/dsl/virtualization_spec.rb
Expand Up @@ -45,6 +45,9 @@ def virtualization_reports_true_for(*args, node:)
end
end

context "on hyperv" do
virtualization_reports_true_for(:guest?, :virtual?, :hyperv?, node: { "virtualization" => { "system" => "hyperv", "role" => "guest" } })
end
context "on kvm" do
virtualization_reports_true_for(:guest?, :virtual?, :kvm?, node: { "virtualization" => { "system" => "kvm", "role" => "guest" } })
virtualization_reports_true_for(:hypervisor?, :physical?, :kvm_host?, node: { "virtualization" => { "system" => "kvm", "role" => "host" } })
Expand Down