add start

This commit is contained in:
Zane C. B-H 2020-04-14 00:28:46 -05:00
parent ef5f4f6bae
commit 10c0685837
1 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,44 @@
#
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
#
package Rex::Virtualization::CBSD::start;
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 start via cbsd bstart ".$name);
my $returned=i_run ('cbsd bstart '.$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');
}
# check for failures caused by it already running
if ( $returned =~ /^already\ running/ ){
die('"'.$name.'" is already running');
}
# test after no such as that will also exit non-zero
if ( $? != 0 ) {
die("Error running 'cbsd bstart ".$name."'");
}
return 1;
}
1;