File Coverage

lib/Rex/Virtualization/Lxc/stop.pm
Criterion Covered Total %
statement 14 26 53.8
branch 0 8 0.0
condition 0 3 0.0
subroutine 5 6 83.3
pod 0 1 0.0
total 19 44 43.1


line stmt bran cond sub pod time code
1             #
2             # (c) Oleg Hardt
3             #
4              
5             package Rex::Virtualization::Lxc::stop;
6              
7 1     1   16 use v5.12.5;
  1         5  
8 1     1   5 use warnings;
  1         8  
  1         57  
9              
10             our $VERSION = '1.14.2.2'; # TRIAL VERSION
11              
12 1     1   8 use Rex::Logger;
  1         3  
  1         10  
13 1     1   26 use Rex::Helper::Run;
  1         5  
  1         75  
14 1     1   8 use Scalar::Util qw(looks_like_number);
  1         2  
  1         319  
15              
16             sub execute {
17 0     0 0   my ( $class, $arg1, %opt ) = @_;
18              
19 0 0         unless ($arg1) {
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 0         unless ($container_name) {
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 0 0       : 30;
35              
36 0           i_run "lxc-stop -t $timeout -n \"$container_name\"", fail_ok => 1;
37 0 0         if ( $? != 0 ) {
38 0           die("Error stopping container $container_name");
39             }
40              
41             }
42              
43             1;