Skip to content

Commit

Permalink
determine if we are an Apple Virtualization Framework guest (#1814)
Browse files Browse the repository at this point in the history
* determine if we are an Apple Virtualization Framework guest based on machine_model

---------

Signed-off-by: Jacob Zaval <[email protected]>
  • Loading branch information
jazaval authored Nov 14, 2023
1 parent dc759f4 commit 25fe11a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ohai/plugins/darwin/virtualization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,10 @@ def sysctl_exists?
virtualization[:role] = "host"
virtualization[:systems][:parallels] = "host"
end

if hardware["machine_model"].include? "VirtualMac"
virtualization[:system] = "apple"
virtualization[:role] = "guest"
end
end
end
8 changes: 8 additions & 0 deletions spec/unit/plugins/darwin/virtualization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
allow(plugin).to receive(:docker_exists?).and_return(false)
plugin[:hardware] = Mash.new
plugin[:hardware][:boot_rom_version] = "not_a_vm"
plugin[:hardware][:machine_model] = "not_a_vm"
end

describe "when detecting OS X virtualization" do
Expand Down Expand Up @@ -181,5 +182,12 @@
plugin.run
expect(plugin[:virtualization]).to eq({ "systems" => {} })
end

it "sets apple guest if hardware attributes mention VirtualMac" do
plugin[:hardware][:machine_model] = "VirtualMac2,1"
plugin.run
expect(plugin[:virtualization][:system]).to eq("apple")
expect(plugin[:virtualization][:role]).to eq("guest")
end
end
end

0 comments on commit 25fe11a

Please sign in to comment.