| 1 | # | ||||||||||||||||||||||||||||||||
| 2 | # (c) Zane C. Bowers-Hadley <vvelox@vvelox.net> | ||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::CBSD::p9shares_add; | ||||||||||||||||||||||||||||||||
| 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=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 17 | 0 | my ( $class, %opts ) = @_; | |||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | # make sure all the keys are sane | ||||||||||||||||||||||||||||||||
| 20 | 0 | my @required_keys = ( 'vm', 'device', 'path' ); | |||||||||||||||||||||||||||||||
| 21 | 0 | foreach my $key (@required_keys) { | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | if ( !defined( $opts{$key} ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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 | ▶ | if ( ( $key ne 'path' ) | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$key ne "path" and $opts{$key} =~ m[[\t\ \=\\/\'\"\n\;\&]]
MC/DC0%0/2
$key ne "path" and $opts{$key} =~ m[[\t\ \=\\/\'\"\n\;\&]]
$key ne "path"
$opts{$key} =~ m[[\t\ \=\\/\'\"\n\;\&]]
Truth table0%0/3
A and B
A= $key ne "path"B= $opts{$key} =~ m[[\t\ \=\\/\'\"\n\;\&]]
| |||||||||||||||||||||||||||||||||
| 29 | && ( $opts{$key} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) ) | ||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||
| 31 | die 'The value for "' | ||||||||||||||||||||||||||||||||
| 32 | . $key . '", "' | ||||||||||||||||||||||||||||||||
| 33 | 0 | . $opts{$key} | |||||||||||||||||||||||||||||||
| 34 | . '", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'; | ||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | elsif ( $opts{$key} =~ /[\t\'\"\n\;\&]/ ) { | ||||||||||||||||||||||||||||||||
| 37 | die 'The value for "' | ||||||||||||||||||||||||||||||||
| 38 | . $key . '", "' | ||||||||||||||||||||||||||||||||
| 39 | 0 | . $opts{$key} | |||||||||||||||||||||||||||||||
| 40 | . '", matched /[\t\'\"\n\;\&]/, meaning it is not a valid value'; | ||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||
| 44 | # put together the command | ||||||||||||||||||||||||||||||||
| 45 | my $command | ||||||||||||||||||||||||||||||||
| 46 | = 'cbsd bhyve-p9shares mode=attach jname=' | ||||||||||||||||||||||||||||||||
| 47 | . $opts{vm} | ||||||||||||||||||||||||||||||||
| 48 | . ' device=' | ||||||||||||||||||||||||||||||||
| 49 | . $opts{device} | ||||||||||||||||||||||||||||||||
| 50 | . " path='" | ||||||||||||||||||||||||||||||||
| 51 | 0 | . $opts{path} . "'"; | |||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 0 | Rex::Logger::debug( "Adding CBSD p9share via... " . $command ); | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 0 | my $returned = i_run( $command, fail_ok => 1 ); | |||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | # the output is colorized, if there is an error | ||||||||||||||||||||||||||||||||
| 58 | 0 | $returned = colorstrip($returned); | |||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | # check for this second as no VM will also exit non-zero | ||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 0 | die( "Error running '" . $command . "'" ); | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | 0 | return 1; | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | 1 | 1; | |||||||||||||||||||||||||||||||