our
$VERSION
=
'0.0.1'
;
sub
execute {
my
(
$class
,
%opts
) =
@_
;
my
@required_keys
= (
'vm'
,
'device'
,
'path'
);
foreach
my
$key
(
@required_keys
) {
if
( !
defined
(
$opts
{
$key
} ) ) {
die
'The required variable "'
.
$key
.
'" is not set'
;
}
if
( (
$key
ne
'path'
)
&& (
$opts
{
$key
} =~ /[\t\ \=\\\/\'\"\n\;\&]/ ) )
{
die
'The value for "'
.
$key
.
'", "'
.
$opts
{
$key
}
.
'", matched /[\t\ \=\/\\\'\"\n\;\&]/, meaning it is not a valid value'
;
}
elsif
(
$opts
{
$key
} =~ /[\t\'\"\n\;\&]/ ) {
die
'The value for "'
.
$key
.
'", "'
.
$opts
{
$key
}
.
'", matched /[\t\'\"\n\;\&]/, meaning it is not a valid value'
;
}
}
my
$command
=
'cbsd bhyve-p9shares mode=attach jname='
.
$opts
{vm}
.
' device='
.
$opts
{device}
.
" path='"
.
$opts
{path} .
"'"
;
Rex::Logger::debug(
"Adding CBSD p9share via... "
.
$command
);
my
$returned
= i_run(
$command
,
fail_ok
=> 1 );
$returned
= colorstrip(
$returned
);
if
( $? != 0 ) {
die
(
"Error running '"
.
$command
.
"'"
);
}
return
1;
}
1;