lib/Rex/Virtualization/Lxc/destroy.pm

filter: Statementstmt 38.2% 13 / 34 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 1 totaltotal 33.3% 17 / 51 CC 6 SCAR 23.9
CC
6
Cov
30%
_format_opts
20.0
execute
12.0
BEGIN
1.0
CRAP 10.9
« lib/Rex/Interface/Connection/HTTP.pm ↑ Summary lib/Rex/Inventory/SMBios/Section.pm »
1 #
2 # (c) Oleg Hardt <litwol@litwol.com>
3 #
4  
5 package Rex::Virtualization::Lxc::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=3 SCAR=24.8
Pod undocumented
16 0 my ( $class, $name, %opt ) = @_;
17  
18 0 my $opts = \%opt;
19 0 $opts->{name} = $name;
20  
21 0 ▶ unless ($opts) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts) 0 0 0
22 0 die("You have to define the destroy options!");
23 }
24  
25 0 Rex::Logger::debug("destroying container $opts->{name}");
26  
27 0 my $options = _format_opts($opts);
28  
29 0 my $destroy_command = "lxc-destroy $options";
30  
31 0 i_run $destroy_command, fail_ok => 1;
32 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
33 0 die("Error destroying container $opts->{name}");
34 }
35  
36 0 return $opts->{name};
37 }
38  
39 0 ▶sub _format_opts {
Subroutine _format_opts: not called CC=4 SCAR=30.0
40 0 my ($opts) = @_;
41  
42 # -n, --name=""
43 # Assign the specified name to the container.
44 0 ▶ if ( !exists $opts->{name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"name"}) 0 0 0
45 0 die("You have to give a name.");
46 }
47  
48 0 my $str = "-n $opts->{name}";
49  
50 # -s, --snapshots=""
51 # destroy including all snapshots.
52 0 ▶ if ( exists $opts->{snapshots} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"snapshots"}) 0 0 0
53 0 $str .= " -s";
54 }
55  
56 # -f, --force
57 # wait for the container to shut down.
58 0 ▶ if ( exists $opts->{force} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"force"}) 0 0 0
59 0 $str .= " -f";
60 }
61  
62 0 return $str;
63 }
64  
65 1 1;
« lib/Rex/Interface/Connection/HTTP.pm ↑ Summary lib/Rex/Inventory/SMBios/Section.pm »