line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization; |
6
|
|
|
|
|
|
|
|
7
|
4
|
|
|
4
|
|
70086
|
use v5.12.5; |
|
4
|
|
|
|
|
33
|
|
8
|
4
|
|
|
4
|
|
20
|
use warnings; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
205
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
867
|
use Rex::Logger; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
77
|
|
13
|
4
|
|
|
4
|
|
1175
|
use Rex::Config; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
24
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %VM_PROVIDER; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Rex::Config->register_config_handler( |
18
|
|
|
|
|
|
|
virtualization => sub { |
19
|
|
|
|
|
|
|
my ($param) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
if ( ref($param) eq '' ) { |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#support 'set virtualization => 'LibVirt', but leave the way open for using a hash in future |
24
|
|
|
|
|
|
|
#other virtualisation drivers may need more settings... |
25
|
|
|
|
|
|
|
$param = { type => $param }; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ( exists $param->{type} ) { |
29
|
|
|
|
|
|
|
Rex::Config->set( virtualization => $param->{type} ); |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub register_vm_provider { |
35
|
0
|
|
|
0
|
0
|
0
|
my ( $class, $service_name, $service_class ) = @_; |
36
|
0
|
|
|
|
|
0
|
$VM_PROVIDER{"\L$service_name"} = $service_class; |
37
|
0
|
|
|
|
|
0
|
return 1; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub create { |
41
|
5
|
|
|
5
|
0
|
332
|
my ( $class, $wanted_provider ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
5
|
|
100
|
|
|
29
|
$wanted_provider ||= Rex::Config->get("virtualization"); |
44
|
5
|
50
|
|
|
|
16
|
if ( ref($wanted_provider) ) { |
45
|
0
|
|
0
|
|
|
0
|
$wanted_provider = $wanted_provider->{type} || "LibVirt"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
5
|
100
|
|
|
|
44
|
if ( !$wanted_provider ) { |
49
|
1
|
|
|
|
|
11
|
die |
50
|
|
|
|
|
|
|
"No virtualization provider set.\nPlease use `set virtualization => 'YourProvider';` to set one,\nor see `perldoc Rex::Commands::Virtualization` for more options"; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
4
|
|
|
|
|
15
|
my $klass = "Rex::Virtualization::$wanted_provider"; |
54
|
|
|
|
|
|
|
|
55
|
4
|
50
|
|
|
|
14
|
if ( exists $VM_PROVIDER{$wanted_provider} ) { |
56
|
0
|
|
|
|
|
0
|
$klass = $VM_PROVIDER{$wanted_provider}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
4
|
|
|
3
|
|
242
|
eval "use $klass"; |
|
3
|
|
|
1
|
|
458
|
|
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
18
|
|
|
1
|
|
|
|
|
448
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
60
|
|
|
|
|
|
|
|
61
|
4
|
100
|
|
|
|
53
|
if ($@) { |
62
|
1
|
|
|
|
|
9
|
die |
63
|
|
|
|
|
|
|
"Failed loading given virtualization module.\nTried to load <$klass>.\nError: $@\n"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
3
|
|
|
|
|
21
|
Rex::Logger::debug("Using $klass for virtualization"); |
67
|
|
|
|
|
|
|
|
68
|
3
|
|
|
|
|
10
|
my $mod = $klass->new; |
69
|
3
|
|
|
|
|
13
|
return $mod; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |