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