Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
This brings initial support for BSD jails virtual machines (#1555)
  • Loading branch information
guillomovitch committed May 20, 2012
1 parent 90ecae7 commit 1e84529
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 0 deletions.
@@ -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;
4 changes: 4 additions & 0 deletions resources/virtualization/jails/sample1
@@ -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
45 changes: 45 additions & 0 deletions t/inventory/virtualization/jails.t
@@ -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);
}

0 comments on commit 1e84529

Please sign in to comment.