add snapshot support and misc cleanups for docs/tests

This commit is contained in:
Zane C. B-H 2021-10-16 19:15:44 -05:00
parent dc7624b886
commit 4f984515c3
11 changed files with 345 additions and 7 deletions

View File

@ -13,11 +13,11 @@ Rex::Virtualization::CBSD - CBSD virtualization module for bhyve
=head1 VERSION
Version 0.0.1
Version 1.0.0
=cut
our $VERSION = '0.0.1';
our $VERSION = '1.0.0';
=head1 SYNOPSIS
@ -43,7 +43,7 @@ our $VERSION = '0.0.1';
foreach my $vm_info_key (@{keys(%vm_info)}){
print $vm_info_key.": ".$vm_info{$vm_info_key}."\n";
}
# stop the VM foo
vm 'stop' => 'foo';
@ -498,6 +498,68 @@ and silently ignores those.
vm_boot => 'net',
bhyve_vnc_resolution => '800x600';
=head3 bsnapshot_create
This creates a disk snapshot of the specified VM via the command below.
cbsd bsnapshot mode=create jname=$vm snapname=$name
The following argument taken.
vm - The VM to snapshot. This is required.
name - The snapshot name. If not specified it defaults to snapshot.
This will die upon error.
vm 'bsnapshot_create', vm=>'foo', name=>'aSnapshot';
=head3 bsnapshot_remove
This removes the specified snapshot for the specified VM.
cbsd bsnapshot mode=destroy jname=$vm snapname=$name
The following argument required.
vm - The VM to snapshot. This is required.
name - The snapshot name.
This will die upon error.
vm 'bsnapshot_remove', vm=>'foo', name=>'aSnapshot';
=head3 bsnapshot_removeall
This removes specified snapshot for the specified VM.
cbsd bsnapshot mode=destroyall jname=$vm
The following argument required.
vm - The VM to remove all snapshots for.
This will die upon error.
vm 'bsnapshot_removeall', vm=>'foo';
=head3 bsnapshot_rollback
This rolls the disks for a VM back to a specified snapshot.
cbsd bsnapshot mode=rollback jname=$vm snapname=$name
The following argument required.
vm - The VM to rollback.
name - The snapshot name.
This will die upon error.
vm 'bsnapshot_rollback', vm=>'foo', name=>'aSnapshot';
=head3 bstart
This starts a VM. This is done via the command...

View File

@ -0,0 +1,57 @@
#
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
#
package Rex::Virtualization::CBSD::bsnapshot_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';
}
if ( !defined( $opts{name} ) ) {
$opts{name} = 'snapshot';
}
# 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';
}
# put together the command
my $command
= 'cbsd bsnapshot mode=create jname=' . $opts{vm} . " snapname='" . $opts{name} . "'";
Rex::Logger::debug( "Creating a snapshot 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;

View File

@ -0,0 +1,57 @@
#
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
#
package Rex::Virtualization::CBSD::bsnapshot_remove;
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 ) = @_;
# make sure we have everything we need defined
if ( !defined( $opts{vm} ) ) {
die 'The required variable "vm" is not set';
}
if ( !defined( $opts{name} ) ) {
die 'The required variable "name" is not set';
}
# 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';
}
# put together the command
my $command
= 'cbsd bsnapshot mode=destroy jname=' . $opts{vm} . " snapname='" . $opts{name} . "'";
Rex::Logger::debug( "Removing a snapshot 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;

View File

@ -0,0 +1,53 @@
#
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
#
package Rex::Virtualization::CBSD::bsnapshot_removeall;
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 ) = @_;
# make sure we have everything we need defined
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}
. '" or "name", "'
. $opts{name}
. '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
}
# put together the command
my $command
= 'cbsd bsnapshot mode=destroyall jname=' . $opts{vm};
Rex::Logger::debug( "Removing all snapshots 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;

View File

@ -0,0 +1,57 @@
#
# (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
#
package Rex::Virtualization::CBSD::bsnapshot_rollback;
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 ) = @_;
# make sure the required variables are set
if ( !defined( $opts{vm} ) ) {
die 'The required variable "vm" is not set';
}
if ( !defined( $opts{name} ) ) {
die 'The required variable "name" is not set';
}
# 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';
}
# put together the command
my $command
= 'cbsd bsnapshot mode=rollback jname=' . $opts{vm} . " snapname='" . $opts{name} . "'";
Rex::Logger::debug( "Rolling back to a CBSD VM snapshot 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;

View File

@ -7,7 +7,7 @@ use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Rex::Virtualization::CBSD::bcheckpoint_create' ) || print "Bail out!\n";
use_ok( 'Rex::Virtualization::CBSD::bsnapshot_create' ) || print "Bail out!\n";
}
diag( "Testing Rex::Virtualization::CBSD::bcheckpoint_create $Rex::Virtualization::CBSD::bcheckpoint_create::VERSION, Perl $], $^X" );
diag( "Testing Rex::Virtualization::CBSD::bsnapshot_create $Rex::Virtualization::CBSD::bsnapshot_create::VERSION, Perl $], $^X" );

View File

@ -7,7 +7,7 @@ use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Rex::Virtualization::CBSD::bcheckpoint_destroyall' ) || print "Bail out!\n";
use_ok( 'Rex::Virtualization::CBSD::bsnapshot_removeall' ) || print "Bail out!\n";
}
diag( "Testing Rex::Virtualization::CBSD::bcheckpoint_destroyall $Rex::Virtualization::CBSD::bcheckpoint_destroyall::VERSION, Perl $], $^X" );
diag( "Testing Rex::Virtualization::CBSD::bsnapshot_removeall $Rex::Virtualization::CBSD::bsnapshot_removeall::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,13 @@
#!perl
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Rex::Virtualization::CBSD::bsnapshot_remove' ) || print "Bail out!\n";
}
diag( "Testing Rex::Virtualization::CBSD::bsnapshot_remove $Rex::Virtualization::CBSD::bsnapshot_remove::VERSION, Perl $], $^X" );

View File

@ -0,0 +1,13 @@
#!perl
use 5.006;
use strict;
use warnings;
use Test::More;
plan tests => 1;
BEGIN {
use_ok( 'Rex::Virtualization::CBSD::bsnapshot_rollback' ) || print "Bail out!\n";
}
diag( "Testing Rex::Virtualization::CBSD::bsnapshot_rollback $Rex::Virtualization::CBSD::bsnapshot_rollback::VERSION, Perl $], $^X" );

View File

@ -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" );

View File

@ -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" );