line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Oleg Hardt |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::Lxc::destroy; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
14
|
use v5.12.5; |
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
40
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Rex::Logger; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
13
|
1
|
|
|
1
|
|
19
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
378
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub execute { |
16
|
0
|
|
|
0
|
0
|
|
my ( $class, $name, %opt ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
my $opts = \%opt; |
19
|
0
|
|
|
|
|
|
$opts->{name} = $name; |
20
|
|
|
|
|
|
|
|
21
|
0
|
0
|
|
|
|
|
unless ($opts) { |
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
|
0
|
|
|
|
|
if ( $? != 0 ) { |
33
|
0
|
|
|
|
|
|
die("Error destroying container $opts->{name}"); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
return $opts->{name}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _format_opts { |
40
|
0
|
|
|
0
|
|
|
my ($opts) = @_; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# -n, --name="" |
43
|
|
|
|
|
|
|
# Assign the specified name to the container. |
44
|
0
|
0
|
|
|
|
|
if ( !exists $opts->{name} ) { |
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
|
0
|
|
|
|
|
if ( exists $opts->{snapshots} ) { |
53
|
0
|
|
|
|
|
|
$str .= " -s"; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# -f, --force |
57
|
|
|
|
|
|
|
# wait for the container to shut down. |
58
|
0
|
0
|
|
|
|
|
if ( exists $opts->{force} ) { |
59
|
0
|
|
|
|
|
|
$str .= " -f"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
return $str; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |