CBSD/bset.pm

filter: Statementstmt 50.0% 17 / 34 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 83.3% 5 / 6 Podpod 0.0% 0 / 1 totaltotal 44.9% 22 / 49 CC 6 SCAR 31.5
CC
6
Cov
40%
execute
42.0
BEGIN
1.0
BEGIN
1.0
CRAP 23.4
« CBSD/bsnapshot_rollback.pm ↑ Summary CBSD/freejname.pm »
1 #
2 # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net>
3 #
4  
5 package Rex::Virtualization::CBSD::bset;
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '0.0.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Term::ANSIColor qw(colorstrip);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub execute {
Subroutine execute: not called CC=6 SCAR=37.4
Pod undocumented
17 0 my ( $class, $name, %opts ) = @_;
18  
19 # make sure we have a
20 0 ▶ if ( !defined($name) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 0 0 0
21 0 die('No VM name defined');
22 }
23  
24 # puts together the string of what to set etc
25 0 my $to_set = '';
26 0 foreach my $key ( keys(%opts) ) {
27  
28 # make sure it does not contain any spaces
29 0 ▶ if ( $key =~ /[\t\ \=\\\/\'\"\n]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ m[[\t\ \=\\/\'\"\n]]) 0 0 0
30 0 die 'The variable "' . $key . '" matched /[\t\ \=\/\\\'\"\n]/, meaning it is not a valid variable name';
31 }
32  
33 # make sure we don't have any quotes
34 0 ▶ if ( $opts{$key} =~ /[\'\"]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{$key} =~ /[\'\"]/) 0 0 0
35 0 die "The value '" . $opts{$key} . "' for key '" . $key . "' contains a single or double quote";
36 }
37  
38 0 $to_set = $to_set . ' ' . $key . "='" . $opts{$key} . "'";
39 }
40  
41 0 my $command = 'cbsd bset jname=' . $name . $to_set;
42  
43 0 Rex::Logger::debug( "Setting config value for a CBSD VM via... " . $command );
44  
45 0 my $returned = i_run( $command, fail_ok => 1 );
46  
47 # the output is colorized
48 0 $returned = colorstrip($returned);
49  
50 # test after no such as that will also exit non-zero
51 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
52 0 die( "Error running '" . $command . "' returned... " . $returned );
53 }
54  
55 0 return 1;
56 }
57  
58 1 1;
« CBSD/bsnapshot_rollback.pm ↑ Summary CBSD/freejname.pm »