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