summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2019-06-11 15:18:31 -0700
committerGitHub <noreply@github.com>2019-06-11 15:18:31 -0700
commitdbacac3bca2213be8a557dbbc26ed515772dafb4 (patch)
treebd0f08e4b49ff74f3e034fb2c2cf437e73546076
parentf04de72cd0a1b8636ca60c238930c4ed60187516 (diff)
parentb42e11f11013d52fed2e8328297e2f76922478c7 (diff)
downloadohai-dbacac3bca2213be8a557dbbc26ed515772dafb4.tar.gz
Merge pull request #1339 from freakinhippie/feature/vbox_host
Add VboxHost plugin to support VirtualBox as a virtualization host
-rw-r--r--RELEASE_NOTES.md4
-rw-r--r--lib/ohai/plugins/vbox_host.rb205
-rw-r--r--spec/unit/plugins/vbox_host_spec.rb332
3 files changed, 541 insertions, 0 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index a2794d83..a3aa1cb8 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -81,6 +81,10 @@ BSD-based systems can now detect guests running on KVM and Amazon's hypervisor w
- Antergos Linux now identified as platform_family 'arch'
- Manjaro Linux now identified as platform_family 'arch'
+## VboxHost (VirtualBox) plugin added
+
+Added VboxHost plugin to detect VirtualBox running as a virtualization host. Provides the 'vbox' attribute tree.
+
# Ohai Release Notes 14.6
## Filesystem Plugin on AIX and Solaris
diff --git a/lib/ohai/plugins/vbox_host.rb b/lib/ohai/plugins/vbox_host.rb
new file mode 100644
index 00000000..b78047ee
--- /dev/null
+++ b/lib/ohai/plugins/vbox_host.rb
@@ -0,0 +1,205 @@
+# Author:: "Joshua Colson" <joshua.colson@gmail.com>
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Ohai.plugin(:VboxHost) do
+ depends "virtualization"
+ provides "vbox"
+
+ # determine if this host is configured with virtualbox or not
+ # the determination is ultimately controlled by the "virtualization" plugin
+ def vbox_host?
+ host = false
+ if !virtualization.nil? && (virtualization["system"] == "vbox" || virtualization["systems"]["vbox"] == "host")
+ host = true if which("VBoxManage")
+ end
+ host
+ end
+
+ # query virtualbox for each configured vm, as well as
+ # each guest"s individual configuration settings
+ def vboxmanage_list_vms
+ vms = Mash.new
+ if vbox_host?
+ so_cmd = "VBoxManage list --sorted vms"
+ logger.trace(so_cmd)
+ so = shell_out(so_cmd)
+
+ if so.exitstatus == 0
+ # parse the output
+ so.stdout.lines.each do |line|
+ case line
+ when /^"(\S*)" \{(\S*)\}$/
+ name = Regexp.last_match(1)
+ uuid = Regexp.last_match(2)
+ vms[name] = vboxmanage_vminfo(uuid)
+ end
+ end
+ end
+ end
+ vms
+ rescue Ohai::Exceptions::Exec
+ logger.trace("Plugin VboxHost: Could not run 'VBoxManage list --sorted vms'. Skipping data")
+ end
+
+ # query the vminfo for particular guest instance, normalizing
+ # the fields so that they"re not enclosed in double-quotes (")
+ def vboxmanage_vminfo(machine_id)
+ vm = Mash.new
+
+ if vbox_host?
+ so_cmd = "VBoxManage showvminfo #{machine_id} --machinereadable"
+ logger.trace(so_cmd)
+ so = shell_out(so_cmd)
+
+ if so.exitstatus == 0
+ so.stdout.lines.each do |line|
+ line.chomp!
+ left, right = line.split("=")
+
+ # remove enclosing quotes, if needed
+ key =
+ case left
+ when /^"(.*)"$/
+ Regexp.last_match(1)
+ else
+ left
+ end
+
+ # skip the name attribute since that is the parent key
+ next if left == "name"
+
+ # remove enclosing quotes, if needed
+ value =
+ case right
+ when /^"(.*)"$/
+ Regexp.last_match(1)
+ else
+ right
+ end
+
+ vm[key.downcase] = value
+ end
+ end
+ end
+ vm
+ rescue Ohai::Exceptions::Exec
+ logger.trace("Plugin VboxHost: Could not run '#{so_cmd}'. Skipping data")
+ end
+
+ # query virtualbox for a list of #{query_type} items
+ # these queries return a result set that is delimited by
+ # multiple successive newlines, with each block containing
+ # key/value pairs delimited by a colon (:) and column aligned
+ #
+ # the keys of each k/v pair are normalized to lowercase
+ def vboxmanage_list_blocks(query_type, name_key)
+ # ignore unrecognized query type
+ supported_queries = %w{
+ bridgedifs dhcpservers dvds hdds hostdvds
+ hostfloppies hostonlyifs natnets ostypes
+ }
+ return nil unless supported_queries.include? query_type
+ results = Mash.new
+
+ if vbox_host?
+ so_cmd = "VBoxManage list --sorted #{query_type}"
+ logger.trace(so_cmd)
+ so = shell_out(so_cmd)
+ # raise an exception if the command fails
+ # so.error!
+
+ if so.exitstatus == 0
+ # break the result into paragraph blocks, on successive newlines
+ so.stdout.each_line("") do |blk|
+ # remove the multiple newlines of each record
+ blk.chomp!.chomp!
+ # initialize a blank record hash
+ record = Mash.new
+ # parse the record block into key/value pairs
+ blk.each_line() do |line|
+ next unless line.include? ":"
+ # split the line into key/value pair
+ key, right = line.split(":", 2)
+
+ # strip the leading/trailing whitespace if the value is not nil
+ value = right.nil? ? "" : right.strip
+ record[key.downcase] = value
+ end
+
+ # insert the record into the list of results
+ if record.key? name_key.downcase
+ name = record.delete(name_key.downcase)
+ results[name] = record
+ end
+ end
+ end
+ end
+ results
+ rescue Ohai::Exceptions::Exec
+ logger.trace("Plugin VboxHost: Could not run '#{so_cmd}'. Skipping data")
+ end
+
+ # collect the data for a virtualization host running VirtualBox
+ collect_data(:default) do
+ ostypes = "ostypes"
+ guests = "guests"
+ natnets = "natnets"
+ hostonlyifs = "hostonlyifs"
+ bridgedifs = "bridgedifs"
+ dhcpservers = "dhcpservers"
+ hdds = "hdds"
+ dvds = "dvds"
+ hostdvds = "hostdvds"
+ hostfloppies = "hostfloppies"
+
+ if vbox_host?
+ vbox Mash.new unless vbox
+
+ # get a list of virtualbox virtual hard disk drives
+ vbox[ostypes] = vboxmanage_list_blocks(ostypes, "ID")
+
+ # get a list of virtualbox guest vms
+ vbox[guests] = vboxmanage_list_vms
+
+ # get a list of virtualbox virtual hard disk drives
+ vbox[hdds] = vboxmanage_list_blocks(hdds, "Location")
+
+ # get a list of virtualbox virtual dvd drives
+ vbox[dvds] = vboxmanage_list_blocks(dvds, "Location")
+
+ # get a list of virtualbox host dvd drives
+ vbox[hostdvds] = vboxmanage_list_blocks(hostdvds, "Name")
+
+ # get a list of virtualbox host floppy drives
+ vbox[hostfloppies] = vboxmanage_list_blocks(hostfloppies, "Name")
+
+ # get a list of virtualbox hostonly network interfaces
+ vbox[hostonlyifs] = vboxmanage_list_blocks(hostonlyifs, "Name")
+
+ # get a list of virtualbox bridged network interfaces
+ vbox[bridgedifs] = vboxmanage_list_blocks(bridgedifs, "Name")
+
+ # get a list of virtualbox dhcp servers
+ vbox[dhcpservers] = vboxmanage_list_blocks(dhcpservers, "NetworkName")
+
+ # get a list of virtualbox nat networks
+ vbox[natnets] = vboxmanage_list_blocks(natnets, "NetworkName")
+ end
+ vbox
+ rescue Ohai::Exceptions::Exec
+ logger.trace("Plugin VboxHost: Could not collect data for VirtualBox host. Skipping data")
+ end
+end
diff --git a/spec/unit/plugins/vbox_host_spec.rb b/spec/unit/plugins/vbox_host_spec.rb
new file mode 100644
index 00000000..b030d31a
--- /dev/null
+++ b/spec/unit/plugins/vbox_host_spec.rb
@@ -0,0 +1,332 @@
+# Author:: "Joshua Colson" <joshua.colson@gmail.com>
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+require_relative "../../spec_helper.rb"
+
+vbox_list_ostypes_stdout = <<~EOF
+ ID: Other
+ Description: Other/Unknown
+ Family ID: Other
+ Family Desc: Other
+ 64 bit: false
+
+ ID: Other_64
+ Description: Other/Unknown (64-bit)
+ Family ID: Other
+ Family Desc: Other
+ 64 bit: true
+
+ ID: Windows31
+ Description: Windows 3.1
+ Family ID: Windows
+ Family Desc: Microsoft Windows
+ 64 bit: false
+
+EOF
+
+vbox_list_vms_stdout = <<~EOF
+ "ubuntu-18.04-amd64_1549746024485_35372" {6294f16b-4f05-4430-afb9-773bdb237aec}
+EOF
+
+vbox_vminfo_stdout = <<~EOF
+ name="ubuntu-18.04-amd64_1549746024485_35372"
+ groups="/"
+ ostype="Ubuntu (64-bit)"
+ UUID="6294f16b-4f05-4430-afb9-773bdb237aec"
+ CfgFile="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64_1549746024485_35372.vbox"
+ SnapFldr="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots"
+ LogFldr="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Logs"
+ hardwareuuid="6294f16b-4f05-4430-afb9-773bdb237aec"
+ memory=1024
+ pagefusion="off"
+ vram=8
+ cpuexecutioncap=100
+ hpet="off"
+ chipset="piix3"
+ firmware="BIOS"
+ cpus=1
+ pae="on"
+ longmode="on"
+ triplefaultreset="off"
+ apic="on"
+ x2apic="on"
+ cpuid-portability-level=0
+ bootmenu="messageandmenu"
+ boot1="disk"
+ boot2="dvd"
+ boot3="none"
+ boot4="none"
+ acpi="on"
+ ioapic="on"
+ biosapic="apic"
+ biossystemtimeoffset=0
+ rtcuseutc="off"
+ hwvirtex="on"
+ nestedpaging="on"
+ largepages="on"
+ vtxvpid="on"
+ vtxux="on"
+ paravirtprovider="default"
+ effparavirtprovider="kvm"
+ VMState="poweroff"
+ VMStateChangeTime="2019-02-09T21:00:33.575000000"
+ monitorcount=1
+ accelerate3d="off"
+ accelerate2dvideo="off"
+ teleporterenabled="off"
+ teleporterport=0
+ teleporteraddress=""
+ teleporterpassword=""
+ tracing-enabled="off"
+ tracing-allow-vm-access="off"
+ tracing-config=""
+ autostart-enabled="off"
+ autostart-delay=0
+ defaultfrontend=""
+ storagecontrollername0="IDE Controller"
+ storagecontrollertype0="PIIX4"
+ storagecontrollerinstance0="0"
+ storagecontrollermaxportcount0="2"
+ storagecontrollerportcount0="2"
+ storagecontrollerbootable0="on"
+ storagecontrollername1="SATA Controller"
+ storagecontrollertype1="IntelAhci"
+ storagecontrollerinstance1="0"
+ storagecontrollermaxportcount1="30"
+ storagecontrollerportcount1="1"
+ storagecontrollerbootable1="on"
+ "IDE Controller-0-0"="none"
+ "IDE Controller-0-1"="none"
+ "IDE Controller-1-0"="none"
+ "IDE Controller-1-1"="none"
+ "SATA Controller-0-0"="/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk"
+ "SATA Controller-ImageUUID-0-0"="1c182745-4b09-41a1-a147-d3ced46f72f6"
+ natnet1="nat"
+ macaddress1="080027E5FA8F"
+ cableconnected1="on"
+ nic1="nat"
+ nictype1="82540EM"
+ nicspeed1="0"
+ mtu="0"
+ sockSnd="64"
+ sockRcv="64"
+ tcpWndSnd="64"
+ tcpWndRcv="64"
+ nic2="none"
+ nic3="none"
+ nic4="none"
+ nic5="none"
+ nic6="none"
+ nic7="none"
+ nic8="none"
+ hidpointing="ps2mouse"
+ hidkeyboard="ps2kbd"
+ uart1="off"
+ uart2="off"
+ uart3="off"
+ uart4="off"
+ lpt1="off"
+ lpt2="off"
+ audio="pulse"
+ audio_in="false"
+ audio_out="false"
+ clipboard="disabled"
+ draganddrop="disabled"
+ vrde="on"
+ vrdeport=-1
+ vrdeports="5947"
+ vrdeaddress="127.0.0.1"
+ vrdeauthtype="null"
+ vrdemulticon="off"
+ vrdereusecon="off"
+ vrdevideochannel="off"
+ vrdeproperty[TCP/Ports]="5947"
+ vrdeproperty[TCP/Address]="127.0.0.1"
+ usb="off"
+ ehci="off"
+ xhci="off"
+ GuestMemoryBalloon=0
+ SnapshotName="base"
+ SnapshotUUID="085cbbec-70cd-4864-9208-5d938dcabb71"
+ CurrentSnapshotName="base"
+ CurrentSnapshotUUID="085cbbec-70cd-4864-9208-5d938dcabb71"
+ CurrentSnapshotNode="SnapshotName"
+EOF
+
+vbox_list_hdds_stdout = <<~EOF
+ UUID: ebb6dca0-879f-480b-a50e-9efe330bd021
+ Parent UUID: base
+ State: locked read
+ Type: normal (base)
+ Location: /virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64-disk001.vmdk
+ Storage format: VMDK
+ Capacity: 65536 MBytes
+ Encryption: disabled
+
+ UUID: 1c182745-4b09-41a1-a147-d3ced46f72f6
+ Parent UUID: ebb6dca0-879f-480b-a50e-9efe330bd021
+ State: created
+ Type: normal (differencing)
+ Location: /virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk
+ Storage format: VMDK
+ Capacity: 65536 MBytes
+ Encryption: disabled
+
+EOF
+
+vbox_list_dvds_stdout = <<~EOF
+ UUID: 897aa7bc-1ec1-4e13-a16d-101d3716c72d
+ State: created
+ Type: normal (base)
+ Location: /tmp/test.dvd
+ Storage format: RAW
+ Capacity: 100 MBytes
+ Encryption: disabled
+
+EOF
+
+vbox_list_hostdvds_stdout = <<~EOF
+ UUID: 00445644-0000-0000-2f64-65762f737230
+ Name: /dev/sr0
+
+EOF
+
+vbox_list_hostfloppies_stdout = <<~EOF
+
+EOF
+
+vbox_list_hostonlyifs_stdout = <<~EOF
+ Name: vboxnet0
+ GUID: 786f6276-656e-4074-8000-0a0027000000
+ DHCP: Disabled
+ IPAddress: 192.168.33.1
+ NetworkMask: 255.255.255.0
+ IPV6Address:
+ IPV6NetworkMaskPrefixLength: 0
+ HardwareAddress: 0a:00:27:00:00:00
+ MediumType: Ethernet
+ Wireless: No
+ Status: Down
+ VBoxNetworkName: HostInterfaceNetworking-vboxnet0
+
+ Name: vboxnet1
+ GUID: 786f6276-656e-4174-8000-0a0027000001
+ DHCP: Disabled
+ IPAddress: 192.168.19.1
+ NetworkMask: 255.255.255.0
+ IPV6Address: fe80::800:27ff:fe00:1
+ IPV6NetworkMaskPrefixLength: 64
+ HardwareAddress: 0a:00:27:00:00:01
+ MediumType: Ethernet
+ Wireless: No
+ Status: Up
+ VBoxNetworkName: HostInterfaceNetworking-vboxnet1
+
+EOF
+
+vbox_list_bridgedifs_stdout = <<~EOF
+ Name: eno1
+ GUID: 316f6e65-0000-4000-8000-309c233b62a9
+ DHCP: Disabled
+ IPAddress: 10.143.72.133
+ NetworkMask: 255.255.255.224
+ IPV6Address: fe80::9226:82e9:1101:60e6
+ IPV6NetworkMaskPrefixLength: 64
+ HardwareAddress: 30:9c:23:3b:62:a9
+ MediumType: Ethernet
+ Wireless: No
+ Status: Up
+ VBoxNetworkName: HostInterfaceNetworking-eno1
+
+EOF
+
+vbox_list_dhcpservers_stdout = <<~EOF
+ NetworkName: HostInterfaceNetworking-vboxnet0
+ IP: 192.168.56.100
+ NetworkMask: 255.255.255.0
+ lowerIPAddress: 192.168.56.101
+ upperIPAddress: 192.168.56.254
+ Enabled: Yes
+
+ NetworkName: HostInterfaceNetworking-vboxnet1
+ IP: 192.168.19.2
+ NetworkMask: 255.255.255.0
+ lowerIPAddress: 192.168.19.3
+ upperIPAddress: 192.168.19.254
+ Enabled: Yes
+
+EOF
+
+# output of: VBoxManage list --sorted natnets
+vbox_list_natnets_stdout = <<~EOF
+ NetworkName: NatNetwork
+ IP: 10.0.2.1
+ Network: 10.0.2.0/24
+ IPv6 Enabled: No
+ IPv6 Prefix: fd17:625c:f037:2::/64
+ DHCP Enabled: Yes
+ Enabled: Yes
+ loopback mappings (ipv4)
+ 127.0.0.1=2
+
+EOF
+
+expected_output = { "ostypes" => { "Other" => { "description" => "Other/Unknown", "family id" => "Other", "family desc" => "Other", "64 bit" => "false" }, "Other_64" => { "description" => "Other/Unknown (64-bit)", "family id" => "Other", "family desc" => "Other", "64 bit" => "true" }, "Windows31" => { "description" => "Windows 3.1", "family id" => "Windows", "family desc" => "Microsoft Windows", "64 bit" => "false" } }, "guests" => { "ubuntu-18.04-amd64_1549746024485_35372" => { "groups" => "/", "ostype" => "Ubuntu (64-bit)", "uuid" => "6294f16b-4f05-4430-afb9-773bdb237aec", "cfgfile" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64_1549746024485_35372.vbox", "snapfldr" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots", "logfldr" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Logs", "hardwareuuid" => "6294f16b-4f05-4430-afb9-773bdb237aec", "memory" => "1024", "pagefusion" => "off", "vram" => "8", "cpuexecutioncap" => "100", "hpet" => "off", "chipset" => "piix3", "firmware" => "BIOS", "cpus" => "1", "pae" => "on", "longmode" => "on", "triplefaultreset" => "off", "apic" => "on", "x2apic" => "on", "cpuid-portability-level" => "0", "bootmenu" => "messageandmenu", "boot1" => "disk", "boot2" => "dvd", "boot3" => "none", "boot4" => "none", "acpi" => "on", "ioapic" => "on", "biosapic" => "apic", "biossystemtimeoffset" => "0", "rtcuseutc" => "off", "hwvirtex" => "on", "nestedpaging" => "on", "largepages" => "on", "vtxvpid" => "on", "vtxux" => "on", "paravirtprovider" => "default", "effparavirtprovider" => "kvm", "vmstate" => "poweroff", "vmstatechangetime" => "2019-02-09T21:00:33.575000000", "monitorcount" => "1", "accelerate3d" => "off", "accelerate2dvideo" => "off", "teleporterenabled" => "off", "teleporterport" => "0", "teleporteraddress" => "", "teleporterpassword" => "", "tracing-enabled" => "off", "tracing-allow-vm-access" => "off", "tracing-config" => "", "autostart-enabled" => "off", "autostart-delay" => "0", "defaultfrontend" => "", "storagecontrollername0" => "IDE Controller", "storagecontrollertype0" => "PIIX4", "storagecontrollerinstance0" => "0", "storagecontrollermaxportcount0" => "2", "storagecontrollerportcount0" => "2", "storagecontrollerbootable0" => "on", "storagecontrollername1" => "SATA Controller", "storagecontrollertype1" => "IntelAhci", "storagecontrollerinstance1" => "0", "storagecontrollermaxportcount1" => "30", "storagecontrollerportcount1" => "1", "storagecontrollerbootable1" => "on", "ide controller-0-0" => "none", "ide controller-0-1" => "none", "ide controller-1-0" => "none", "ide controller-1-1" => "none", "sata controller-0-0" => "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk", "sata controller-imageuuid-0-0" => "1c182745-4b09-41a1-a147-d3ced46f72f6", "natnet1" => "nat", "macaddress1" => "080027E5FA8F", "cableconnected1" => "on", "nic1" => "nat", "nictype1" => "82540EM", "nicspeed1" => "0", "mtu" => "0", "socksnd" => "64", "sockrcv" => "64", "tcpwndsnd" => "64", "tcpwndrcv" => "64", "nic2" => "none", "nic3" => "none", "nic4" => "none", "nic5" => "none", "nic6" => "none", "nic7" => "none", "nic8" => "none", "hidpointing" => "ps2mouse", "hidkeyboard" => "ps2kbd", "uart1" => "off", "uart2" => "off", "uart3" => "off", "uart4" => "off", "lpt1" => "off", "lpt2" => "off", "audio" => "pulse", "audio_in" => "false", "audio_out" => "false", "clipboard" => "disabled", "draganddrop" => "disabled", "vrde" => "on", "vrdeport" => "-1", "vrdeports" => "5947", "vrdeaddress" => "127.0.0.1", "vrdeauthtype" => "null", "vrdemulticon" => "off", "vrdereusecon" => "off", "vrdevideochannel" => "off", "vrdeproperty[tcp/ports]" => "5947", "vrdeproperty[tcp/address]" => "127.0.0.1", "usb" => "off", "ehci" => "off", "xhci" => "off", "guestmemoryballoon" => "0", "snapshotname" => "base", "snapshotuuid" => "085cbbec-70cd-4864-9208-5d938dcabb71", "currentsnapshotname" => "base", "currentsnapshotuuid" => "085cbbec-70cd-4864-9208-5d938dcabb71", "currentsnapshotnode" => "SnapshotName" } }, "hdds" => { "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/ubuntu-18.04-amd64-disk001.vmdk" => { "uuid" => "ebb6dca0-879f-480b-a50e-9efe330bd021", "parent uuid" => "base", "state" => "locked read", "type" => "normal (base)", "storage format" => "VMDK", "capacity" => "65536 MBytes", "encryption" => "disabled" }, "/virtual/machines/ubuntu-18.04-amd64_1549746024485_35372/Snapshots/{1c182745-4b09-41a1-a147-d3ced46f72f6}.vmdk" => { "uuid" => "1c182745-4b09-41a1-a147-d3ced46f72f6", "parent uuid" => "ebb6dca0-879f-480b-a50e-9efe330bd021", "state" => "created", "type" => "normal (differencing)", "storage format" => "VMDK", "capacity" => "65536 MBytes", "encryption" => "disabled" } }, "dvds" => { "/tmp/test.dvd" => { "uuid" => "897aa7bc-1ec1-4e13-a16d-101d3716c72d", "state" => "created", "type" => "normal (base)", "storage format" => "RAW", "capacity" => "100 MBytes", "encryption" => "disabled" } }, "hostdvds" => { "/dev/sr0" => { "uuid" => "00445644-0000-0000-2f64-65762f737230" } }, "hostfloppies" => {}, "hostonlyifs" => { "vboxnet0" => { "guid" => "786f6276-656e-4074-8000-0a0027000000", "dhcp" => "Disabled", "ipaddress" => "192.168.33.1", "networkmask" => "255.255.255.0", "ipv6address" => "", "ipv6networkmaskprefixlength" => "0", "hardwareaddress" => "0a:00:27:00:00:00", "mediumtype" => "Ethernet", "wireless" => "No", "status" => "Down", "vboxnetworkname" => "HostInterfaceNetworking-vboxnet0" }, "vboxnet1" => { "guid" => "786f6276-656e-4174-8000-0a0027000001", "dhcp" => "Disabled", "ipaddress" => "192.168.19.1", "networkmask" => "255.255.255.0", "ipv6address" => "fe80::800:27ff:fe00:1", "ipv6networkmaskprefixlength" => "64", "hardwareaddress" => "0a:00:27:00:00:01", "mediumtype" => "Ethernet", "wireless" => "No", "status" => "Up", "vboxnetworkname" => "HostInterfaceNetworking-vboxnet1" } }, "bridgedifs" => { "eno1" => { "guid" => "316f6e65-0000-4000-8000-309c233b62a9", "dhcp" => "Disabled", "ipaddress" => "10.143.72.133", "networkmask" => "255.255.255.224", "ipv6address" => "fe80::9226:82e9:1101:60e6", "ipv6networkmaskprefixlength" => "64", "hardwareaddress" => "30:9c:23:3b:62:a9", "mediumtype" => "Ethernet", "wireless" => "No", "status" => "Up", "vboxnetworkname" => "HostInterfaceNetworking-eno1" } }, "dhcpservers" => { "HostInterfaceNetworking-vboxnet0" => { "ip" => "192.168.56.100", "networkmask" => "255.255.255.0", "loweripaddress" => "192.168.56.101", "upperipaddress" => "192.168.56.254", "enabled" => "Yes" }, "HostInterfaceNetworking-vboxnet1" => { "ip" => "192.168.19.2", "networkmask" => "255.255.255.0", "loweripaddress" => "192.168.19.3", "upperipaddress" => "192.168.19.254", "enabled" => "Yes" } }, "natnets" => { "NatNetwork" => { "ip" => "10.0.2.1", "network" => "10.0.2.0/24", "ipv6 enabled" => "No", "ipv6 prefix" => "fd17:625c:f037:2::/64", "dhcp enabled" => "Yes", "enabled" => "Yes" } } }
+
+describe Ohai::System, "plugin vbox_host" do
+ let(:plugin) { get_plugin("vbox_host") }
+
+ context "if the host does not have virtualbox installed" do
+ it "should not create a vbox attribute" do
+ plugin[:virtualization] = Mash.new
+ plugin[:virtualization][:systems] = Mash.new
+ plugin.run
+ expect(plugin).not_to have_key(:vbox)
+ end
+ end
+
+ context "if the host has virtualbox installed" do
+ it "should create a vbox attribute with accurate data" do
+ plugin[:virtualization] = Mash.new
+ plugin[:virtualization][:systems] = Mash.new
+ plugin[:virtualization][:systems][:vbox] = "host"
+ allow(plugin).to receive(:which).with("VBoxManage").and_return("/usr/bin/VBoxManage")
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted ostypes").and_return(mock_shell_out(0, vbox_list_ostypes_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted vms").and_return(mock_shell_out(0, vbox_list_vms_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage showvminfo 6294f16b-4f05-4430-afb9-773bdb237aec --machinereadable").and_return(mock_shell_out(0, vbox_vminfo_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hdds").and_return(mock_shell_out(0, vbox_list_hdds_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted dvds").and_return(mock_shell_out(0, vbox_list_dvds_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostdvds").and_return(mock_shell_out(0, vbox_list_hostdvds_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostfloppies").and_return(mock_shell_out(0, vbox_list_hostfloppies_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted hostonlyifs").and_return(mock_shell_out(0, vbox_list_hostonlyifs_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted bridgedifs").and_return(mock_shell_out(0, vbox_list_bridgedifs_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted dhcpservers").and_return(mock_shell_out(0, vbox_list_dhcpservers_stdout, ""))
+ allow(plugin).to receive(:shell_out).with("VBoxManage list --sorted natnets").and_return(mock_shell_out(0, vbox_list_natnets_stdout, ""))
+ plugin.run
+ expect(plugin).to have_key(:vbox)
+ # expect(plugin[:vbox]['ostypes']).to eq(expected_output['ostypes'])
+ # expect(plugin[:vbox]['guests']).to eq(expected_output['guests'])
+ # expect(plugin[:vbox]['hdds']).to eq(expected_output['hdds'])
+ # expect(plugin[:vbox]['dvds']).to eq(expected_output['dvds'])
+ # expect(plugin[:vbox]['hostdvds']).to eq(expected_output['hostdvds'])
+ # expect(plugin[:vbox]['hostfloppies']).to eq(expected_output['hostfloppies'])
+ # expect(plugin[:vbox]['hostonlyifs']).to eq(expected_output['hostonlyifs'])
+ # expect(plugin[:vbox]['bridgedifs']).to eq(expected_output['bridgedifs'])
+ # expect(plugin[:vbox]['dhcpservers']).to eq(expected_output['dhcpservers'])
+ # expect(plugin[:vbox]['natnets']).to eq(expected_output['natnets'])
+ expect(plugin[:vbox]).to eq(expected_output)
+ end
+ end
+end