line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Zane C. Bowers-Hadley |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::CBSD::blist; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
71969
|
use strict; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
51
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
477
|
use Rex::Logger; |
|
1
|
|
|
|
|
11276
|
|
|
1
|
|
|
|
|
38
|
|
13
|
1
|
|
|
1
|
|
437
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
81687
|
|
|
1
|
|
|
|
|
82
|
|
14
|
1
|
|
|
1
|
|
8
|
use Term::ANSIColor qw(colorstrip); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1205
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub execute { |
17
|
0
|
|
|
0
|
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
|
0
|
|
|
|
|
if ( $? != 0 ) { |
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; |