| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::CBSD::bpause; | ||||||||||||||||||||||||||||||||||||||||||
| 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, $name, $mode ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # make sure we have a jname to pass | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if ( !defined($name) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | die('No VM name defined'); | |||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # set the mode to auto if none is set | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if ( !defined($mode) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | $mode = 'auto'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # make sure mode is something valid | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if ( ( $mode eq 'auto' ) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$mode eq "auto" or $mode eq "on" or $mode eq "off"
$mode eq "auto" or $mode eq "on"
MC/DC0%0/3
$mode eq "auto" or $mode eq "on" or $mode eq "off"
$mode eq "auto"
$mode eq "on"
$mode eq "off"
Truth table0%0/4
A or B or C
A= $mode eq "auto"B= $mode eq "on"C= $mode eq "off"
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | || ( $mode eq 'on' ) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | || ( $mode eq 'off' ) ) | ||||||||||||||||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | die "Mode specified is something other than 'auto', 'on', or 'off'."; | |||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | Rex::Logger::debug( "CBSD VM start via cbsd brebstart " . $name ); | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | # run it | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my $returned = i_run( 'cbsd bpause ' . $name . ' mode=' . $mode, fail_ok => 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # the output is colorized | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $returned = colorstrip($returned); | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | # check for failures caused by it not existing | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( $returned =~ /^No\ such/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | die( '"' . $name . '" does not exist' ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | die( "Error running 'cbsd brestart " . $name . "'" ); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||