add in checkpointing, minus listing... also misc cleanups
This commit is contained in:
parent
da9633dbf7
commit
dc7624b886
|
@ -96,7 +96,39 @@ of seconds a lease for the VM name should last. The default is 30.
|
|||
|
||||
=head2 bhyve
|
||||
|
||||
=head2 bclone
|
||||
=head3 bcheckpoint_create
|
||||
|
||||
Creates a checkpoint via the command below.
|
||||
|
||||
cbsd bcheckpoint mode=create jname=$vm suspend=$suspend name=$name
|
||||
|
||||
The only required option is the key vm.
|
||||
|
||||
vm - VM to checkpoint
|
||||
|
||||
name - name of checkpoint. by default: 'checkpoint'.
|
||||
|
||||
suspend= - when set to 1 then turn off the domain immediately after checkpoint,
|
||||
for disk consistency. By default - 0, create checkpoint only.
|
||||
|
||||
This will die upon error.
|
||||
|
||||
vm 'bcheckpoint_create', vm=>'foo';
|
||||
|
||||
=head3 bcheckpoint_destroyall
|
||||
|
||||
Removes all checkpoints via the command below.
|
||||
|
||||
cbsd bcheckpoint mode=destroyall jname=$vm
|
||||
|
||||
One argument is taken and that is the name of the VM.
|
||||
|
||||
This will die upon error.
|
||||
|
||||
# removes all checkpoints for the VM 'foo'
|
||||
vm 'bcheckpoint_destroyall', 'foo';
|
||||
|
||||
=head3 bclone
|
||||
|
||||
This closnes a VM.
|
||||
|
||||
|
@ -472,18 +504,25 @@ This starts a VM. This is done via the command...
|
|||
|
||||
cbsd bstart jname=$vm
|
||||
|
||||
One argument is taken and that is the name of the VM. If '*' or 'vm*' then
|
||||
One argument is required and that is the name of the VM. If '*' or 'vm*' then
|
||||
start all VM whose names begin with 'vm', e.g. 'vm1', 'vm2'...
|
||||
|
||||
The following options may be used.
|
||||
|
||||
checkpoint - The name of the checkpoint to start the VM using.
|
||||
|
||||
This dies upon failure.
|
||||
|
||||
eval{
|
||||
vm 'bstart' => 'foo'
|
||||
vm 'bstart' => 'foo';
|
||||
} or do {
|
||||
my $error = $@ || 'Unknown failure';
|
||||
warn('Failed to start the VM foo... '.$error);
|
||||
}
|
||||
|
||||
# starts foo from the checkpoint named checkpoint
|
||||
vm 'bstart' => 'foo', checkpoint=>'checkpoint';
|
||||
|
||||
|
||||
=head3 bstop
|
||||
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#
|
||||
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
|
||||
#
|
||||
|
||||
package Rex::Virtualization::CBSD::bcheckpoint_create;
|
||||
|
||||
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, %opts ) = @_;
|
||||
|
||||
if ( !defined( $opts{vm} ) ) {
|
||||
die 'The required variable "vm" is not set';
|
||||
}
|
||||
|
||||
# set the defaults
|
||||
if ( !defined( $opts{suspend} ) ) {
|
||||
$opts{suspend} = 0;
|
||||
}
|
||||
if ( !defined( $opts{name} ) ) {
|
||||
$opts{name} = 'checkpoint';
|
||||
}
|
||||
|
||||
# make sure all the keys are sane
|
||||
if ( ( $opts{vm} =~ /[\t\ \=\\\/\'\"\n\;\&]/ )
|
||||
|| ( $opts{name} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) )
|
||||
{
|
||||
die 'The value either for "vm", "'
|
||||
. $opts{vm}
|
||||
. '" or "name", "'
|
||||
. $opts{name}
|
||||
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
|
||||
}
|
||||
if ( $opts{suspend} =~ /^[01]$/ ) {
|
||||
die 'The value for "suspend", "'
|
||||
. $opts{suspend}
|
||||
. '", matched /[\t\'\"\n\;\&]/, meaning it is not a valid value';
|
||||
}
|
||||
|
||||
# put together the command
|
||||
my $command
|
||||
= 'cbsd bcheckpoint mode=create jname=' . $opts{vm} . " name='" . $opts{name} . "' suspend=" . $opts{suspend};
|
||||
|
||||
Rex::Logger::debug( "Checking a CBSD VM via... " . $command );
|
||||
|
||||
my $returned = i_run( $command, fail_ok => 1 );
|
||||
|
||||
# the output is colorized, if there is an error
|
||||
$returned = colorstrip($returned);
|
||||
|
||||
# check for this second as no VM will also exit non-zero
|
||||
if ( $? != 0 ) {
|
||||
die( "Error running '" . $command . "'" );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
|
||||
#
|
||||
|
||||
package Rex::Virtualization::CBSD::bcheckpoint_destroyall;
|
||||
|
||||
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, %opts ) = @_;
|
||||
|
||||
if ( !defined( $opts{vm} ) ) {
|
||||
die 'The required variable "vm" is not set';
|
||||
}
|
||||
|
||||
# make sure all the keys are sane
|
||||
if ( $opts{vm} =~ /[\t\ \=\\\/\'\"\n\;\&]/ )
|
||||
{
|
||||
die 'The value either for "vm", "'
|
||||
. $opts{vm}
|
||||
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
|
||||
}
|
||||
|
||||
# put together the command
|
||||
my $command
|
||||
= 'cbsd bcheckpoint mode=destroyall jname=' . $opts{vm};
|
||||
|
||||
Rex::Logger::debug( "Removing all checkpoints for a CBSD VM via... " . $command );
|
||||
|
||||
my $returned = i_run( $command, fail_ok => 1 );
|
||||
|
||||
# the output is colorized, if there is an error
|
||||
$returned = colorstrip($returned);
|
||||
|
||||
# check for this second as no VM will also exit non-zero
|
||||
if ( $? != 0 ) {
|
||||
die( "Error running '" . $command . "'" );
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
|
@ -7,39 +7,61 @@ package Rex::Virtualization::CBSD::bstart;
|
|||
use strict;
|
||||
use warnings;
|
||||
|
||||
our $VERSION = '0.0.1'; # VERSION
|
||||
our $VERSION = '0.1.0'; # VERSION
|
||||
|
||||
use Rex::Logger;
|
||||
use Rex::Helper::Run;
|
||||
use Term::ANSIColor qw(colorstrip);
|
||||
|
||||
sub execute {
|
||||
my ( $class, $name ) = @_;
|
||||
my ( $class, $vm, %opts ) = @_;
|
||||
|
||||
if ( !defined($name) ) {
|
||||
if ( !defined($vm) ) {
|
||||
die('No VM name defined');
|
||||
}
|
||||
|
||||
Rex::Logger::debug( "CBSD VM start via cbsd bstart " . $name );
|
||||
# make sure all the VM is sane
|
||||
if ( $opts{vn} =~ /[\t\ \=\\\/\'\"\n\;\&]/ )
|
||||
{
|
||||
die 'The value either for "vm", "'
|
||||
. $opts{vm}
|
||||
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
|
||||
}
|
||||
|
||||
my $returned = i_run( 'cbsd bstart jname=' . $name, fail_ok => 1 );
|
||||
my $command='cbsd bstart jname=' . $vm;
|
||||
|
||||
if (defined($opts{checkpoint})) {
|
||||
# make sure all the VM is sane
|
||||
if ( $opts{checkpoint} =~ /[\t\ \=\\\/\'\"\n\;\&]/ )
|
||||
{
|
||||
die 'The value either for "checkpoint", "'
|
||||
. $opts{checkpoint}
|
||||
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
|
||||
}
|
||||
|
||||
$command=$command." checkpoint='".$opts{checkpoint}."'";
|
||||
}
|
||||
|
||||
Rex::Logger::debug( "CBSD VM start via... ".$command );
|
||||
|
||||
my $returned = i_run( 'cbsd bstart jname=' . $vm, 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' );
|
||||
die( '"' . $vm . '" does not exist' );
|
||||
}
|
||||
|
||||
# check for failures caused by it already running
|
||||
if ( $returned =~ /already\ running/ ) {
|
||||
die( '"' . $name . '" is already running' );
|
||||
die( '"' . $vm . '" is already running' );
|
||||
}
|
||||
|
||||
# test after no such as that will also exit non-zero
|
||||
if ( $? != 0 ) {
|
||||
die( "Error running 'cbsd bstart " . $name . "'" );
|
||||
die( "Error running 'cbsd bstart " . $vm . "'" );
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#!perl
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
plan tests => 1;
|
||||
|
||||
BEGIN {
|
||||
use_ok( 'Rex::Virtualization::CBSD::bcheckpoint_create' ) || print "Bail out!\n";
|
||||
}
|
||||
|
||||
diag( "Testing Rex::Virtualization::CBSD::bcheckpoint_create $Rex::Virtualization::CBSD::bcheckpoint_create::VERSION, Perl $], $^X" );
|
|
@ -0,0 +1,13 @@
|
|||
#!perl
|
||||
use 5.006;
|
||||
use strict;
|
||||
use warnings;
|
||||
use Test::More;
|
||||
|
||||
plan tests => 1;
|
||||
|
||||
BEGIN {
|
||||
use_ok( 'Rex::Virtualization::CBSD::bcheckpoint_destroyall' ) || print "Bail out!\n";
|
||||
}
|
||||
|
||||
diag( "Testing Rex::Virtualization::CBSD::bcheckpoint_destroyall $Rex::Virtualization::CBSD::bcheckpoint_destroyall::VERSION, Perl $], $^X" );
|
Loading…
Reference in New Issue