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
|
package Ocsinventory::Agent::Backend::Virtualization::VmWareWorkstation;
#
# initial version: Walid Nouh
#
use strict;
sub check {
my $params = shift;
my $common = $params->{common};
return $common->can_run('/bin/vmrun')
}
sub run {
my $params = shift;
my $common = $params->{common};
my $logger = $params->{logger};
my $cpu;
my $cores;
my $uuid;
my $mem;
my $status;
my $name;
my $i = 0;
my $commande = "/bin/vmrun list";
foreach my $vmxpath ( `$commande` ) {
next unless $i++ > 0; # Ignore the first line
if (!open TMP, "<$vmxpath") {
$logger->debug("Can't open $vmxpath\n");
next;
}
my @vminfos = <TMP>;
close TMP;
foreach my $line (@vminfos) {
if ($line =~ m/^displayName =\s\"+(.*)\"/) {
$name = $1;
} elsif ($line =~ m/^numvcpus =\s\"+(.*)\"/){
$cpu = $1;
} elsif ($line =~ m/^cpuid.coresPerSocket =\s\"+(.*)\" /){
$cores = $1;
} elsif ($line =~ m/^memsize =\s\"+(.*)\"/) {
$mem = $1;
} elsif ($line =~ m/^uuid.bios =\s\"+(.*)\"/) {
$uuid = $1;
}
}
$common->addVirtualMachine ({
NAME => $name,
VCPU => $cpu,
CORES => $cores,
UUID => $uuid,
MEMORY => $mem,
STATUS => "running",
SUBSYSTEM => "VmWare Workstation",
VMTYPE => "VmWare",
});
}
}
1;
|