| 1 | # | ||||||||||||||||||||||||||||
| 2 | # (c) Oleg Hardt <litwol@litwol.com> | ||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | package Rex::Virtualization::Lxc::stop; | ||||||||||||||||||||||||||||
| 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 | 1 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub execute { | ||||||||||||||||||||||||||
|
Subroutine
execute: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $class, $arg1, %opt ) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | unless ($arg1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | die("You have to define the container name!"); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | my $container_name = $arg1; | |||||||||||||||||||||||||||
| 24 | 0 | Rex::Logger::debug("stopping container $container_name"); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | unless ($container_name) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | die("VM $container_name not found."); | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my $opts = \%opt; | |||||||||||||||||||||||||||
| 31 | my $timeout = | ||||||||||||||||||||||||||||
| 32 | ( exists $opts->{timeout} and looks_like_number( $opts->{timeout} ) ) | ||||||||||||||||||||||||||||
| 33 | ? $opts->{timeout} | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | : 30; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $opts->{"timeout"} and &looks_like_number($opts->{"timeout"})
MC/DC0%0/2
exists $opts->{"timeout"} and &looks_like_number($opts->{"timeout"})
exists $opts->{"timeout"}
&looks_like_number($opts->{"timeout"})
Truth table0%0/3
A and B
A= exists $opts->{"timeout"}B= &looks_like_number($opts->{"timeout"})
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | i_run "lxc-stop -t $timeout -n \"$container_name\"", fail_ok => 1; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ( $? != 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | die("Error stopping container $container_name"); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | 1; | |||||||||||||||||||||||||||