File Coverage

blib/lib/Rex/Virtualization/CBSD/p9shares_rm.pm
Criterion Covered Total %
statement 15 29 51.7
branch 0 6 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 20 42 47.6


line stmt bran cond sub pod time code
1             #
2             # (c) Zane C. Bowers-Hadley
3             #
4              
5             package Rex::Virtualization::CBSD::p9shares_rm;
6              
7 1     1   67328 use strict;
  1         12  
  1         30  
8 1     1   5 use warnings;
  1         2  
  1         51  
9              
10             our $VERSION = '0.0.1'; # VERSION
11              
12 1     1   438 use Rex::Logger;
  1         10582  
  1         36  
13 1     1   408 use Rex::Helper::Run;
  1         77885  
  1         76  
14 1     1   8 use Term::ANSIColor qw(colorstrip);
  1         2  
  1         2054  
15              
16             sub execute {
17 0     0 0   my ( $class, %opts ) = @_;
18              
19             # make sure all the keys are sane
20 0           my @required_keys = ( 'vm', 'device' );
21 0           foreach my $key (@required_keys) {
22              
23 0 0         if ( !defined( $opts{$key} ) ) {
24 0           die 'The required variable "' . $key . '" is not set';
25             }
26              
27             # make sure it does not contain any possible characters we don't want
28 0 0         if ( $opts{$key} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) {
29             die 'The value for "'
30             . $key . '", "'
31 0           . $opts{$key}
32             . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value';
33             }
34             }
35              
36             # put together the command
37 0           my $command = 'cbsd bhyve-p9shares mode=detach jname=' . $opts{vm} . ' device=' . $opts{device};
38              
39 0           Rex::Logger::debug( "Removing CBSD p9share via... " . $command );
40              
41 0           my $returned = i_run( $command, fail_ok => 1 );
42              
43             # the output is colorized, if there is an error
44 0           $returned = colorstrip($returned);
45              
46             # check for this second as no VM will also exit non-zero
47 0 0         if ( $? != 0 ) {
48 0           die( "Error running '" . $command . "'" );
49             }
50              
51 0           return 1;
52             }
53              
54             1;