our
$VERSION
=
'1.16.0'
;
sub
execute {
my
(
$class
,
$arg1
,
$action
,
$option
) =
@_
;
unless
(
$arg1
) {
die
(
"You have to define the vm name!"
);
}
my
$dom
=
$arg1
;
unless
(
$dom
) {
die
(
"VM $dom not found."
);
}
if
(
$action
eq
"add"
) {
FOLDER:
for
my
$folder
(
keys
%{
$option
} ) {
my
$info
= Rex::Virtualization::VBox::info->execute(
$dom
);
my
@keys
=
grep
{ m/^SharedFolderNameMachineMapping/ }
keys
%{
$info
};
for
my
$k
(
@keys
) {
if
(
$info
->{
$k
} eq
$folder
) {
next
FOLDER;
}
}
my
$from_path
=
$option
->{
$folder
};
i_run
"VBoxManage sharedfolder add \"$dom\" --name \"$folder\" --automount --hostpath \"$from_path\""
;
}
}
else
{
if
(
$option
ne
"-all"
) {
i_run
"VBoxManage sharedfolder remove \"$dom\" --name \"$option\""
;
}
else
{
my
$info
= Rex::Virtualization::VBox::info->execute(
$dom
);
my
@keys
=
grep
{ m/^SharedFolderNameMachineMapping/ }
keys
%{
$info
};
for
my
$k
(
@keys
) {
i_run
"VBoxManage sharedfolder delete \"$dom\" --name \"$info->{$k}\""
;
}
}
}
if
( $? != 0 ) {
die
(
"Error setting folder shares for vm $dom"
);
}
}
1;