146 lines
2.7 KiB
Perl
146 lines
2.7 KiB
Perl
package VM::CBSD::Poller;
|
|
|
|
use 5.006;
|
|
use strict;
|
|
use warnings;
|
|
use base 'Error::Helper';
|
|
use JSON;
|
|
|
|
=head1 NAME
|
|
|
|
VM::CBSD::Poller - Polls the status of VMs managed by CBSD.
|
|
|
|
=head1 VERSION
|
|
|
|
Version 0.0.0
|
|
|
|
=cut
|
|
|
|
our $VERSION = '0.0.0';
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
use VM::CBSD::Poller;
|
|
|
|
my $cbsd_vm_poller = VM::CBSD::Poller->new();
|
|
|
|
head1 METHODS
|
|
|
|
=head2 new
|
|
|
|
This initiates the object.
|
|
|
|
=cut
|
|
|
|
sub new{
|
|
my $self = {
|
|
perror=>undef,
|
|
error=>undef,
|
|
errorString=>"",
|
|
errorExtra=>{
|
|
flags=>{
|
|
1=>'cbsdError',
|
|
}
|
|
},
|
|
};
|
|
bless $self;
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
sub poll{
|
|
my $self=$_[0];
|
|
|
|
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;
|
|
}
|
|
$raw =~ s/\x1b\[[0-9;]*m//g;
|
|
|
|
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,
|
|
vm_cpus=>$vm_cpus,
|
|
}
|
|
}
|
|
|
|
return %return_hash;
|
|
}
|
|
|
|
=head1 AUTHOR
|
|
|
|
Zane C. Bowers-Hadley, C<< <vvelox at vvelox.net> >>
|
|
|
|
=head1 BUGS
|
|
|
|
Please report any bugs or feature requests to C<bug-vm-cbsd-poller at rt.cpan.org>, or through
|
|
the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=VM-CBSD-Poller>. I will be notified, and then you'll
|
|
automatically be notified of progress on your bug as I make changes.
|
|
|
|
|
|
|
|
|
|
=head1 SUPPORT
|
|
|
|
You can find documentation for this module with the perldoc command.
|
|
|
|
perldoc VM::CBSD::Poller
|
|
|
|
|
|
You can also look for information at:
|
|
|
|
=over 4
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here)
|
|
|
|
L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=VM-CBSD-Poller>
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation
|
|
|
|
L<http://annocpan.org/dist/VM-CBSD-Poller>
|
|
|
|
=item * CPAN Ratings
|
|
|
|
L<https://cpanratings.perl.org/d/VM-CBSD-Poller>
|
|
|
|
=item * Search CPAN
|
|
|
|
L<https://metacpan.org/release/VM-CBSD-Poller>
|
|
|
|
=back
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT
|
|
|
|
This software is Copyright (c) 2019 by Zane C. Bowers-Hadley.
|
|
|
|
This is free software, licensed under:
|
|
|
|
The Artistic License 2.0 (GPL Compatible)
|
|
|
|
|
|
=cut
|
|
|
|
1; # End of VM::CBSD::Poller
|