| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# (c) Oleg Hardt |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::Lxc::copy; |
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
15
|
use v5.12.5; |
|
|
1
|
|
|
|
|
3
|
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
44
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.2.3'; # TRIAL VERSION |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Rex::Logger; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
18
|
|
|
13
|
1
|
|
|
1
|
|
72
|
use Rex::Helper::Run; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
344
|
|
|
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 copy options!"); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $options = _format_opts($opts); |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $copy_command = "lxc-copy $options"; |
|
28
|
0
|
|
|
|
|
|
i_run $copy_command, fail_ok => 1; |
|
29
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
|
30
|
0
|
|
|
|
|
|
die("Error running \"$copy_command\""); |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $opts->{newname}; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _format_opts { |
|
37
|
0
|
|
|
0
|
|
|
my ($opts) = @_; |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# -n, --name="" |
|
40
|
|
|
|
|
|
|
# Assign the specified name to the container to be copied. |
|
41
|
0
|
0
|
|
|
|
|
if ( !exists $opts->{"name"} ) { |
|
42
|
0
|
|
|
|
|
|
die("You have to give a name."); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# -N, --newname="" |
|
46
|
|
|
|
|
|
|
# Assign the specified name to the new container. |
|
47
|
0
|
0
|
|
|
|
|
if ( !exists $opts->{"newname"} ) { |
|
48
|
0
|
|
|
|
|
|
die("You have to specify a newname."); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $str = "-n $opts->{'name'} -N $opts->{'newname'}"; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# -s, --snapshot |
|
54
|
|
|
|
|
|
|
# create snapshot instead of clone |
|
55
|
0
|
0
|
|
|
|
|
if ( exists $opts->{snapshot} ) { |
|
56
|
0
|
|
|
|
|
|
$str .= " -s"; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# -B, --backingstorage=backingstorage |
|
60
|
|
|
|
|
|
|
# backingstorage type for the container |
|
61
|
0
|
0
|
|
|
|
|
if ( exists $opts->{backingstorage} ) { |
|
62
|
0
|
|
|
|
|
|
$str .= " -B $opts->{backingstorage}"; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# -e, --ephemeral |
|
66
|
|
|
|
|
|
|
# create snapshot instead of clone |
|
67
|
0
|
0
|
|
|
|
|
if ( exists $opts->{ephemeral} ) { |
|
68
|
0
|
|
|
|
|
|
$str .= " -e"; |
|
69
|
|
|
|
|
|
|
} |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# -m, --mount |
|
72
|
|
|
|
|
|
|
# create snapshot instead of clone |
|
73
|
0
|
0
|
|
|
|
|
if ( exists $opts->{mount} ) { |
|
74
|
0
|
|
|
|
|
|
$str .= " -m $opts->{mount}"; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return $str; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |