| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::CBSD::bcheckpoint_create; | ||||||||||||||||||||||||||||
| 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=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $class, %opts ) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | if ( !defined( $opts{vm} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | die 'The required variable "vm" is not set'; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # set the defaults | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ( !defined( $opts{suspend} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | $opts{suspend} = 0; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | 0 | ▶ | if ( !defined( $opts{name} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | $opts{name} = 'checkpoint'; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # make sure all the keys are sane | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | if ( ( $opts{vm} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]] or $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
MC/DC0%0/2
$opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]] or $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
$opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
$opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
Truth table0%0/3
A or B
A= $opts{"vm"} =~ m[[\t\ \=\\/\'\"\n\;\&]]B= $opts{"name"} =~ m[[\t\ \=\\/\'\"\n\;\&]]
| |||||||||||||||||||||||||||||
| 33 | || ( $opts{name} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) ) | ||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | die 'The value either for "vm", "' | ||||||||||||||||||||||||||||
| 36 | . $opts{vm} | ||||||||||||||||||||||||||||
| 37 | . '" or "name", "' | ||||||||||||||||||||||||||||
| 38 | . $opts{name} | ||||||||||||||||||||||||||||
| 39 | 0 | . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( $opts{suspend} =~ /^[01]$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | die 'The value for "suspend", "' | ||||||||||||||||||||||||||||
| 43 | . $opts{suspend} | ||||||||||||||||||||||||||||
| 44 | 0 | . '", matched /[\t\'\"\n\;\&]/, meaning it is not a valid value'; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | # put together the command | ||||||||||||||||||||||||||||
| 48 | my $command | ||||||||||||||||||||||||||||
| 49 | 0 | = 'cbsd bcheckpoint mode=create jname=' . $opts{vm} . " name='" . $opts{name} . "' suspend=" . $opts{suspend}; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | Rex::Logger::debug( "Checking a CBSD VM via... " . $command ); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | my $returned = i_run( $command, fail_ok => 1 ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # the output is colorized, if there is an error | ||||||||||||||||||||||||||||
| 56 | 0 | $returned = colorstrip($returned); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | # check for this second as no VM will also exit non-zero | ||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | die( "Error running '" . $command . "'" ); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | return 1; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 1 | 1; | |||||||||||||||||||||||||||