lib/Rex/Virtualization/LibVirt/create.pm

filter: Statementstmt 75.5% 151 / 200 Branchbran 41.3% 48 / 116 Conditioncond 27.0% 13 / 48 MC/DCmcdc 0.0% 0 / 29 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 1 totaltotal 55.9% 231 / 413 CC 76 SCAR 45.5
CC
76
Cov
58%
_set_defaults
184.3
_set_storage_defaults
107.7
execute
34.0
CRAP 95.0
« lib/Rex/Resource/firewall.pm ↑ Summary lib/Rex/Virtualization/LibVirt/blklist.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Virtualization::LibVirt::create;
6  
7 2 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '1.16.1'; # VERSION
11  
12 2 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Rex::Commands::Gather;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Rex::Hardware;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 2 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Rex::Commands::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Rex::Commands::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Rex::File::Parser::Data;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Rex::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Rex::Helper::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use XML::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use Rex::Virtualization::LibVirt::hypervisor;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 2 my $QEMU_IMG;
29 2 ▶if ( can_run("qemu-img") ) {
Branch: 2 branches
BranchTrueFalseTotal
if (can_run('qemu-img')) { } 1 1 2
elsif (can_run('qemu-img-xen')) { } 0 1 1
30 1 $QEMU_IMG = "qemu-img";
31 }
32 elsif ( can_run("qemu-img-xen") ) {
33 0 $QEMU_IMG = "qemu-img-xen";
34 }
35  
36 # read __DATA__ into an array
37 2 my @data = <DATA>;
38  
39 2 ▶sub execute {
Subroutine execute: called CC=15 SCAR=35.2
Pod undocumented
40 2 my ( $class, $name, %opt ) = @_;
41 2 my $virt_settings = Rex::Config->get("virtualization");
42 chomp( my $uri =
43 2 ▶ ref($virt_settings) ? $virt_settings->{connect} : i_run "virsh uri" );
Branch: 1 branch
BranchTrueFalseTotal
ref $virt_settings ? : 0 2 2
44  
45 2 my $opts = \%opt;
46 2 $opts->{"name"} = $name;
47  
48 2 ▶ unless ($opts) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts) 0 2 2
49 0 die("You have to define the create options!");
50 }
51  
52 ## detect the hypervisor caps
53 2 my $hypervisor =
54 Rex::Virtualization::LibVirt::hypervisor->execute('capabilities');
55 2 my $virt_type = "unknown";
56  
57 2 _set_defaults( $opts, $hypervisor );
58  
59 2 ▶ if ( exists $hypervisor->{"kvm"} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $hypervisor->{'kvm'}) { } 2 0 2
elsif (exists $hypervisor->{'xen'}) { } 0 0 0
60 2 $virt_type = "kvm";
61 }
62 elsif ( exists $hypervisor->{"xen"} ) {
63 0 $virt_type = "xen-" . $opts->{"type"};
64 }
65 else {
66 0 die("Hypervisor not supported.");
67 }
68  
69 2 my $fp = Rex::File::Parser::Data->new( data => \@data );
70 2 my $create_xml = $fp->read("create-${virt_type}.xml");
71  
72 2 my $template = Rex::Template->new;
73 2 my $parsed_template = $template->parse( $create_xml, $opts );
74  
75 2 Rex::Logger::debug($parsed_template);
76  
77 ## create storage devices
78 2 for ( @{ $opts->{'storage'} } ) {
79  
80 2 ▶ if ( !exists $_->{"template"} && $_->{"size"} && $_->{"type"} eq "file" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not exists $_->{'template'} and $_->{'size'} and $_->{'type'} eq 'file') { } 2 0 2
elsif ($_->{'template'} and $_->{'type'} eq 'file') { } 0 0 0
Condition33%2/6
not exists $_->{"template"} and $_->{"size"} and $_->{"type"} eq "file"
!ll&&!rl&&r
002
not exists $_->{"template"} and $_->{"size"}
!ll&&!rl&&r
002
MC/DC0%0/3
not exists $_->{"template"} and $_->{"size"} and $_->{"type"} eq "file"
not exists $_->{"template"} $_->{"size"} $_->{"type"} eq "file"
Truth table25%1/4
not(A) and B and C
A= not exists $_->{"template"}B= $_->{"size"}C= $_->{"type"} eq "file"
ABCresult
0XX0
10X0
1100
1111
81 2 my $size = $_->{'size'};
82 2 ▶ if ( !is_file( $_->{"file"} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not is_file($_->{'file'})) { } 2 0 2
83 2 Rex::Logger::debug("creating storage disk: \"$_->{file}\"");
84 2 i_run "$QEMU_IMG create -f $_->{driver_type} '$_->{file}' $size",
85 fail_ok => 1;
86 2 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 2 2
87 0 die("Error creating storage disk: $_->{'file'}");
88 }
89 }
90 else {
91 0 Rex::Logger::info("$_->{file} already exists. Using this.");
92 }
93 }
94 ▶ elsif ( $_->{'template'} && $_->{'type'} eq "file" ) {
Condition0%0/3
$_->{"template"} and $_->{"type"} eq "file"
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{"template"} and $_->{"type"} eq "file"
$_->{"template"} $_->{"type"} eq "file"
Truth table0%0/3
A and B
A= $_->{"template"}B= $_->{"type"} eq "file"
ABresult
0X0
100
111
95 0 Rex::Logger::info(
96 "building domain: \"$opts->{'name'}\" from template: \"$_->{'template'}\""
97 );
98 0 Rex::Logger::info("Please wait ...");
99 0 i_run
100 "$QEMU_IMG convert -f raw '$_->{template}' -O '$_->{driver_type}' '$_->{file}'",
101 fail_ok => 1;
102 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
103 0 die(
104 "Error building domain: \"$opts->{'name'}\" from template: \"$_->{'template'}\"\n
105 Template doesn't exist or the qemu-img binary is missing"
106 );
107 }
108 }
109 else {
110 0 Rex::Logger::info("$_->{file} already exists. Using this.");
111 }
112 }
113  
114 2 Rex::Logger::info("Creating domain: \"$opts->{'name'}\"");
115  
116 2 $parsed_template =~ s/[\n\r]//gms;
117  
118 2 my $file_name = get_tmp_file;
119  
120 2 file "$file_name", content => $parsed_template;
121  
122 2 i_run "virsh -c $uri define '$file_name'", fail_ok => 1;
123 2 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 2 2
124 0 die("Error defining vm $opts->{name}");
125 }
126 2 unlink($file_name);
127  
128 2 return;
129 }
130  
131 2 ▶sub _set_defaults {
Subroutine _set_defaults: called CC=30 SCAR=52.2
132 2 my ( $opts, $hyper ) = @_;
133  
134 2 ▶ if ( !exists $opts->{"name"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"name"}) 0 2 2
135 0 die("You have to give a name.");
136 }
137  
138 2 ▶ if ( !exists $opts->{"storage"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"storage"}) 0 2 2
139 0 die("You have to add at least one storage disk.");
140 }
141  
142 2 ▶ if ( !exists $opts->{"type"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"type"}) 2 0 2
143  
144 2 ▶ if ( exists $opts->{"os"}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{'os'} and exists $opts->{'os'}{'kernel'} and not exists $hyper->{'kvm'}) { } 0 2 2
Condition33%2/6
exists $opts->{"os"} and exists $opts->{"os"}{"kernel"} and not exists $hyper->{"kvm"}
!ll&&!rl&&r
200
exists $opts->{"os"} and exists $opts->{"os"}{"kernel"}
!ll&&!rl&&r
200
MC/DC0%0/3
exists $opts->{"os"} and exists $opts->{"os"}{"kernel"} and not exists $hyper->{"kvm"}
exists $opts->{"os"} exists $opts->{"os"}{"kernel"} not exists $hyper->{"kvm"}
Truth table25%1/4
A and B and not(C)
A= exists $opts->{"os"}B= exists $opts->{"os"}{"kernel"}C= not exists $hyper->{"kvm"}
ABCresult
0XX0
10X0
1100
1111
145 && exists $opts->{"os"}->{"kernel"}
146 && !exists $hyper->{"kvm"} )
147 {
148 0 $opts->{"type"} = "pvm";
149 }
150 else {
151 2 $opts->{"type"} = "hvm";
152 }
153  
154 }
155  
156 2 ▶ if ( !$opts->{"memory"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"memory"}) 2 0 2
157 2 $opts->{"memory"} = 512 * 1024;
158 }
159  
160 2 ▶ if ( !$opts->{"cpus"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($opts->{"cpus"}) 2 0 2
161 2 $opts->{"cpus"} = 1;
162 }
163  
164 2 ▶ if ( !exists $opts->{"clock"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"clock"}) 2 0 2
165 2 $opts->{"clock"} = "utc";
166 }
167  
168 2 ▶ if ( !exists $opts->{"arch"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"arch"}) 2 0 2
169 2 ▶ if ( exists $hyper->{"x86_64"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hyper->{'x86_64'}) { } 2 0 2
170 2 $opts->{"arch"} = "x86_64";
171 }
172 else {
173 0 $opts->{"arch"} = "i686";
174 }
175 }
176  
177 2 ▶ if ( !exists $opts->{"boot"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"boot"}) 2 0 2
178 2 $opts->{"boot"} = "hd";
179 }
180  
181 2 ▶ if ( !exists $opts->{"emulator"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"emulator"}) 2 0 2
182 2 $opts->{"emulator"} = $hyper->{"emulator"};
183  
184 2 ▶ if ( operating_system_is("Debian") && exists $hyper->{"xen"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (operating_system_is("Debian") and exists $hyper->{"xen"}) 0 2 2
Condition33%1/3
operating_system_is("Debian") and exists $hyper->{"xen"}
!ll&&!rl&&r
020
MC/DC0%0/2
operating_system_is("Debian") and exists $hyper->{"xen"}
operating_system_is("Debian") exists $hyper->{"xen"}
Truth table33%1/3
A and B
A= operating_system_is("Debian")B= exists $hyper->{"xen"}
ABresult
0X0
100
111
185  
186 # fix for debian, because virsh capabilities don't give the correct
187 # emulator.
188 0 $opts->{"emulator"} = "/usr/lib/xen-4.0/bin/qemu-dm";
189 }
190  
191 }
192  
193 2 ▶ if ( exists $hyper->{"loader"} && !exists $opts->{"loader"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hyper->{"loader"} and not exists $opts->{"loader"}) 0 2 2
Condition33%1/3
exists $hyper->{"loader"} and not exists $opts->{"loader"}
!ll&&!rl&&r
200
MC/DC0%0/2
exists $hyper->{"loader"} and not exists $opts->{"loader"}
exists $hyper->{"loader"} not exists $opts->{"loader"}
Truth table33%1/3
A and not(B)
A= exists $hyper->{"loader"}B= not exists $opts->{"loader"}
ABresult
0X0
100
111
194 0 $opts->{"loader"} = $hyper->{"loader"};
195 }
196  
197 2 ▶ if ( !exists $opts->{"on_poweroff"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"on_poweroff"}) 2 0 2
198 2 $opts->{"on_poweroff"} = "destroy";
199 }
200  
201 2 ▶ if ( !exists $opts->{"on_reboot"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"on_reboot"}) 2 0 2
202 2 $opts->{"on_reboot"} = "restart";
203 }
204  
205 2 ▶ if ( !exists $opts->{"on_crash"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"on_crash"}) 2 0 2
206 2 $opts->{"on_crash"} = "restart";
207 }
208  
209 2 ▶ if ( exists $hyper->{"xen"} && $opts->{"type"} eq "pvm" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hyper->{"xen"} and $opts->{"type"} eq "pvm") 0 2 2
Condition33%1/3
exists $hyper->{"xen"} and $opts->{"type"} eq "pvm"
!ll&&!rl&&r
200
MC/DC0%0/2
exists $hyper->{"xen"} and $opts->{"type"} eq "pvm"
exists $hyper->{"xen"} $opts->{"type"} eq "pvm"
Truth table33%1/3
A and B
A= exists $hyper->{"xen"}B= $opts->{"type"} eq "pvm"
ABresult
0X0
100
111
210  
211 0 ▶ if ( !exists $opts->{"os"}->{"type"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"os"}{"type"}) 0 0 0
212 0 $opts->{"os"}->{"type"} = "linux";
213 }
214  
215 0 ▶ if ( !exists $opts->{"os"}->{"kernel"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"os"}{"kernel"}) 0 0 0
216 0 my %hw = Rex::Hardware->get(qw/ Kernel /);
217  
218 0 ▶ if ( is_redhat() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_redhat()) { } 0 0 0
219 $opts->{"os"}->{"kernel"} =
220 0 "/boot/vmlinuz-" . $hw{"Kernel"}->{"kernelrelease"};
221 }
222 else {
223 $opts->{"os"}->{"kernel"} =
224 0 "/boot/vmlinuz-" . $hw{"Kernel"}->{"kernelrelease"};
225 }
226 }
227  
228 0 ▶ if ( !exists $opts->{"os"}->{"initrd"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"os"}{"initrd"}) 0 0 0
229 0 my %hw = Rex::Hardware->get(qw/ Kernel /);
230  
231 0 ▶ if ( is_redhat() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_redhat()) { } 0 0 0
232 $opts->{"os"}->{"initrd"} =
233 0 "/boot/initrd-" . $hw{"Kernel"}->{"kernelrelease"} . ".img";
234 }
235 else {
236 $opts->{"os"}->{"initrd"} =
237 0 "/boot/initrd.img-" . $hw{"Kernel"}->{"kernelrelease"};
238 }
239 }
240  
241 0 ▶ if ( !exists $opts->{"os"}->{"cmdline"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"os"}{"cmdline"}) 0 0 0
242 0 ▶ my @root_store = grep { $_->{"is_root"} && $_->{"is_root"} == 1 }
Condition0%0/3
$_->{'is_root'} && $_->{'is_root'} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{'is_root'} && $_->{'is_root'} == 1
$_->{'is_root'} $_->{'is_root'} == 1
Truth table0%0/3
A && B
A= $_->{'is_root'}B= $_->{'is_root'} == 1
ABresult
0X0
100
111
243 0 @{ $opts->{"storage"} };
244 $opts->{"os"}->{"cmdline"} =
245 0 "root=/dev/" . $root_store[0]->{"dev"} . " ro";
246 }
247  
248 }
249  
250 2 _set_storage_defaults( $opts, $hyper );
251  
252 2 _set_network_defaults( $opts, $hyper );
253  
254 }
255  
256 2 ▶sub _set_storage_defaults {
Subroutine _set_storage_defaults: called CC=26 SCAR=46.8
257 2 my ( $opts, $hyper ) = @_;
258  
259 2 my $store_letter = "a";
260 2 for my $store ( @{ $opts->{"storage"} } ) {
261  
262 2 ▶ if ( !exists $store->{"type"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $store->{"type"}) 2 0 2
263 2 $store->{"type"} = "file";
264 }
265  
266 2 ▶ if ( !exists $store->{"driver_type"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $store->{"driver_type"}) 1 1 2
267 1 $store->{"driver_type"} = "raw";
268 }
269  
270 2 ▶ if ( !exists $store->{"size"} && $store->{"type"} eq "file" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $store->{"size"} and $store->{"type"} eq "file") 2 0 2
Condition33%1/3
not exists $store->{"size"} and $store->{"type"} eq "file"
!ll&&!rl&&r
002
MC/DC0%0/2
not exists $store->{"size"} and $store->{"type"} eq "file"
not exists $store->{"size"} $store->{"type"} eq "file"
Truth table33%1/3
not(A) and B
A= not exists $store->{"size"}B= $store->{"type"} eq "file"
ABresult
0X0
100
111
271  
272 2 ▶ if ( $store->{"file"} =~ m/swap/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($store->{'file'} =~ /swap/u) { } 0 2 2
273 0 $store->{"size"} = "1G";
274 }
275 else {
276 2 $store->{"size"} = "10G";
277 }
278  
279 }
280  
281 2 ▶ if ( exists $store->{"file"}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $store->{"file"} and $store->{"file"} =~ /\.iso$/u and not exists $store->{"device"}) 0 2 2
Condition33%2/6
exists $store->{"file"} and $store->{"file"} =~ /\.iso$/u and not exists $store->{"device"}
!ll&&!rl&&r
200
exists $store->{"file"} and $store->{"file"} =~ /\.iso$/u
!ll&&!rl&&r
020
MC/DC0%0/3
exists $store->{"file"} and $store->{"file"} =~ /\.iso$/u and not exists $store->{"device"}
exists $store->{"file"} $store->{"file"} =~ /\.iso$/u not exists $store->{"device"}
Truth table25%1/4
A and B and not(C)
A= exists $store->{"file"}B= $store->{"file"} =~ /\.iso$/uC= not exists $store->{"device"}
ABCresult
0XX0
10X0
1100
1111
282 && $store->{"file"} =~ m/\.iso$/
283 && !exists $store->{"device"} )
284 {
285 0 $store->{"device"} = "cdrom";
286 }
287  
288 2 ▶ if ( !exists $store->{"device"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $store->{"device"}) 2 0 2
289 2 $store->{"device"} = "disk";
290 }
291  
292 2 ▶ if ( !exists $store->{"dev"} && $store->{"device"} eq "cdrom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $store->{"dev"} and $store->{"device"} eq "cdrom") 0 2 2
Condition33%1/3
not exists $store->{"dev"} and $store->{"device"} eq "cdrom"
!ll&&!rl&&r
200
MC/DC0%0/2
not exists $store->{"dev"} and $store->{"device"} eq "cdrom"
not exists $store->{"dev"} $store->{"device"} eq "cdrom"
Truth table33%1/3
not(A) and B
A= not exists $store->{"dev"}B= $store->{"device"} eq "cdrom"
ABresult
0X0
100
111
293 0 $store->{"dev"} = "hdc";
294 }
295  
296 2 ▶ if ( !exists $store->{"dev"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $store->{"dev"}) 0 2 2
297  
298 0 ▶ if ( exists $hyper->{"kvm"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hyper->{'kvm'}) { } 0 0 0
299 0 $store->{"dev"} = "vd${store_letter}";
300 }
301 else {
302 0 $store->{"dev"} = "hd${store_letter}";
303 }
304  
305 }
306  
307 2 ▶ if ( !exists $store->{"bus"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $store->{"bus"}) 2 0 2
308  
309 2 ▶ if ( exists $hyper->{"kvm"} && $store->{"device"} eq "disk" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hyper->{'kvm'} and $store->{'device'} eq 'disk') { } 2 0 2
Condition33%1/3
exists $hyper->{"kvm"} and $store->{"device"} eq "disk"
!ll&&!rl&&r
002
MC/DC0%0/2
exists $hyper->{"kvm"} and $store->{"device"} eq "disk"
exists $hyper->{"kvm"} $store->{"device"} eq "disk"
Truth table33%1/3
A and B
A= exists $hyper->{"kvm"}B= $store->{"device"} eq "disk"
ABresult
0X0
100
111
310 2 $store->{"bus"} = "virtio";
311 }
312 else {
313 0 $store->{"bus"} = "ide";
314 }
315  
316 }
317  
318 2 ▶ if ( exists $hyper->{"kvm"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hyper->{"kvm"}) 2 0 2
319  
320 2 ▶ if ( $store->{"bus"} eq "virtio" && !exists $store->{"address"} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($store->{'bus'} eq 'virtio' and not exists $store->{'address'}) { } 2 0 2
elsif ($store->{'bus'} eq 'ide' and not exists $store->{'address'}) { } 0 0 0
Condition33%1/3
$store->{"bus"} eq "virtio" and not exists $store->{"address"}
!ll&&!rl&&r
002
MC/DC0%0/2
$store->{"bus"} eq "virtio" and not exists $store->{"address"}
$store->{"bus"} eq "virtio" not exists $store->{"address"}
Truth table33%1/3
A and not(B)
A= $store->{"bus"} eq "virtio"B= not exists $store->{"address"}
ABresult
0X0
100
111
321 2 $store->{"address"} = {
322 type => "pci",
323 domain => "0x0000",
324 bus => "0x00",
325 slot => "0x05",
326 function => "0x0",
327 };
328 }
329 ▶ elsif ( $store->{"bus"} eq "ide" && !exists $store->{"address"} ) {
Condition0%0/3
$store->{"bus"} eq "ide" and not exists $store->{"address"}
!ll&&!rl&&r
000
MC/DC0%0/2
$store->{"bus"} eq "ide" and not exists $store->{"address"}
$store->{"bus"} eq "ide" not exists $store->{"address"}
Truth table0%0/3
A and not(B)
A= $store->{"bus"} eq "ide"B= not exists $store->{"address"}
ABresult
0X0
100
111
330 0 $store->{"address"} = {
331 type => "drive",
332 controller => 0,
333 bus => 1,
334 unit => 0,
335 };
336 }
337  
338 }
339  
340 2 ▶ if ( $store->{"device"} eq "cdrom" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($store->{"device"} eq "cdrom") 0 2 2
341 0 $store->{"readonly"} = 1;
342 }
343  
344 2 ▶ if ( is_redhat() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_redhat()) 0 2 2
345  
346 0 ▶ if ( !exists $store->{"aio"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $store->{"aio"}) 0 0 0
347 0 $store->{"aio"} = 1;
348 }
349  
350 }
351  
352 2 $store_letter++;
353  
354 }
355  
356 }
357  
358 2 ▶sub _set_network_defaults {
Subroutine _set_network_defaults: called CC=8 SCAR=22.5
359 2 my ( $opts, $hyper ) = @_;
360  
361 2 ▶ if ( !exists $opts->{"network"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $opts->{"network"}) 2 0 2
362 2 $opts->{"network"} = [
363 {
364 type => "bridge",
365 bridge => "virbr0",
366 },
367 ];
368 }
369  
370 2 my $slot = 10;
371  
372 2 for my $netdev ( @{ $opts->{"network"} } ) {
373  
374 2 ▶ if ( !exists $netdev->{"type"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $netdev->{"type"}) 0 2 2
375  
376 0 $netdev->{"type"} = "bridge";
377  
378 }
379  
380 2 ▶ if ( !exists $netdev->{"bridge"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $netdev->{"bridge"}) 0 2 2
381  
382 0 $netdev->{"bridge"} = "virbr0";
383  
384 }
385  
386 2 ▶ if ( exists $hyper->{"kvm"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hyper->{"kvm"}) 2 0 2
387  
388 2 ▶ if ( !exists $netdev->{"model"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $netdev->{"model"}) 2 0 2
389  
390 2 $netdev->{"model"} = "virtio";
391  
392 }
393  
394 2 ▶ if ( !exists $netdev->{"address"} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $netdev->{"address"}) 2 0 2
395  
396 2 $netdev->{"address"} = {
397 type => "pci",
398 domain => "0x0000",
399 bus => "0x00",
400 slot => "0x" . sprintf( '%02i', $slot ),
401 function => "0x0",
402 };
403  
404 2 $slot++;
405  
406 }
407  
408 }
409  
410 }
411 }
412  
413 2 1;
414  
415 __DATA__
« lib/Rex/Resource/firewall.pm ↑ Summary lib/Rex/Virtualization/LibVirt/blklist.pm »