line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# (c) Oleg Hardt |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Rex::Virtualization::Lxc::create; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
20
|
use v5.12.5; |
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
9
|
use warnings; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
39
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.14.3'; # VERSION |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Rex::Logger; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
10
|
|
13
|
1
|
|
|
1
|
|
29
|
use Rex::Helper::Run; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
357
|
|
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 create options!"); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my $options = _format_opts($opts); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $create_command = "lxc-create $options"; |
28
|
0
|
|
|
|
|
|
i_run $create_command, fail_ok => 1; |
29
|
0
|
0
|
|
|
|
|
if ( $? != 0 ) { |
30
|
0
|
|
|
|
|
|
die("Error running \"$create_command\""); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $opts->{name}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _format_opts { |
37
|
0
|
|
|
0
|
|
|
my ($opts) = @_; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# -n, --name="" |
40
|
|
|
|
|
|
|
# Assign the specified name to the container. |
41
|
0
|
0
|
|
|
|
|
if ( !exists $opts->{"name"} ) { |
42
|
0
|
|
|
|
|
|
die("You have to give a name."); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# -t, --template="" |
46
|
|
|
|
|
|
|
# Assign the specified template to the container. |
47
|
0
|
0
|
|
|
|
|
if ( !exists $opts->{"template"} ) { |
48
|
0
|
|
|
|
|
|
die("You have to specify a template."); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $str = "-n $opts->{'name'} -t $opts->{'template'}"; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# BDEV Backing store type to use |
54
|
0
|
0
|
|
|
|
|
if ( exists $opts->{bdev} ) { |
55
|
0
|
|
|
|
|
|
$str .= " -B $opts->{bdev}"; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# -f, --config=CONFIG |
59
|
|
|
|
|
|
|
# Initial configuration file. |
60
|
0
|
0
|
|
|
|
|
if ( exists $opts->{config} ) { |
61
|
0
|
|
|
|
|
|
$str .= " -f $opts->{config}"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return $str; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |