line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Jan Gehring |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::LibVirt::hypervisor; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
28
|
use v5.12.5; |
|
2
|
|
|
|
|
8
|
|
8
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
80
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
28
|
use Rex::Logger; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
13
|
2
|
|
|
2
|
|
43
|
use Rex::Helper::Run; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
145
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
13
|
use XML::Simple; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
15
|
|
16
|
|
|
|
|
|
|
|
17
|
2
|
|
|
2
|
|
116
|
use Data::Dumper; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1052
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub execute { |
20
|
2
|
|
|
2
|
0
|
7
|
my ( $class, $arg1, %opt ) = @_; |
21
|
2
|
|
|
|
|
5
|
my $virt_settings = Rex::Config->get("virtualization"); |
22
|
|
|
|
|
|
|
chomp( my $uri = |
23
|
2
|
50
|
|
|
|
9
|
ref($virt_settings) ? $virt_settings->{connect} : i_run "virsh uri" ); |
24
|
|
|
|
|
|
|
|
25
|
2
|
50
|
|
|
|
15
|
unless ($arg1) { |
26
|
0
|
|
|
|
|
0
|
die("You have to define the vm name!"); |
27
|
|
|
|
|
|
|
} |
28
|
2
|
|
|
|
|
5
|
my ( $xml, @dominfo ); |
29
|
2
|
50
|
|
|
|
7
|
if ( $arg1 eq 'capabilities' ) { |
30
|
2
|
|
|
|
|
8
|
@dominfo = i_run "virsh -c $uri capabilities", fail_ok => 1; |
31
|
2
|
50
|
|
|
|
443
|
if ( $? != 0 ) { |
32
|
0
|
|
|
|
|
0
|
die("Error running virsh capabilities"); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
|
|
16
|
my $xs = XML::Simple->new(); |
36
|
2
|
|
|
|
|
234
|
$xml = $xs->XMLin( |
37
|
|
|
|
|
|
|
join( "", @dominfo ), |
38
|
|
|
|
|
|
|
KeepRoot => 1, |
39
|
|
|
|
|
|
|
KeyAttr => 1, |
40
|
|
|
|
|
|
|
ForceContent => 1 |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
0
|
Rex::Logger::debug("Unknown action $arg1"); |
45
|
0
|
|
|
|
|
0
|
die("Unknown action $arg1"); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
2
|
|
|
|
|
429900
|
my %ret = (); |
49
|
2
|
|
|
|
|
6
|
my ( $k, $v ); |
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
14
|
if ( ref( $xml->{'capabilities'}->{'guest'} ) ne "ARRAY" ) { |
52
|
0
|
|
|
|
|
0
|
$xml->{'capabilities'}->{'guest'} = [ $xml->{'capabilities'}->{'guest'} ]; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
2
|
|
|
|
|
5
|
for my $line ( @{ $xml->{'capabilities'}->{'guest'} } ) { |
|
2
|
|
|
|
|
11
|
|
56
|
|
|
|
|
|
|
|
57
|
4
|
100
|
|
|
|
17
|
next if ( $line->{'arch'}->{'name'} ne "x86_64" ); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$ret{ $line->{'arch'}->{'name'} } = 'true' |
60
|
2
|
50
|
|
|
|
15
|
if defined( $line->{'arch'}->{'name'} ); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$ret{'emulator'} = $line->{'arch'}->{'emulator'}->{'content'} |
63
|
2
|
50
|
|
|
|
12
|
if defined( $line->{'arch'}->{'emulator'}->{'content'} ); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$ret{'loader'} = $line->{'arch'}->{'loader'}->{'content'} |
66
|
2
|
50
|
|
|
|
11
|
if defined( $line->{'arch'}->{'loader'}->{'content'} ); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$ret{ $line->{'os_type'}->{'content'} } = 'true' |
69
|
2
|
50
|
|
|
|
13
|
if defined( $line->{'os_type'}->{'content'} ); |
70
|
|
|
|
|
|
|
|
71
|
2
|
50
|
33
|
|
|
21
|
if ( defined( $line->{'arch'}->{'domain'} ) |
72
|
|
|
|
|
|
|
&& ref( $line->{'arch'}->{'domain'} ) eq 'ARRAY' ) |
73
|
|
|
|
|
|
|
{ |
74
|
2
|
|
|
|
|
5
|
for ( @{ $line->{'arch'}->{'domain'} } ) { |
|
2
|
|
|
|
|
9
|
|
75
|
4
|
|
|
|
|
48
|
$ret{ $_->{'type'} } = 'true'; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
else { |
79
|
|
|
|
|
|
|
$ret{ $line->{'arch'}->{'domain'}->{'type'} } = 'true' |
80
|
0
|
0
|
|
|
|
0
|
if defined( $line->{'arch'}->{'domain'}->{'type'} ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
2
|
|
|
|
|
190
|
return \%ret; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |