| 1 | # | ||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||
| 3 | # | ||||||||||
| 4 | |||||||||||
| 5 | package Rex::Virtualization::CBSD::bcheckpoint_destroyall; | ||||||||||
| 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=4 SCAR=30.0
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 | # make sure all the keys are sane | ||||||||||
| 24 | 0 | ▶ | if ( $opts{vm} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | { | ||||||||||
| 26 | die 'The value either for "vm", "' | ||||||||||
| 27 | . $opts{vm} | ||||||||||
| 28 | 0 | . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | # put together the command | ||||||||||
| 32 | my $command | ||||||||||
| 33 | 0 | = 'cbsd bcheckpoint mode=destroyall jname=' . $opts{vm}; | |||||||||
| 34 | |||||||||||
| 35 | 0 | Rex::Logger::debug( "Removing all checkpoints for a CBSD VM via... " . $command ); | |||||||||
| 36 | |||||||||||
| 37 | 0 | my $returned = i_run( $command, fail_ok => 1 ); | |||||||||
| 38 | |||||||||||
| 39 | # the output is colorized, if there is an error | ||||||||||
| 40 | 0 | $returned = colorstrip($returned); | |||||||||
| 41 | |||||||||||
| 42 | # check for this second as no VM will also exit non-zero | ||||||||||
| 43 | 0 | ▶ | if ( $? != 0 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | die( "Error running '" . $command . "'" ); | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | return 1; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | 1 | 1; | |||||||||