diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index cc897f8d..ed0b6b23 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -14723,7 +14723,7 @@ sub read This reads a variable from the C<< variables >> table. Be sure to only use the reply from here to override what might have been set in a config file. This method always returns the data from the database itself. -The method returns an array reference containing, in order, the variable's value, database UUID and last modified date stamp in unix time (since epoch) and last as a normal time stamp. +The method returns an array reference containing, in order, the variable's value, variable UUID and last modified date stamp in unix time (since epoch) and last as a normal time stamp. If anything goes wrong, C<< !!error!! >> is returned. If the variable didn't exist in the database, an empty string will be returned for the UUID, value and modified date. diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index bfd8cbef..0e08089a 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -4823,6 +4823,8 @@ sub test_ipmi This uses the host list from C<< Get->trusted_hosts >>, along with data from C<< ip_addresses >>, to create a list of host name to IP addresses that should be in C<< /etc/hosts >>. Existing hosts where the IP has changed will be updated. Missing entries will be added. All other existing entries are left unchanged. +B<< Note >>: If C<< sys::hosts::manage >> is set to C<< 0 >>, this method will return without doing anything + This method takes no parameters. =cut @@ -4834,6 +4836,13 @@ sub update_hosts my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->update_hosts()" }}); + # Is managing hosts disabled? + if ((exists $anvil->data->{sys}{hosts}{manage}) && ($anvil->data->{sys}{hosts}{manage} eq "0")) + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0648"}); + return(0); + } + # Get the list of hosts we trust. my $trusted_host_uuids = $anvil->Get->trusted_hosts({debug => $debug}); $anvil->Database->get_ip_addresses({debug => $debug}); diff --git a/share/words.xml b/share/words.xml index 93f4ff27..5e521616 100644 --- a/share/words.xml +++ b/share/words.xml @@ -1897,6 +1897,7 @@ The file: [#!variable!file!#] needs to be updated. The difference is: Reloading corosync config. #!variable!program!# is disabled in anvil.conf. and '--force' was not used. Exiting. [ Note ] - The network interface: [#!variable!name!#] with 'network_interface_uuid': [#!variable!uuid!#] is a duplicate, removing it from the database(s). + [ Note ] - Managing /etc/hosts has been disabled. The host name: [#!variable!target!#] does not resolve to an IP address. @@ -2581,6 +2582,7 @@ If you are comfortable that the target has changed for a known reason, you can s This is the number of bytes received (rx) by a network interface since it was last started. This is the number of bytes transmitted (tx) by a network interface since it was last started. Stay Off + This is the command used to provision the referenced server. #!variable!number!#/sec @@ -2921,6 +2923,11 @@ We will sleep a bit and try again. + + + + + @@ -3078,6 +3085,8 @@ We will sleep a bit and try again. + + @@ -3106,12 +3115,16 @@ We will sleep a bit and try again. + + + + @@ -3125,6 +3138,7 @@ We will sleep a bit and try again. + @@ -3176,12 +3190,16 @@ We will sleep a bit and try again. + + + + @@ -3259,6 +3277,7 @@ We will sleep a bit and try again. + @@ -3353,6 +3372,8 @@ We will sleep a bit and try again. + + @@ -3428,6 +3449,9 @@ We will sleep a bit and try again. + + + @@ -3484,6 +3508,11 @@ We will sleep a bit and try again. + + + + + @@ -3549,6 +3578,7 @@ We will sleep a bit and try again. + @@ -3587,6 +3617,7 @@ We will sleep a bit and try again. + diff --git a/tools/anvil-provision-server b/tools/anvil-provision-server index efbbccb0..a999fe64 100755 --- a/tools/anvil-provision-server +++ b/tools/anvil-provision-server @@ -404,6 +404,33 @@ sub write_definition } } + # Lastly, if there's a variable recording the shell call used to provision this server, write it out. + my $server_uuid = $anvil->data->{servers}{anvil_uuid}{$anvil_uuid}{server_name}{$server_name}{server_uuid}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { server_uuid => $server_uuid }}); + my ($variable_value, $variable_uuid, $mtime, $modified_date) = $anvil->Database->read_variable({ + debug => 2, + variable_name => "server::provision_script", + variable_source_uuid => $server_uuid, + variable_source_table => "servers", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + variable_value => $variable_value, + variable_uuid => $variable_uuid, + }}); + if (($variable_value) && ($variable_value =~ /virt-install/gs)) + { + my $provision_file = $anvil->data->{path}{directories}{shared}{provision}."/".$server_name.".sh"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { provision_file => $provision_file }}); + my $problem = $anvil->Storage->write_file({ + overwrite => 1, + backup => 1, + file => $provision_file, + body => $variable_value, + mode => "0755", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); + } + # The peer is done, it'll pick up the XML definition when ScanCore runs $anvil->Job->update_progress({ progress => 100, @@ -433,6 +460,23 @@ sub provision_server ### Support disk images (ie: sysprep) via '--import'. The device used for booting is the first ### device specified via "--disk" ### Consider support for TPM, RNG and watchdog devices + my $server_uuid = $anvil->data->{job}{server_uuid} ? $anvil->data->{job}{server_uuid} : $anvil->Get->uuid(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + "job::os" => $anvil->data->{job}{os}, + server_uuid => $server_uuid, + }}); + my $disk_bus = ",target.bus=virtio"; + my $nic_model = ",model.type=virtio"; + if ($anvil->data->{job}{os} eq "win7") + { + $disk_bus = ""; + $nic_model = ",model.type=e1000e"; + } + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + disk_bus => $disk_bus, + nic_model => $nic_model, + }}); + my $shell_call = $anvil->data->{path}{exe}{'virt-install'}." --connect qemu:///system \\\n"; $shell_call .= "--name ".$server." \\\n"; $shell_call .= " --os-variant ".$anvil->data->{job}{os}." \\\n"; @@ -440,17 +484,14 @@ sub provision_server $shell_call .= " --events on_poweroff=destroy,on_reboot=restart \\\n"; $shell_call .= " --vcpus ".$anvil->data->{job}{cpu_cores}.",sockets=1,cores=".$anvil->data->{job}{cpu_cores}." \\\n"; $shell_call .= " --cpu host \\\n"; - $shell_call .= " --network bridge=ifn1_bridge1,model=virtio \\\n"; + $shell_call .= " --network bridge=ifn1_bridge1".$nic_model." \\\n"; $shell_call .= " --graphics vnc \\\n"; $shell_call .= " --sound ich9 \\\n"; $shell_call .= " --clock offset=".$clock_offset." \\\n"; # We may want to support ',rtc_tickpolicy=catchup' $shell_call .= " --boot menu=on \\\n"; - $shell_call .= " --disk path=/dev/drbd/by-res/".$server."/0,target.bus=virtio,driver.io=threads,cache=writeback,driver.discard=unmap,boot.order=1 \\\n"; + $shell_call .= " --disk path=/dev/drbd/by-res/".$server."/0".$disk_bus.",driver.io=threads,cache=writeback,driver.discard=unmap,boot.order=1 \\\n"; $shell_call .= " --disk path=".$anvil->data->{job}{install_iso_path}.",device=cdrom,shareable=on,boot.order=2 \\\n"; - if ($anvil->data->{job}{server_uuid}) - { - $shell_call .= " --uuid=".$anvil->data->{job}{server_uuid}." \\\n"; - } + $shell_call .= " --uuid=".$server_uuid." \\\n"; if ($anvil->data->{job}{driver_iso_path}) { $shell_call .= " --disk path=".$anvil->data->{job}{driver_iso_path}.",device=cdrom,shareable=on,boot.order=3 --force \\\n"; @@ -464,6 +505,30 @@ sub provision_server }); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 2, key => "job_0199", variables => { shell_call => $shell_call }}); + # Write the command out to /mnt/shared/provision/ + my $provision_file = $anvil->data->{path}{directories}{shared}{provision}."/".$server.".sh"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); + my $problem = $anvil->Storage->write_file({ + overwrite => 1, + backup => 1, + file => $provision_file, + body => $shell_call, + mode => "0755", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); + + # Also, record the provision command + my $variable_uuid = $anvil->Database->insert_or_update_variables({ + variable_name => "server::provision_script", + variable_value => $shell_call, + variable_default => "", + variable_description => "striker_0293", + variable_section => "servers", + variable_source_uuid => $server_uuid, + variable_source_table => "servers", + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { variable_uuid => $variable_uuid }}); + # Call as a background process. my ($handle, $return_code) = $anvil->System->call({ background => 1, @@ -546,7 +611,7 @@ sub provision_server return_code => $return_code, }}); - my $problem = $anvil->Server->parse_definition({ + $problem = $anvil->Server->parse_definition({ server => $server, source => "from_virsh", definition => $server_definition_xml, @@ -578,7 +643,6 @@ sub provision_server # Add the server to the 'servers' table my $anvil_uuid = $anvil->data->{job}{anvil_uuid}; my $short_host_name = $anvil->Get->short_host_name; - my $server_uuid = $anvil->data->{server}{$short_host_name}{$server}{"from_virsh"}{info}{uuid}; my $got_server_uuid = $anvil->Database->insert_or_update_servers({ server_uuid => $server_uuid, server_name => $server, @@ -1221,6 +1285,8 @@ sub parse_job_data if ($line =~ /os=(.*)$/) { $anvil->data->{job}{os} = $1; + $anvil->data->{job}{os} =~ s/^\s+//; + $anvil->data->{job}{os} =~ s/\s+?//; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'job::os' => $anvil->data->{job}{os} }}); } }