line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Zane C. Bowers-Hadley |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::CBSD::vm_os_profiles_hash; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
68919
|
use strict; |
|
1
|
|
|
|
|
12
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.0.1'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
478
|
use Rex::Logger; |
|
1
|
|
|
|
|
10891
|
|
|
1
|
|
|
|
|
38
|
|
13
|
1
|
|
|
1
|
|
430
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
78380
|
|
|
1
|
|
|
|
|
115
|
|
14
|
1
|
|
|
1
|
|
9
|
use Term::ANSIColor qw(colorstrip); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1822
|
|
15
|
1
|
|
|
1
|
|
13
|
use Rex::Commands::User; |
|
1
|
|
|
|
|
100763
|
|
|
1
|
|
|
|
|
8
|
|
16
|
1
|
|
|
1
|
|
613
|
use Rex::Commands::Fs; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
6
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub execute { |
19
|
0
|
|
|
0
|
0
|
|
my ( $class, %opts ) = @_; |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
Rex::Logger::debug("Getting a list of VM OS types for CBSD "); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# set cloudinit to false by default |
24
|
0
|
0
|
|
|
|
|
if ( !defined( $opts{cloudinit} ) ) { |
25
|
0
|
|
|
|
|
|
$opts{cloudinit} = 0; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# get where CBSD is installed to |
29
|
0
|
|
|
|
|
|
my %cbsd; |
30
|
0
|
0
|
|
|
|
|
eval { %cbsd = get_user('cbsd'); } or do { |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
0
|
|
|
|
my $error = $@ || 'Unknown failure'; |
32
|
0
|
|
|
|
|
|
die( "get_user('cbsd') died with... " . $error ); |
33
|
|
|
|
|
|
|
}; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $cbsd_etc_defaults_dir = $cbsd{home} . '/etc/defaults/'; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# get the VM OS/profile config lists |
38
|
0
|
|
|
|
|
|
my @vm_configs = grep { /^vm\-/ } list_files($cbsd_etc_defaults_dir); |
|
0
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# find the requested ones |
41
|
0
|
|
|
|
|
|
my %profiles; |
42
|
0
|
|
|
|
|
|
foreach my $config (@vm_configs) { |
43
|
0
|
|
|
|
|
|
my ( $vm, $os, $profile ) = split( /\-/, $config, 3 ); |
44
|
0
|
|
|
|
|
|
$profile =~ s/\.conf$//; |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $add_profile = 1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# if cloudinit is defined, only add cloudinit images |
49
|
0
|
0
|
|
|
|
|
if ( $opts{cloudinit} ) { |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# since we are default adding, make sure it is not a cloudinit |
52
|
|
|
|
|
|
|
# profile and don't add it if it is not |
53
|
0
|
0
|
|
|
|
|
if ( $profile !~ /^cloud\-/ ) { |
54
|
0
|
|
|
|
|
|
$add_profile = 0; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# add the profile if needed |
59
|
0
|
0
|
|
|
|
|
if ($add_profile) { |
60
|
0
|
0
|
|
|
|
|
if ( !defined( $profiles{$os} ) ) { |
61
|
0
|
|
|
|
|
|
$profiles{$os} = { $profile => 1 }; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
else { |
64
|
0
|
|
|
|
|
|
$profiles{$os}{$profile} = 1; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return %profiles; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |