line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::VBox::share_folder; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
14
|
use v5.12.5; |
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
40
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Rex::Logger; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
45
|
|
13
|
1
|
|
|
1
|
|
32
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
68
|
|
14
|
1
|
|
|
1
|
|
16
|
use Rex::Virtualization::VBox::info; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
13
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# |
17
|
|
|
|
|
|
|
# vm share_folder => "foovm", add => { sharename => "/host/path" }; |
18
|
|
|
|
|
|
|
# vm share_folder => "foovm", remove => "sharename"; |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub execute { |
22
|
0
|
|
|
0
|
0
|
|
my ( $class, $arg1, $action, $option ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
0
|
0
|
|
|
|
|
unless ($arg1) { |
25
|
0
|
|
|
|
|
|
die("You have to define the vm name!"); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $dom = $arg1; |
29
|
|
|
|
|
|
|
|
30
|
0
|
0
|
|
|
|
|
unless ($dom) { |
31
|
0
|
|
|
|
|
|
die("VM $dom not found."); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
if ( $action eq "add" ) { |
35
|
0
|
|
|
|
|
|
FOLDER: for my $folder ( keys %{$option} ) { |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $info = Rex::Virtualization::VBox::info->execute($dom); |
37
|
0
|
|
|
|
|
|
my @keys = grep { m/^SharedFolderNameMachineMapping/ } keys %{$info}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
for my $k (@keys) { |
39
|
0
|
0
|
|
|
|
|
if ( $info->{$k} eq $folder ) { |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# folder already mapped |
42
|
0
|
|
|
|
|
|
next FOLDER; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $from_path = $option->{$folder}; |
47
|
0
|
|
|
|
|
|
i_run |
48
|
|
|
|
|
|
|
"VBoxManage sharedfolder add \"$dom\" --name \"$folder\" --automount --hostpath \"$from_path\""; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
else { |
52
|
0
|
0
|
|
|
|
|
if ( $option ne "-all" ) { |
53
|
0
|
|
|
|
|
|
i_run "VBoxManage sharedfolder remove \"$dom\" --name \"$option\""; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
else { |
56
|
|
|
|
|
|
|
# if no name is given, remove all redirects |
57
|
|
|
|
|
|
|
# output: SharedFolderNameMachineMapping1 |
58
|
0
|
|
|
|
|
|
my $info = Rex::Virtualization::VBox::info->execute($dom); |
59
|
0
|
|
|
|
|
|
my @keys = grep { m/^SharedFolderNameMachineMapping/ } keys %{$info}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
for my $k (@keys) { |
62
|
0
|
|
|
|
|
|
i_run "VBoxManage sharedfolder delete \"$dom\" --name \"$info->{$k}\""; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
69
|
0
|
|
|
|
|
|
die("Error setting folder shares for vm $dom"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |