| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::LibVirt::info; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use v5.14.4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '1.16.1'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Rex::Logger; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Rex::Helper::Run; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use XML::Simple; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Rex::Virtualization::LibVirt::dumpxml; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | my ( $class, $vmname ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | my $virt_settings = Rex::Config->get("virtualization"); | |||||||||||||||||||||||||||||||||||||||||
| 23 | chomp( my $uri = | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | ref($virt_settings) ? $virt_settings->{connect} : i_run "virsh uri" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | unless ($vmname) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | die("You have to define the vm name!"); | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | Rex::Logger::debug("Getting info of domain: $vmname"); | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | my $xml; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my @dominfo = i_run "virsh -c $uri dominfo '$vmname'", fail_ok => 1; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | die("Error running virsh dominfo '$vmname'"); | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my %ret = (); | |||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my ( $k, $v ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | for my $line (@dominfo) { | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ( $k, $v ) = split( /:\s+/, $line ); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $ret{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (Rex::Config::get_use_rex_kvm_agent) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | my $xml_ref = Rex::Virtualization::LibVirt::dumpxml->execute($vmname); | |||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ( $xml_ref | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$xml_ref and exists $xml_ref->{"devices"}{"serial"} and ref $xml_ref->{"devices"}{"serial"} eq "ARRAY"
$xml_ref and exists $xml_ref->{"devices"}{"serial"}
MC/DC0%0/3
$xml_ref and exists $xml_ref->{"devices"}{"serial"} and ref $xml_ref->{"devices"}{"serial"} eq "ARRAY"
$xml_ref
exists $xml_ref->{"devices"}{"serial"}
ref $xml_ref->{"devices"}{"serial"} eq "ARRAY"
Truth table0%0/4
A and B and C
A= $xml_refB= exists $xml_ref->{"devices"}{"serial"}C= ref $xml_ref->{"devices"}{"serial"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | && exists $xml_ref->{devices}->{serial} | ||||||||||||||||||||||||||||||||||||||||||
| 52 | && ref $xml_ref->{devices}->{serial} eq "ARRAY" ) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | my ($agent_serial) = grep { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | exists $_->{type} | ||||||||||||||||||||||||||||||||||||||||||
| 56 | && $_->{type} eq "tcp" | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | && $_->{target}->{port} == 1 | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
exists $_->{'type'} && $_->{'type'} eq 'tcp' && $_->{'target'}{'port'} == 1
exists $_->{"type"} and $_->{"type"} eq "tcp"
MC/DC0%0/3
exists $_->{'type'} && $_->{'type'} eq 'tcp' && $_->{'target'}{'port'} == 1
exists $_->{"type"}
$_->{"type"} eq "tcp"
$_->{'target'}{'port'} == 1
Truth table0%0/4
A and B && C
A= exists $_->{"type"}B= $_->{"type"} eq "tcp"C= $_->{'target'}{'port'} == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | } @{ $xml_ref->{devices}->{serial} }; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | #TODO: $xml_ref->{devices}->{serial} is an arrayref if there are multiple devices, hashref otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 61 | #TODO: it might be a better idea to name the serial device and match by its name here | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $ret{has_kvm_agent_on_port} = $agent_serial->{source}->{service}; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | return \%ret; | |||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||