| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::CBSD::bclone; | ||||||||||||||||||||||||||||
| 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=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $class, %opts ) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # make sure we have the required keys | ||||||||||||||||||||||||||||
| 20 | # and sane | ||||||||||||||||||||||||||||
| 21 | 0 | my @required_keys = ( 'old', 'new' ); | |||||||||||||||||||||||||||
| 22 | 0 | foreach my $key (@required_keys) { | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | if ( !defined( $opts{$key} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | die( 'Required key "' . $key . '" not defined' ); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | # make sure it does not contain any possible characters we don't want | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $opts{$key} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | die 'The value for "' | ||||||||||||||||||||||||||||
| 30 | . $key . '", "' | ||||||||||||||||||||||||||||
| 31 | 0 | . $opts{$key} | |||||||||||||||||||||||||||
| 32 | . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # the command to use | ||||||||||||||||||||||||||||
| 37 | 0 | my $command = 'cbsd bclone old=' . $opts{old} . ' new=' . $opts{new}; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | # make sure all the variables are sane | ||||||||||||||||||||||||||||
| 40 | # and if set and sane add it | ||||||||||||||||||||||||||||
| 41 | 0 | my @bool_vars = ( 'checkstate', 'promote', 'mac_reinit' ); | |||||||||||||||||||||||||||
| 42 | 0 | foreach my $key (@bool_vars) { | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # make sure that the it is either 0 or 1 | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | if ( defined( $opts{$key} ) && ( $opts{$key} !~ /^[01]$/ ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opts{$key} and not $opts{$key} =~ /^[01]$/
MC/DC0%0/2
defined $opts{$key} and not $opts{$key} =~ /^[01]$/
defined $opts{$key}
not $opts{$key} =~ /^[01]$/
Truth table0%0/3
A and not(B)
A= defined $opts{$key}B= not $opts{$key} =~ /^[01]$/
| |||||||||||||||||||||||||||||
| 46 | 0 | die( 'Key "' . $key . '" defined and is "' . $opts{key} . '", which does not match /^[01]$/' ); | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | # if we get here it is sane and if defined, set it | ||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( defined( $opts{key} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $command = $command . ' ' . $key . '=' . $opts{$key}; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | Rex::Logger::debug( "Cloning CBSD VM via... " . $command ); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | my $returned = i_run( $command, fail_ok => 1 ); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # the output is colorized | ||||||||||||||||||||||||||||
| 61 | 0 | $returned = colorstrip($returned); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # test after no such as that will also exit non-zero | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 0 | die( "Error running '" . $command . "' returned... " . $returned ); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | return 1; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | 1; | |||||||||||||||||||||||||||