| 1 | # | ||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||
| 3 | # | ||||||||||
| 4 | |||||||||||
| 5 | package Rex::Virtualization::CBSD::blist; | ||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 1 | our $VERSION = '0.0.1'; # VERSION | |||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use Rex::Logger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Rex::Helper::Run; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Term::ANSIColor qw(colorstrip); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | sub execute { | ||||||||
|
Subroutine
execute: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 17 | 0 | my ($class) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 0 | Rex::Logger::debug( | |||||||||
| 20 | "Getting CBSD VM list via cbsd bls display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip4_addr,status,vnc,path header=0" | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | 0 | my %VMs; | |||||||||
| 24 | |||||||||||
| 25 | # header=0 is needed to avoid including code to exclude it | ||||||||||
| 26 | # if display= is changed, the parsing order needs updated | ||||||||||
| 27 | 0 | my $found = i_run( | |||||||||
| 28 | 'cbsd bls display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip4_addr,status,vnc,path header=0', | ||||||||||
| 29 | fail_ok => 1 | ||||||||||
| 30 | ); | ||||||||||
| 31 | 0 | ▶ | if ( $? != 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | die( | |||||||||
| 33 | "Error running 'cbsd bls display=nodename,jname,jid,vm_ram,vm_curmem,vm_cpus,pcpu,vm_os_type,ip4_addr,status,vnc,path header=0'" | ||||||||||
| 34 | ); | ||||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | # cbsd bls is colorized with no off mode for the color | ||||||||||
| 38 | # remove it here so the data can be safely used else where | ||||||||||
| 39 | 0 | $found = colorstrip($found); | |||||||||
| 40 | |||||||||||
| 41 | 0 | my @found_lines = split( /\n/, $found ); | |||||||||
| 42 | |||||||||||
| 43 | 0 | foreach my $line (@found_lines) { | |||||||||
| 44 | 0 | my %VM; | |||||||||
| 45 | |||||||||||
| 46 | # needs to be updated if display= is ever changed | ||||||||||
| 47 | ( | ||||||||||
| 48 | $VM{'node'}, $VM{'name'}, $VM{'pid'}, $VM{'ram'}, $VM{'curmem'}, $VM{'cpus'}, | ||||||||||
| 49 | 0 | $VM{'pcpu'}, $VM{'os'}, $VM{'ip4'}, $VM{'status'}, $VM{'vnc'}, $VM{'path'} | |||||||||
| 50 | ) = split( /[\ \t]+/, $line ); | ||||||||||
| 51 | 0 | $VMs{ $VM{'name'} } = \%VM; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | 0 | return %VMs; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 1 | 1; | |||||||||