File Coverage

lib/Rex/Virtualization/VBox/info.pm
Criterion Covered Total %
statement 17 33 51.5
branch 0 4 0.0
condition n/a
subroutine 6 7 85.7
pod 0 1 0.0
total 23 45 51.1


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Virtualization::VBox::info;
6              
7 1     1   13 use v5.12.5;
  1         11  
8 1     1   5 use warnings;
  1         5  
  1         59  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 1     1   7 use Rex::Logger;
  1         3  
  1         6  
13 1     1   76 use Rex::Helper::Run;
  1         6  
  1         73  
14              
15 1     1   8 use XML::Simple;
  1         13  
  1         10  
16              
17 1     1   93 use Data::Dumper;
  1         2  
  1         299  
18              
19             sub execute {
20 0     0 0   my ( $class, $vmname ) = @_;
21              
22 0 0         unless ($vmname) {
23 0           die("You have to define the vm name!");
24             }
25              
26 0           Rex::Logger::debug("Getting info of domain: $vmname");
27              
28 0           my $xml;
29              
30 0           my @dominfo = i_run "VBoxManage showvminfo \"$vmname\" --machinereadable",
31             fail_ok => 1;
32              
33 0 0         if ( $? != 0 ) {
34 0           die("Error running VBoxManage showvminfo $vmname");
35             }
36              
37 0           my %ret = ();
38 0           my ( $k, $v );
39              
40 0           for my $line (@dominfo) {
41 0           ( $k, $v ) = split( /=/, $line );
42 0           $k =~ s/^"|"$//g;
43 0           $v =~ s/^"|"$//g;
44 0           $ret{$k} = $v;
45             }
46              
47 0           return \%ret;
48             }
49              
50             1;