File Coverage

lib/Rex/Virtualization/VBox/list.pm
Criterion Covered Total %
statement 14 32 43.7
branch 0 8 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 19 47 40.4


line stmt bran cond sub pod time code
1             #
2             # (c) Jan Gehring
3             #
4              
5             package Rex::Virtualization::VBox::list;
6              
7 1     1   14 use v5.12.5;
  1         3  
8 1     1   5 use warnings;
  1         2  
  1         40  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 1     1   6 use Rex::Logger;
  1         2  
  1         5  
13 1     1   24 use Rex::Helper::Run;
  1         3  
  1         68  
14              
15 1     1   6 use Data::Dumper;
  1         2  
  1         284  
16              
17             sub execute {
18 0     0 0   my ( $class, $arg1, %opt ) = @_;
19 0           my @domains;
20              
21 0 0         if ( $arg1 eq "all" ) {
    0          
22 0           @domains = i_run "VBoxManage list vms", fail_ok => 1;
23 0 0         if ( $? != 0 ) {
24 0           die("Error running VBoxManage list vms");
25             }
26             }
27             elsif ( $arg1 eq "running" ) {
28 0           @domains = i_run "VBoxManage list runningvms", fail_ok => 1;
29 0 0         if ( $? != 0 ) {
30 0           die("Error running VBoxManage runningvms");
31             }
32             }
33             else {
34 0           return;
35             }
36              
37 0           my @ret = ();
38 0           for my $line (@domains) {
39 0           my ( $name, $id ) = $line =~ m:^"([^"]+)"\s*\{([^\}]+)\}$:;
40              
41 0           my @status = map { /^VMState="([^"]+)"$/ }
  0            
42             i_run "VBoxManage showvminfo \"{$id}\" --machinereadable", fail_ok => 1;
43 0           my $status;
44              
45 0           push(
46             @ret,
47             {
48             id => $id,
49             name => $name,
50             status => $status[0],
51             }
52             );
53             }
54              
55 0           return \@ret;
56              
57             }
58              
59             1;