This file is indexed.

/usr/share/perl5/Rex/Hardware/VirtInfo.pm is in rex 1.4.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package Rex::Hardware::VirtInfo;

use strict;
use warnings;

our $VERSION = '1.4.1'; # VERSION

use Rex;
use Rex::Commands::Run;
use Rex::Helper::Run;
use Rex::Commands::Fs;
use Rex::Commands::File;
use Rex::Logger;

use Rex::Inventory::Bios;

require Rex::Hardware;

sub get {

  my $cache          = Rex::get_cache();
  my $cache_key_name = $cache->gen_key_name("hardware.virt_info");

  if ( $cache->valid($cache_key_name) ) {
    return $cache->get($cache_key_name);
  }

  if ( Rex::is_ssh || $^O !~ m/^MSWin/i ) {

    my (
      $product_name, $bios_vendor, $sys_vendor,
      $self_status,  $cpuinfo,     $modules
    ) = ( '', '', '', '', '', '' );

    $product_name =
      i_run "cat /sys/devices/virtual/dmi/id/product_name 2>/dev/null";
    $bios_vendor =
      i_run "cat /sys/devices/virtual/dmi/id/bios_vendor 2>/dev/null";
    $sys_vendor =
      i_run "cat /sys/devices/virtual/dmi/id/sys_vendor 2>/dev/null";

    $self_status = i_run "cat /proc/self/status 2>/dev/null";
    $cpuinfo     = i_run "cat /proc/cpuinfo 2>/dev/null";
    $modules     = i_run "cat /proc/modules 2>/dev/null";

    my ( $virtualization_type, $virtualization_role ) = ( '', '' );

    if ( is_dir("/proc/xen") ) {
      $virtualization_type = "xen";
      $virtualization_role = "guest";

      my $string = i_run "cat /proc/xen/capabilities 2>/dev/null";
      if ( $string =~ /control_d/ ) {
        $virtualization_role = "host";
      }
    }

    elsif ( is_dir("/proc/vz") ) {
      $virtualization_type = "openvz";
      $virtualization_role = "guest";

      if ( is_dir("/proc/bc") ) {
        $virtualization_role = "host";
      }
    }

    elsif ( $product_name =~ /KVM|Bochs/ ) {
      $virtualization_type = "kvm";
      $virtualization_role = "guest";
    }

    elsif ( $product_name =~ /VMware Virtual Platform/ ) {
      $virtualization_type = "vmware";
      $virtualization_role = "guest";
    }

    elsif ( $bios_vendor =~ /Xen/ ) {
      $virtualization_type = "xen";
      $virtualization_role = "guest";
    }

    elsif ( $bios_vendor =~ /innotek GmbH/ ) {
      $virtualization_type = "virtualbox";
      $virtualization_role = "guest";
    }

    elsif ( $sys_vendor =~ /Microsoft Corporation/ ) {
      $virtualization_type = "VirtualPC";
      $virtualization_role = "guest";
    }

    elsif ( $sys_vendor =~ /Parallels Software International Inc/ ) {
      $virtualization_type = "parallels";
      $virtualization_role = "guest";
    }

    elsif ( $self_status =~ /VxID: \d+/ ) {
      $virtualization_type = "linux_vserver";
      $virtualization_role = "guest";

      if ( $self_status =~ /VxID: 0/ ) {
        $virtualization_role = "host";
      }
    }

    elsif ( $cpuinfo =~ /model name.*QEMU Virtual CPU/ ) {
      $virtualization_type = "kvm";
      $virtualization_role = "guest";
    }

    elsif ( $cpuinfo =~ /vendor_id.*User Mode Linux|model name.*UML/ ) {
      $virtualization_type = "uml";
      $virtualization_role = "guest";
    }

    elsif ( $cpuinfo =~ /vendor_id.*PowerVM Lx86/ ) {
      $virtualization_type = "powervm_lx86";
      $virtualization_role = "guest";
    }

    elsif ( $cpuinfo =~ /vendor_id.*IBM\/S390/ ) {
      $virtualization_type = "ibm_systemz";
      $virtualization_role = "guest";
    }

    elsif ( $modules =~ /kvm/ ) {
      $virtualization_type = "kvm";
      $virtualization_role = "host";
    }

    elsif ( $modules =~ /vboxdrv/ ) {
      $virtualization_type = "virtualbox";
      $virtualization_role = "host";
    }

    my $data = {
      virtualization_type => $virtualization_type,
      virtualization_role => $virtualization_role,
    };

    $cache->set( $cache_key_name, $data );

    return $data;

  }
}