| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Oleg Hardt |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::Lxc::attach; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
21
|
use v5.12.5; |
|
|
1
|
|
|
|
|
4
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
50
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.2'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
8
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
9
|
|
|
13
|
1
|
|
|
1
|
|
23
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
374
|
|
|
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 attach options!"); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $options = _format_opts($opts); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $attach_command = "lxc-attach $options"; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
i_run $attach_command, fail_ok => 1; |
|
30
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
31
|
0
|
|
|
|
|
|
die("Error running \"$attach_command\""); |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $opts->{newname}; |
|
35
|
|
|
|
|
|
|
} |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub _format_opts { |
|
38
|
0
|
|
|
0
|
|
|
my ($opts) = @_; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# -n, --name="" |
|
41
|
|
|
|
|
|
|
# Assign the specified name to the container to be attached to. |
|
42
|
0
|
0
|
|
|
|
|
if ( !exists $opts->{"name"} ) { |
|
43
|
0
|
|
|
|
|
|
die("You have to give a name."); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $str = "-n $opts->{'name'}"; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# -B, --backingstorage=backingstorage |
|
49
|
|
|
|
|
|
|
# backingstorage type for the container |
|
50
|
0
|
0
|
|
|
|
|
if ( !exists $opts->{command} ) { |
|
51
|
0
|
|
|
|
|
|
die("You have to specify a COMMAND"); |
|
52
|
|
|
|
|
|
|
} |
|
53
|
0
|
|
|
|
|
|
$str .= " -- $opts->{command}"; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
return $str; |
|
56
|
|
|
|
|
|
|
} |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |