Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This brings initial support for BSD jails virtual machines (#1555)
- Loading branch information
1 parent
90ecae7
commit 1e84529
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
lib/FusionInventory/Agent/Task/Inventory/Input/Virtualization/Jails.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package FusionInventory::Agent::Task::Inventory::Input::Virtualization::Jails; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use FusionInventory::Agent::Tools; | ||
|
||
sub isEnabled { | ||
return canRun('jls'); | ||
} | ||
|
||
sub doInventory { | ||
my (%params) = @_; | ||
|
||
my $inventory = $params{inventory}; | ||
my $logger = $params{inventory}; | ||
|
||
my $command = 'jls -n'; | ||
foreach my $machine (_getVirtualMachines(logger => $logger)) { | ||
$inventory->addEntry( | ||
section => 'VIRTUALMACHINES', entry => $machine | ||
); | ||
} | ||
} | ||
|
||
sub _getVirtualMachines { | ||
my (%params) = ( | ||
command => 'jls -n', | ||
@_ | ||
); | ||
|
||
my $handle = getFileHandle(%params); | ||
|
||
return unless $handle; | ||
|
||
my @machines; | ||
while (my $line = <$handle>) { | ||
my $info; | ||
foreach my $item (split(' ', $line)) { | ||
next unless $item =~ /(\S+)=(\S+)/; | ||
my $key = $1; | ||
my $value = $2; | ||
$info->{$1} = $2; | ||
} | ||
|
||
my $machine = { | ||
VMTYPE => 'jail', | ||
NAME => $info->{'host.hostname'}, | ||
VMID => $info->{'jid'}, | ||
STATUS => 'running' | ||
}; | ||
|
||
push @machines, $machine; | ||
|
||
} | ||
close $handle; | ||
|
||
return @machines; | ||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
nodying enforce_statfs=2 host=new ip4=new ip6=disable jid=2 name=2 parent=0 path=/home/jails/xmpp-test3 nopersist securelevel=-1 allow.nochflags allow.nomount allow.noquotas allow.noraw_sockets allow.set_hostname allow.nosocket_af allow.nosysvipc children.cur=0 children.max=0 cpuset.id=3 host.domainname="" host.hostid=0 host.hostname=xmpp-test3 host.hostuuid=00000000-0000-0000-0000-000000000000 ip4.addr=10.XX.XXX.249,10.XX.XXX.251 ip4.saddrsel ip6.addr= ip6.saddrsel | ||
nodying enforce_statfs=2 host=new ip4=new ip6=disable jid=3 name=3 parent=0 path=/home/jails/xmpp-test2 nopersist securelevel=-1 allow.nochflags allow.nomount allow.noquotas allow.noraw_sockets allow.set_hostname allow.nosocket_af allow.nosysvipc children.cur=0 children.max=0 cpuset.id=4 host.domainname="" host.hostid=0 host.hostname=xmpp-test2 host.hostuuid=00000000-0000-0000-0000-000000000000 ip4.addr=10.XX.XXX.248 ip4.saddrsel ip6.addr= ip6.saddrsel | ||
nodying enforce_statfs=2 host=new ip4=new ip6=disable jid=4 name=4 parent=0 path=/home/jails/xmpp-test1 nopersist securelevel=-1 allow.nochflags allow.nomount allow.noquotas allow.noraw_sockets allow.set_hostname allow.nosocket_af allow.nosysvipc children.cur=0 children.max=0 cpuset.id=5 host.domainname="" host.hostid=0 host.hostname=xmpp-test1 host.hostuuid=00000000-0000-0000-0000-000000000000 ip4.addr=10.XX.XXX.247 ip4.saddrsel ip6.addr= ip6.saddrsel | ||
nodying enforce_statfs=2 host=new ip4=new ip6=disable jid=5 name=5 parent=0 path=/home/jails/noname_local nopersist securelevel=-1 allow.nochflags allow.nomount allow.noquotas allow.noraw_sockets allow.set_hostname allow.nosocket_af allow.nosysvipc children.cur=0 children.max=0 cpuset.id=6 host.domainname="" host.hostid=0 host.hostname=noname.local host.hostuuid=00000000-0000-0000-0000-000000000000 ip4.addr=10.XX.XXX.250 ip4.saddrsel ip6.addr= ip6.saddrsel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
|
||
use FusionInventory::Agent::Task::Inventory::Input::Virtualization::Jails; | ||
|
||
my %tests = ( | ||
sample1 => [ | ||
{ | ||
NAME => 'xmpp-test3', | ||
STATUS => 'running', | ||
VMID => '2', | ||
VMTYPE => 'jail', | ||
}, | ||
{ | ||
NAME => 'xmpp-test2', | ||
STATUS => 'running', | ||
VMID => '3', | ||
VMTYPE => 'jail', | ||
}, | ||
{ | ||
NAME => 'xmpp-test1', | ||
STATUS => 'running', | ||
VMID => '4', | ||
VMTYPE => 'jail', | ||
}, | ||
{ | ||
NAME => 'noname.local', | ||
STATUS => 'running', | ||
VMID => '5', | ||
VMTYPE => 'jail', | ||
}, | ||
] | ||
); | ||
|
||
plan tests => scalar keys %tests; | ||
|
||
foreach my $test (keys %tests) { | ||
my $file = "resources/virtualization/jails/$test"; | ||
my @machines = FusionInventory::Agent::Task::Inventory::Input::Virtualization::Jails::_getVirtualMachines(file => $file); | ||
is_deeply(\@machines, $tests{$test}, $test); | ||
} |