lib/Rex/Virtualization/Lxc/copy.pm

filter: Statementstmt 33.3% 13 / 39 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 4 / 6 Podpod 0.0% 0 / 1 totaltotal 27.4% 17 / 62 CC 9 SCAR 34.3
CC
9
Cov
24%
_format_opts
56.0
execute
12.0
BEGIN
1.0
CRAP 30.9
« blib/lib/Rex/Interface/Connection/SSH.pm ↑ Summary lib/Rex/Virtualization/Docker/import.pm »
1 #
2 # (c) Oleg Hardt <litwol@litwol.com>
3 #
4  
5 package Rex::Virtualization::Lxc::copy;
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 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 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
30 0 die("Error running \"$copy_command\"");
31 }
32  
33 0 return $opts->{newname};
34 }
35  
36 0 ▶sub _format_opts {
Subroutine _format_opts: not called CC=7 SCAR=40.3
37 0 my ($opts) = @_;
38  
39 # -n, --name=""
40 # Assign the specified name to the container to be copied.
41 0 ▶ if ( !exists $opts->{"name"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"name"}) 0 0 0
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 ▶ if ( !exists $opts->{"newname"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"newname"}) 0 0 0
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 ▶ if ( exists $opts->{snapshot} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"snapshot"}) 0 0 0
56 0 $str .= " -s";
57 }
58  
59 # -B, --backingstorage=backingstorage
60 # backingstorage type for the container
61 0 ▶ if ( exists $opts->{backingstorage} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"backingstorage"}) 0 0 0
62 0 $str .= " -B $opts->{backingstorage}";
63 }
64  
65 # -e, --ephemeral
66 # create snapshot instead of clone
67 0 ▶ if ( exists $opts->{ephemeral} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"ephemeral"}) 0 0 0
68 0 $str .= " -e";
69 }
70  
71 # -m, --mount
72 # create snapshot instead of clone
73 0 ▶ if ( exists $opts->{mount} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"mount"}) 0 0 0
74 0 $str .= " -m $opts->{mount}";
75 }
76  
77 0 return $str;
78 }
79  
80 1 1;
« blib/lib/Rex/Interface/Connection/SSH.pm ↑ Summary lib/Rex/Virtualization/Docker/import.pm »