Merge pull request #185 from ClusterLabs/anvil-tools-dev

Anvil tools dev
main
Digimer 3 years ago committed by GitHub
commit 61d4eb7d7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      Anvil/Tools/Database.pm
  2. 9
      Anvil/Tools/System.pm
  3. 31
      share/words.xml
  4. 82
      tools/anvil-provision-server

@ -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.

@ -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});

@ -1897,6 +1897,7 @@ The file: [#!variable!file!#] needs to be updated. The difference is:
<key name="log_0645">Reloading corosync config.</key>
<key name="log_0646">#!variable!program!# is disabled in anvil.conf. and '--force' was not used. Exiting.</key>
<key name="log_0647">[ Note ] - The network interface: [#!variable!name!#] with 'network_interface_uuid': [#!variable!uuid!#] is a duplicate, removing it from the database(s).</key>
<key name="log_0648">[ Note ] - Managing /etc/hosts has been disabled.</key>
<!-- Messages for users (less technical than log entries), though sometimes used for logs, too. -->
<key name="message_0001">The host name: [#!variable!target!#] does not resolve to an IP address.</key>
@ -2581,6 +2582,7 @@ If you are comfortable that the target has changed for a known reason, you can s
<key name="striker_0290">This is the number of bytes received (rx) by a network interface since it was last started.</key>
<key name="striker_0291">This is the number of bytes transmitted (tx) by a network interface since it was last started.</key>
<key name="striker_0292">Stay Off</key>
<key name="striker_0293">This is the command used to provision the referenced server.</key>
<!-- These are generally units and appended to numbers -->
<key name="suffix_0001">#!variable!number!#/sec</key>
@ -2921,6 +2923,11 @@ We will sleep a bit and try again.
<key name="os_list_alpinelinux3.6"><![CDATA[Alpine Linux 3.6]]></key>
<key name="os_list_alpinelinux3.7"><![CDATA[Alpine Linux 3.7]]></key>
<key name="os_list_alpinelinux3.8"><![CDATA[Alpine Linux 3.8]]></key>
<key name="os_list_alpinelinux3.9"><![CDATA[Alpine Linux 3.9]]></key>
<key name="os_list_alpinelinux3.10"><![CDATA[Alpine Linux 3.10]]></key>
<key name="os_list_alpinelinux3.11"><![CDATA[Alpine Linux 3.11]]></key>
<key name="os_list_alpinelinux3.12"><![CDATA[Alpine Linux 3.12]]></key>
<key name="os_list_alpinelinux3.13"><![CDATA[Alpine Linux 3.13]]></key>
<key name="os_list_alt.p8"><![CDATA[ALT p8 StarterKits]]></key>
<key name="os_list_alt.p9"><![CDATA[ALT p9 StarterKits]]></key>
<key name="os_list_alt.sisyphus"><![CDATA[ALT regular]]></key>
@ -3078,6 +3085,8 @@ We will sleep a bit and try again.
<key name="os_list_eos3.6"><![CDATA[Endless OS 3.6]]></key>
<key name="os_list_eos3.7"><![CDATA[Endless OS 3.7]]></key>
<key name="os_list_eos3.8"><![CDATA[Endless OS 3.8]]></key>
<key name="os_list_eos3.9"><![CDATA[Endless OS 3.9]]></key>
<key name="os_list_eos3.10"><![CDATA[Endless OS 3.10]]></key>
<key name="os_list_fedora-rawhide"><![CDATA[Fedora Rawhide]]></key>
<key name="os_list_fedora-unknown"><![CDATA[Fedora]]></key>
<key name="os_list_fedora1"><![CDATA[Fedora Core 1]]></key>
@ -3106,12 +3115,16 @@ We will sleep a bit and try again.
<key name="os_list_fedora30"><![CDATA[Fedora 30]]></key>
<key name="os_list_fedora31"><![CDATA[Fedora 31]]></key>
<key name="os_list_fedora32"><![CDATA[Fedora 32]]></key>
<key name="os_list_fedora33"><![CDATA[Fedora 33]]></key>
<key name="os_list_fedora4"><![CDATA[Fedora Core 4]]></key>
<key name="os_list_fedora5"><![CDATA[Fedora Core 5]]></key>
<key name="os_list_fedora6"><![CDATA[Fedora Core 6]]></key>
<key name="os_list_fedora7"><![CDATA[Fedora 7]]></key>
<key name="os_list_fedora8"><![CDATA[Fedora 8]]></key>
<key name="os_list_fedora9"><![CDATA[Fedora 9]]></key>
<key name="os_list_fedora-coreos-next"><![CDATA[Fedora CoreOS]]></key>
<key name="os_list_fedora-coreos-stable"><![CDATA[Fedora CoreOS]]></key>
<key name="os_list_fedora-coreos-testing"><![CDATA[Fedora CoreOS]]></key>
<key name="os_list_freebsd1.0"><![CDATA[FreeBSD 1.0]]></key>
<key name="os_list_freebsd10.0"><![CDATA[FreeBSD 10.0]]></key>
<key name="os_list_freebsd10.1"><![CDATA[FreeBSD 10.1]]></key>
@ -3125,6 +3138,7 @@ We will sleep a bit and try again.
<key name="os_list_freebsd11.4"><![CDATA[FreeBSD 11.4]]></key>
<key name="os_list_freebsd12.0"><![CDATA[FreeBSD 12.0]]></key>
<key name="os_list_freebsd12.1"><![CDATA[FreeBSD 12.1]]></key>
<key name="os_list_freebsd12.2"><![CDATA[FreeBSD 12.2]]></key>
<key name="os_list_freebsd2.0"><![CDATA[FreeBSD 2.0]]></key>
<key name="os_list_freebsd2.0.5"><![CDATA[FreeBSD 2.0.5]]></key>
<key name="os_list_freebsd2.2.8"><![CDATA[FreeBSD 2.2.8]]></key>
@ -3176,12 +3190,16 @@ We will sleep a bit and try again.
<key name="os_list_gnome-continuous-3.14"><![CDATA[GNOME 3.14]]></key>
<key name="os_list_gnome3.6"><![CDATA[GNOME 3.6]]></key>
<key name="os_list_gnome3.8"><![CDATA[GNOME 3.8]]></key>
<key name="os_list_guix-1.1"><![CDATA[Guix 1.1]]></key>
<key name="os_list_haikunightly"><![CDATA[Haiku Nightly]]></key>
<key name="os_list_haikur1alpha1"><![CDATA[Haiku R1/Alpha1]]></key>
<key name="os_list_haikur1alpha2"><![CDATA[Haiku R1/Alpha2]]></key>
<key name="os_list_haikur1alpha3"><![CDATA[Haiku R1/Alpha3]]></key>
<key name="os_list_haikur1alpha4.1"><![CDATA[Haiku R1/Alpha4.1]]></key>
<key name="os_list_haikur1beta1"><![CDATA[Haiku R1/Beta1]]></key>
<key name="os_list_linux2016"><![CDATA[Generic Linux 2016]]></key>
<key name="os_list_linux2018"><![CDATA[Generic Linux 2018]]></key>
<key name="os_list_linux2020"><![CDATA[Generic Linux 2020]]></key>
<key name="os_list_macosx10.0"><![CDATA[MacOS X Cheetah]]></key>
<key name="os_list_macosx10.1"><![CDATA[MacOS X Puma]]></key>
<key name="os_list_macosx10.2"><![CDATA[MacOS X Jaguar]]></key>
@ -3259,6 +3277,7 @@ We will sleep a bit and try again.
<key name="os_list_netware5"><![CDATA[Novell Netware 5]]></key>
<key name="os_list_netware6"><![CDATA[Novell Netware 6]]></key>
<key name="os_list_nixos-20.03"><![CDATA[NixOS 20.03]]></key>
<key name="os_list_nixos-20.09"><![CDATA[NixOS 20.09]]></key>
<key name="os_list_nixos-unknown"><![CDATA[NixOS]]></key>
<key name="os_list_nixos-unstable"><![CDATA[NixOS Unstable]]></key>
<key name="os_list_oel4.4"><![CDATA[Oracle Enterprise Linux 4.4]]></key>
@ -3353,6 +3372,8 @@ We will sleep a bit and try again.
<key name="os_list_popos18.10"><![CDATA[Pop!_OS 18.10]]></key>
<key name="os_list_popos19.04"><![CDATA[Pop!_OS 19.04]]></key>
<key name="os_list_popos19.10"><![CDATA[Pop!_OS 19.10]]></key>
<key name="os_list_popos20.04"><![CDATA[Pop!_OS 20.04]]></key>
<key name="os_list_popos20.10"><![CDATA[Pop!_OS 20.10]]></key>
<key name="os_list_pureos8"><![CDATA[PureOS]]></key>
<key name="os_list_rhel-atomic-7.0"><![CDATA[Red Hat Enterprise Linux Atomic Host 7.0]]></key>
<key name="os_list_rhel-atomic-7.1"><![CDATA[Red Hat Enterprise Linux Atomic Host 7.1]]></key>
@ -3428,6 +3449,9 @@ We will sleep a bit and try again.
<key name="os_list_rhel8.1"><![CDATA[Red Hat Enterprise Linux 8.1]]></key>
<key name="os_list_rhel8.2"><![CDATA[Red Hat Enterprise Linux 8.2]]></key>
<key name="os_list_rhel8.3"><![CDATA[Red Hat Enterprise Linux 8.3]]></key>
<key name="os_list_rhel8.4"><![CDATA[Red Hat Enterprise Linux 8.4]]></key>
<key name="os_list_rhel9-unknown"><![CDATA[Red Hat Enterprise Linux 9 Unknown]]></key>
<key name="os_list_rhel9.0"><![CDATA[Red Hat Enterprise Linux 9.0]]></key>
<key name="os_list_rhl1.0"><![CDATA[Red Hat Linux 1.0]]></key>
<key name="os_list_rhl1.1"><![CDATA[Red Hat Linux 1.1]]></key>
<key name="os_list_rhl2.0"><![CDATA[Red Hat Linux 2.0]]></key>
@ -3484,6 +3508,11 @@ We will sleep a bit and try again.
<key name="os_list_silverblue30"><![CDATA[Fedora Silverblue 30]]></key>
<key name="os_list_silverblue31"><![CDATA[Fedora Silverblue 31]]></key>
<key name="os_list_silverblue32"><![CDATA[Fedora Silverblue 32]]></key>
<key name="os_list_silverblue-rawhide"><![CDATA[Fedora Silverblue Rawhide]]></key>
<key name="os_list_silverblue-unknown"><![CDATA[Fedora Silverblue]]></key>
<key name="os_list_silverblue33"><![CDATA[Fedora Silverblue 33]]></key>
<key name="os_list_slackware-current"><![CDATA[Slackware -current]]></key>
<key name="os_list_slackware14.2"><![CDATA[Slackware 14.2]]></key>
<key name="os_list_sle-unknown"><![CDATA[SUSE Linux Enterprise Unknown]]></key>
<key name="os_list_sle15"><![CDATA[SUSE Linux Enterprise 15]]></key>
<key name="os_list_sle15-unknown"><![CDATA[SUSE Linux Enterprise 15 Unknown]]></key>
@ -3549,6 +3578,7 @@ We will sleep a bit and try again.
<key name="os_list_ubuntu19.04"><![CDATA[Ubuntu 19.04]]></key>
<key name="os_list_ubuntu19.10"><![CDATA[Ubuntu 19.10]]></key>
<key name="os_list_ubuntu20.04"><![CDATA[Ubuntu 20.04]]></key>
<key name="os_list_ubuntu20.10"><![CDATA[Ubuntu 20.10]]></key>
<key name="os_list_ubuntu4.10"><![CDATA[Ubuntu 4.10]]></key>
<key name="os_list_ubuntu5.04"><![CDATA[Ubuntu 5.04]]></key>
<key name="os_list_ubuntu5.10"><![CDATA[Ubuntu 5.10]]></key>
@ -3587,6 +3617,7 @@ We will sleep a bit and try again.
<key name="os_list_winnt4.0"><![CDATA[Microsoft Windows NT Server 4.0]]></key>
<key name="os_list_winvista"><![CDATA[Microsoft Windows Vista]]></key>
<key name="os_list_winxp"><![CDATA[Microsoft Windows XP]]></key>
<key name="os_list_unknown"><![CDATA[Unknown]]></key>
</language>
<!-- 日本語 -->

@ -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} }});
}
}

Loading…
Cancel
Save