| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Jan Gehring <jan.gehring@gmail.com> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::LibVirt::destroy; | ||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 0 | my ( $class, $arg1, %opt ) = @_; | |||||||||||||||||||||||||||
| 17 | 0 | my $virt_settings = Rex::Config->get("virtualization"); | |||||||||||||||||||||||||||
| 18 | chomp( my $uri = | ||||||||||||||||||||||||||||
| 19 | 0 | ▶ | ref($virt_settings) ? $virt_settings->{connect} : i_run "virsh uri" ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | unless ($arg1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | die("You have to define the vm name!"); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $dom = $arg1; | |||||||||||||||||||||||||||
| 26 | 0 | Rex::Logger::debug("destroying domain: $dom"); | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | unless ($dom) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 0 | die("VM $dom not found."); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # virsh must distinguish between a not-running VM and failed to destroy via exit code! | ||||||||||||||||||||||||||||
| 33 | 0 | my $out = i_run "virsh -c $uri destroy '$dom' 2>&1", fail_ok => 1; | |||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ( $? != 0 && $out !~ /domain is not running/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$? != 0 and not $out =~ /domain is not running/u
MC/DC0%0/2
$? != 0 and not $out =~ /domain is not running/u
$? != 0
not $out =~ /domain is not running/u
Truth table0%0/3
A and not(B)
A= $? != 0B= not $out =~ /domain is not running/u
| |||||||||||||||||||||||||||||
| 35 | 0 | die("Error destroying vm $dom"); | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 1 | 1; | |||||||||||||||||||||||||||