| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::CBSD::bstop; | ||||||||||||||||||||||||||||
| 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=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $class, $name, %opts ) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # set the hard_timeout if needed | ||||||||||||||||||||||||||||
| 20 | 0 | my $hard_timeout = ''; | |||||||||||||||||||||||||||
| 21 | 0 | ▶ | if ( defined( $opts{hard_timeout} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | # make sure we have a valid value | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | if ( $opts{hard_timeout} !~ /^[0123456789]+$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | die 'hard_timeout value,"' . $opts{hard_timeout} . '", is not numeric'; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | $hard_timeout = 'hard_timeout=' . $opts{hard_timeout}; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | # set the noacpi value if needed | ||||||||||||||||||||||||||||
| 32 | 0 | my $noacpi = ''; | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ( defined( $opts{noacpi} ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | # make sure we have a valid value | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ( ( $opts{noacpi} ne '0' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts{"noacpi"} ne 0 and $opts{"noacpi"} ne 1
MC/DC0%0/2
$opts{"noacpi"} ne 0 and $opts{"noacpi"} ne 1
$opts{"noacpi"} ne 0
$opts{"noacpi"} ne 1
Truth table0%0/3
A and B
A= $opts{"noacpi"} ne 0B= $opts{"noacpi"} ne 1
| |||||||||||||||||||||||||||||
| 37 | && ( $opts{noacpi} ne '1' ) ) | ||||||||||||||||||||||||||||
| 38 | { | ||||||||||||||||||||||||||||
| 39 | 0 | die 'noacpi is set and it is not equal to "0" or "1"'; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | $noacpi = 'noacpi=' . $opts{noacpi}; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | # make sure we have a | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( !defined($name) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | die('No VM name defined'); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | Rex::Logger::debug( "CBSD VM stop via cbsd bstop " . $name ); | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | my $returned = i_run( 'cbsd bstop jname=' . $name . ' ' . $hard_timeout . ' ' . $noacpi, fail_ok => 1 ); | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | # the output is colorized | ||||||||||||||||||||||||||||
| 55 | 0 | $returned = colorstrip($returned); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | # check for failures caused by it not existing | ||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( $returned =~ /^No\ such/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | die( '"' . $name . '" does not exist' ); | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | # test after no such as that will also exit non-zero | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | die( "Error running 'cbsd bstop " . $name . "'" ); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # this is warning message will be thrown if stop fails.... does not return 0 though | ||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $returned =~ /unable\ to\ determine\ bhyve\ pid/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | die( "Either already stopped or other issue determining bhyve PID for '" . $name . "'" ); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | return 1; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | 1; | |||||||||||||||||||||||||||