Updated anvil-provision-server so that when the OS type is 'win7', set the disk to sata and the NIC to e1000e. Also updated it to store the virt-install call in the 'variables' table and write it out to /mnt/shared/provision.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 3 years ago
parent 06f679d7e7
commit 2f8b1fb72e
  1. 2
      Anvil/Tools/Database.pm
  2. 1
      share/words.xml
  3. 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. 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. 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.

@ -2582,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_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_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_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 --> <!-- These are generally units and appended to numbers -->
<key name="suffix_0001">#!variable!number!#/sec</key> <key name="suffix_0001">#!variable!number!#/sec</key>

@ -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 # The peer is done, it'll pick up the XML definition when ScanCore runs
$anvil->Job->update_progress({ $anvil->Job->update_progress({
progress => 100, progress => 100,
@ -433,6 +460,23 @@ sub provision_server
### Support disk images (ie: sysprep) via '--import'. The device used for booting is the first ### Support disk images (ie: sysprep) via '--import'. The device used for booting is the first
### device specified via "--disk" ### device specified via "--disk"
### Consider support for TPM, RNG and watchdog devices ### 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"; my $shell_call = $anvil->data->{path}{exe}{'virt-install'}." --connect qemu:///system \\\n";
$shell_call .= "--name ".$server." \\\n"; $shell_call .= "--name ".$server." \\\n";
$shell_call .= " --os-variant ".$anvil->data->{job}{os}." \\\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 .= " --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 .= " --vcpus ".$anvil->data->{job}{cpu_cores}.",sockets=1,cores=".$anvil->data->{job}{cpu_cores}." \\\n";
$shell_call .= " --cpu host \\\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 .= " --graphics vnc \\\n";
$shell_call .= " --sound ich9 \\\n"; $shell_call .= " --sound ich9 \\\n";
$shell_call .= " --clock offset=".$clock_offset." \\\n"; # We may want to support ',rtc_tickpolicy=catchup' $shell_call .= " --clock offset=".$clock_offset." \\\n"; # We may want to support ',rtc_tickpolicy=catchup'
$shell_call .= " --boot menu=on \\\n"; $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"; $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=".$server_uuid." \\\n";
{
$shell_call .= " --uuid=".$anvil->data->{job}{server_uuid}." \\\n";
}
if ($anvil->data->{job}{driver_iso_path}) 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"; $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 }}); $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. # Call as a background process.
my ($handle, $return_code) = $anvil->System->call({ my ($handle, $return_code) = $anvil->System->call({
background => 1, background => 1,
@ -546,7 +611,7 @@ sub provision_server
return_code => $return_code, return_code => $return_code,
}}); }});
my $problem = $anvil->Server->parse_definition({ $problem = $anvil->Server->parse_definition({
server => $server, server => $server,
source => "from_virsh", source => "from_virsh",
definition => $server_definition_xml, definition => $server_definition_xml,
@ -578,7 +643,6 @@ sub provision_server
# Add the server to the 'servers' table # Add the server to the 'servers' table
my $anvil_uuid = $anvil->data->{job}{anvil_uuid}; my $anvil_uuid = $anvil->data->{job}{anvil_uuid};
my $short_host_name = $anvil->Get->short_host_name; 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({ my $got_server_uuid = $anvil->Database->insert_or_update_servers({
server_uuid => $server_uuid, server_uuid => $server_uuid,
server_name => $server, server_name => $server,
@ -1221,6 +1285,8 @@ sub parse_job_data
if ($line =~ /os=(.*)$/) if ($line =~ /os=(.*)$/)
{ {
$anvil->data->{job}{os} = $1; $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} }}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'job::os' => $anvil->data->{job}{os} }});
} }
} }

Loading…
Cancel
Save