get stop working

This commit is contained in:
Zane C. B-H 2020-04-14 00:23:47 -05:00
parent 8ea0cd5d66
commit ef5f4f6bae
1 changed files with 45 additions and 0 deletions

View File

@ -0,0 +1,45 @@
#
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
#
package Rex::Virtualization::CBSD::stop;
use strict;
use warnings;
our $VERSION = '0.0.1'; # VERSION
use Rex::Logger;
use Rex::Helper::Run;
use Term::ANSIColor qw(colorstrip);
sub execute {
my ( $class, $name ) = @_;
if (!defined( $name ) ){
die('No VM name defined');
}
Rex::Logger::debug("CBSD VM stop via cbsd bstop ".$name);
my $returned=i_run ('cbsd bstop '.$name , fail_ok => 1);
# the output is colorized
$returned=colorstrip($returned);
# check for failures caused by it not existing
if ( $returned =~ /^No\ such/ ){
die('"'.$name.'" does not exist');
}
# test after no such as that will also exit non-zero
if ( $? != 0 ) {
die("Error running 'cbsd bstop ".$name."'");
}
# this is warning message will be thrown if stop fails.... does not return 0 though
if ( $returned =~ /unable\ to\ determine\ bhyve\ pid/ ){
die("Either already stopped or other issue determining bhyve PID for '".$name."'");
}
return 1;
}
1;