This commit is contained in:
Zane C. B-H 2019-05-02 11:28:11 -05:00
parent a4b605da30
commit efc3f39d6e
2 changed files with 58 additions and 28 deletions

View File

@ -1,15 +1,11 @@
VM-CBSD-Poller
The README is used to introduce the module and provide instructions on
how to install the module, any machine dependencies it may have (for
example C compilers and installed libraries) and any other information
that should be provided before the module is installed.
This polls the Bhyve VMs managed by CBSD and returns a hash with the found
data. The command that is wrapped is 'cbsd bls'.
This needs to be run as UID 0 in most installations, given the requirements
of the cbsd command and how it is installed.
A README file is required for CPAN modules since CPAN extracts the README
file from a module distribution so that people browsing the archive
can use it to get an idea of the module's uses. It is usually a good idea
to provide version information here so that people can decide whether
fixes for the module are worth downloading.
INSTALLATION

View File

@ -3,50 +3,84 @@ package VM::CBSD::Poller;
use 5.006;
use strict;
use warnings;
use base 'Error::Helper';
use JSON;
=head1 NAME
VM::CBSD::Poller - The great new VM::CBSD::Poller!
VM::CBSD::Poller - Polls the status of VMs managed by CBSD.
=head1 VERSION
Version 0.01
Version 0.0.0
=cut
our $VERSION = '0.01';
our $VERSION = '0.0.0';
=head1 SYNOPSIS
Quick summary of what the module does.
Perhaps a little code snippet.
use VM::CBSD::Poller;
my $foo = VM::CBSD::Poller->new();
...
my $cbsd_vm_poller = VM::CBSD::Poller->new();
=head1 EXPORT
head1 METHODS
A list of functions that can be exported. You can delete this section
if you don't export anything, such as for a purely object-oriented module.
=head2 new
=head1 SUBROUTINES/METHODS
=head2 function1
This initiates the object.
=cut
sub function1 {
sub new{
my $self = {
perror=>undef,
error=>undef,
errorString=>"",
errorExtra=>{
flags=>{
1=>'cbsdError',
}
},
};
bless $self;
return $self;
}
=head2 function2
sub poll{
my $self=$_[0];
=cut
my $raw=`cbsd bls header=0 display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip6_addr,status,vnc_port`;
if ( $? != 0 ){
$self->{error}=1;
$self->{errorString}='"cbsd bls header=0 display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip6_addr,status,vnc_port" exited with a non-zero value';
$self->warn;
return undef;
}
sub function2 {
my @raw_split=split(/\n/, $raw);
my %return_hash;
foreach my $line (@raw_split){
my ( $nodename, $jname, $jid, $vm_ram, $vm_curmem, $vm_cpus, $pcpu, $vm_os_type, $ip4_addr, $status, $vnc_port ) = split(/[\t ]+/, $line);
$return_hash{$jname}={
jname=>$jname,
nodename=>$nodename,
jid=>$jid,
vm_ram=>$vm_ram,
vm_curmem=>$vm_curmem,
pcpu=>$pcpu,
vm_os_type=>$vm_os_type,
ip4_addr=>$ip4_addr,
status=>$status,
vnc_port=>$vnc_port,
}
}
return %return_hash;
}
=head1 AUTHOR