| 1 | # | ||||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||||
| 3 | # | ||||||||||||
| 4 | |||||||||||||
| 5 | package Rex::Virtualization::CBSD::vm_os_profiles; | ||||||||||||
| 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 | 1 | ▶ | use Rex::Commands::User; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 1 | ▶ | use Rex::Commands::Fs; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 0 | ▶ | sub execute { | ||||||||||
|
Subroutine
execute: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||
| 19 | 0 | my ( $class, $wanted_os, %opts ) = @_; | |||||||||||
| 20 | |||||||||||||
| 21 | # set cloudinit to false by default | ||||||||||||
| 22 | 0 | ▶ | if ( !defined( $opts{cloudinit} ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 23 | 0 | $opts{cloudinit} = 0; | |||||||||||
| 24 | } | ||||||||||||
| 25 | |||||||||||||
| 26 | # the OS we want profiles for | ||||||||||||
| 27 | 0 | ▶ | if ( !defined($wanted_os) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | eval { %cbsd = get_user('cbsd'); } or do { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 36 | 0 | ▶ | my $error = $@ || 'Unknown failure'; | ||||||||||
|
Condition0%0/2
$@ || 'Unknown failure'
MC/DC0%0/1
$@ || 'Unknown failure'
$@
Truth table0%0/2
A
A= $@
| |||||||||||||
| 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); | |||||||||||
| 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 | ▶ | if ( $opts{cloudinit} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | if ( $profile !~ /^cloud\-/ ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 58 | 0 | $add_profile = 0; | |||||||||||
| 59 | } | ||||||||||||
| 60 | } | ||||||||||||
| 61 | |||||||||||||
| 62 | # add the profile if needed | ||||||||||||
| 63 | 0 | ▶ | if ($add_profile) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | 0 | ▶ | if ( $os eq $wanted_os ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 65 | 0 | $profile =~ s/\.conf$//; | |||||||||||
| 66 | 0 | $profiles{$profile} = 1; | |||||||||||
| 67 | } | ||||||||||||
| 68 | } | ||||||||||||
| 69 | } | ||||||||||||
| 70 | |||||||||||||
| 71 | 0 | return keys(%profiles); | |||||||||||
| 72 | } | ||||||||||||
| 73 | |||||||||||||
| 74 | 1 | 1; | |||||||||||