| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | my $opts = \%opt; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | $opts->{"name"} = $name; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 2 | ▶ | unless ($opts) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
not exists $_->{"template"} and $_->{"size"} and $_->{"type"} eq "file"
not exists $_->{"template"} and $_->{"size"}
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | my $size = $_->{'size'}; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | if ( !is_file( $_->{"file"} ) ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | die("You have to give a name."); | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | if ( !exists $opts->{"storage"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | die("You have to add at least one storage disk."); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | ▶ | if ( !exists $opts->{"type"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | ▶ | if ( exists $opts->{"os"} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
exists $opts->{"os"} and exists $opts->{"os"}{"kernel"} and not exists $hyper->{"kvm"}
exists $opts->{"os"} and exists $opts->{"os"}{"kernel"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | $opts->{"memory"} = 512 * 1024; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | ▶ | if ( !$opts->{"cpus"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | $opts->{"cpus"} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | ▶ | if ( !exists $opts->{"clock"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 2 | $opts->{"clock"} = "utc"; | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | ▶ | if ( !exists $opts->{"arch"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | ▶ | if ( exists $hyper->{"x86_64"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | $opts->{"boot"} = "hd"; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | ▶ | if ( !exists $opts->{"emulator"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | $opts->{"emulator"} = $hyper->{"emulator"}; | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | ▶ | if ( operating_system_is("Debian") && exists $hyper->{"xen"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
operating_system_is("Debian") and exists $hyper->{"xen"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%1/3
exists $hyper->{"loader"} and not exists $opts->{"loader"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $opts->{"loader"} = $hyper->{"loader"}; | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 2 | ▶ | if ( !exists $opts->{"on_poweroff"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 2 | $opts->{"on_poweroff"} = "destroy"; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | if ( !exists $opts->{"on_reboot"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | $opts->{"on_reboot"} = "restart"; | |||||||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 2 | ▶ | if ( !exists $opts->{"on_crash"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | $opts->{"on_crash"} = "restart"; | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | if ( exists $hyper->{"xen"} && $opts->{"type"} eq "pvm" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $hyper->{"xen"} and $opts->{"type"} eq "pvm"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if ( !exists $opts->{"os"}->{"type"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $opts->{"os"}->{"type"} = "linux"; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ( !exists $opts->{"os"}->{"kernel"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my %hw = Rex::Hardware->get(qw/ Kernel /); | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if ( is_redhat() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | my %hw = Rex::Hardware->get(qw/ Kernel /); | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | if ( is_redhat() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | ▶ | my @root_store = grep { $_->{"is_root"} && $_->{"is_root"} == 1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->{'is_root'} && $_->{'is_root'} == 1
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 2 | $store->{"type"} = "file"; | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 2 | ▶ | if ( !exists $store->{"driver_type"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1 | $store->{"driver_type"} = "raw"; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 2 | ▶ | if ( !exists $store->{"size"} && $store->{"type"} eq "file" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $store->{"size"} and $store->{"type"} eq "file"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 2 | ▶ | if ( $store->{"file"} =~ m/swap/ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition33%2/6
exists $store->{"file"} and $store->{"file"} =~ /\.iso$/u and not exists $store->{"device"}
exists $store->{"file"} and $store->{"file"} =~ /\.iso$/u
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | $store->{"device"} = "disk"; | |||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | ▶ | if ( !exists $store->{"dev"} && $store->{"device"} eq "cdrom" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not exists $store->{"dev"} and $store->{"device"} eq "cdrom"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $store->{"dev"} = "hdc"; | |||||||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | ▶ | if ( !exists $store->{"dev"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | ▶ | if ( exists $hyper->{"kvm"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 2 | ▶ | if ( exists $hyper->{"kvm"} && $store->{"device"} eq "disk" ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $hyper->{"kvm"} and $store->{"device"} eq "disk"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | ▶ | if ( $store->{"bus"} eq "virtio" && !exists $store->{"address"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$store->{"bus"} eq "virtio" and not exists $store->{"address"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $store->{"readonly"} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 2 | ▶ | if ( is_redhat() ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | ▶ | if ( !exists $store->{"aio"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $netdev->{"type"} = "bridge"; | |||||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 2 | ▶ | if ( !exists $netdev->{"bridge"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | $netdev->{"bridge"} = "virbr0"; | |||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 2 | ▶ | if ( exists $hyper->{"kvm"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 2 | ▶ | if ( !exists $netdev->{"model"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 2 | $netdev->{"model"} = "virtio"; | |||||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 2 | ▶ | if ( !exists $netdev->{"address"} ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||