| 1 | # | ||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||
| 3 | # | ||||||||||||||
| 4 | |||||||||||||||
| 5 | package Rex::Virtualization::VBox::list; | ||||||||||||||
| 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 Data::Dumper; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 0 | ▶ | sub execute { | ||||||||||||
|
Subroutine
execute: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||
| 18 | 0 | my ( $class, $arg1, %opt ) = @_; | |||||||||||||
| 19 | 0 | my @domains; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | ▶ | if ( $arg1 eq "all" ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 22 | 0 | @domains = i_run "VBoxManage list vms", fail_ok => 1; | |||||||||||||
| 23 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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 | ▶ | if ( $? != 0 ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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="([^"]+)"$/ } | |||||||||||||
| 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 | 1; | |||||||||||||