Author: arkurth
Date: Fri Nov 21 21:43:42 2014
New Revision: 1641005
URL: http://svn.apache.org/r1641005
Log:
VCL-409
Fixed bug in image.pm::setup_capture_base_image. It was using the computer's
provisioning.name value as the install type. Added
utils.pm::get_provisioning_osinstalltype_info. Updated image.pm to determine
all of the OSinstalltype names which are mapped to the computer's provisioning
ID. This is used to prune the list of OS's to choose from.
Fixed some poorly worded instructions displayed if other reservations exist for
a computer used to capture a base image.
Modified:
vcl/trunk/managementnode/lib/VCL/image.pm
vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: vcl/trunk/managementnode/lib/VCL/image.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/image.pm?rev=1641005&r1=1641004&r2=1641005&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/image.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/image.pm Fri Nov 21 21:43:42 2014
@@ -620,28 +620,24 @@ sub setup_capture_base_image {
my $computer_hostname = $computer_info{$computer_id}{hostname};
my $computer_state_name = $computer_info{$computer_id}{state}{name};
+ my $computer_provisioning_id =
$computer_info{$computer_id}{provisioning}{id};
my $computer_provisioning_module_name =
$computer_info{$computer_id}{provisioning}{module}{name};
my $computer_provisioning_module_pretty_name =
$computer_info{$computer_id}{provisioning}{module}{prettyname};
my $computer_provisioning_pretty_name =
$computer_info{$computer_id}{provisioning}{prettyname};
my $computer_provisioning_name =
$computer_info{$computer_id}{provisioning}{name};
my $computer_node_name = $computer_info{$computer_id}{SHORTNAME};
- my $install_type;
- if ($computer_provisioning_module_name =~ /xcat/i) {
- $install_type = 'partimage';
- }
- else {
- $install_type = $computer_provisioning_name;
- }
+ my $osinstalltype_info =
get_provisioning_osinstalltype_info($computer_provisioning_id);
+ my @provisioning_osinstalltype_names = map {
$osinstalltype_info->{$_}{name} } keys %$osinstalltype_info;
print "\nComputer to be captured: $computer_hostname (ID:
$computer_id)\n";
print "Computer shortname: $computer_node_name\n";
print "Computer State: $computer_state_name\n";
print "Provisioning module:
$computer_provisioning_module_pretty_name\n";
- print "Install type: $install_type\n";
+ print "OS install types: " . join(", ", sort
@provisioning_osinstalltype_names) . "\n";
my $vmhost_name;
- if ($install_type ne "partimage") {
+ if ($computer_provisioning_module_name !~ /xcat/i) {
$image_is_virtual = 1;
#should have a vmhost assigned
if ($computer_info{$computer_id}{vmhostid}){
@@ -696,7 +692,7 @@ sub setup_capture_base_image {
my $computer_requests = get_request_by_computerid($computer_id);
my %existing_requests_array_choices;
if (keys(%$computer_requests)) {
- $existing_requests_array_choices{0}{"prettyname"} = "None :
delete all previous reservations for $computer_node_name";
+ $existing_requests_array_choices{0}{"prettyname"} = "Delete all
existing reservations for $computer_node_name";
for my $competing_request_id (sort keys %$computer_requests) {
my $competing_reservation_id =
$computer_requests->{$competing_request_id}{data}->get_reservation_id();
my $competing_imagerevision_id =
$computer_requests->{$competing_request_id}{data}->get_imagerevision_id();
@@ -714,8 +710,8 @@ sub setup_capture_base_image {
}
my $num_computer_requests = keys(%$computer_requests);
- print "WARNING: Image capture reservation exists for
$computer_node_name.\n\n";
- print "Make Selection, Choose none to start over or choose the
image to restart image capture for that request:\n";
+ print "WARNING: Image capture reservation exists for
$computer_node_name.\n";
+ print "Either choose the image name to restart image capture
for that request or choose none to delete the previous reservations:\n";
my $chosen_request_id =
setup_get_hash_choice(\%existing_requests_array_choices, 'prettyname');
return if (!defined($chosen_request_id));
@@ -814,15 +810,26 @@ sub setup_capture_base_image {
}
# Loop through the OS table info
- for my $os_id (keys %$os_info) {
- # Remove keys which don't match the selected computer type
+ OS_ID: for my $os_id (keys %$os_info) {
+ my $osinstalltype_name = $os_info->{$os_id}{installtype};
+
# Remove keys where the name begins with esx - deprecated OS
type
- if ($os_info->{$os_id}{installtype} ne $install_type ||
$os_info->{$os_id}{name} =~ /^vmwareesx/i) {
+ if ($osinstalltype_name =~ /^vmwareesx/i) {
delete $os_info->{$os_id};
+ next;
}
+
+ # Remove keys which don't match the selected computer type
+ for my $provisioning_osinstalltype_name
(@provisioning_osinstalltype_names) {
+ if ($provisioning_osinstalltype_name eq
$osinstalltype_name) {
+ next OS_ID;
+ }
+ }
+
+ delete $os_info->{$os_id};
}
- print "Select the OS to be captured (install type: $install_type):\n";
+ print "Select the OS to be captured (install type: " . join(', ', sort
@provisioning_osinstalltype_names) . "):\n";
my $os_id = setup_get_hash_choice($os_info, 'prettyname');
return if (!defined($os_id));
my $os_prettyname = $os_info->{$os_id}{prettyname};
Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1641005&r1=1641004&r2=1641005&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Fri Nov 21 21:43:42 2014
@@ -160,6 +160,7 @@ our @EXPORT = qw(
get_next_image_default
get_os_info
get_production_imagerevision_info
+ get_provisioning_osinstalltype_info
get_random_mac_address
get_request_by_computerid
get_request_current_state_name
@@ -6880,6 +6881,7 @@ sub get_computer_info {
'module',
'schedule',
'platform',
+ 'nathost',
);
# Construct the select statement
@@ -6919,6 +6921,10 @@ ON (
)
LEFT JOIN (schedule) ON (schedule.id = computer.scheduleid)
LEFT JOIN (module AS predictivemodule) ON (predictivemodule.id =
computer.predictivemoduleid)
+LEFT JOIN (nathost, nathostcomputermap) ON (
+ nathostcomputermap.computerid = computer.id
+ AND nathostcomputermap.nathostid = nathost.id
+)
WHERE
computer.deleted != '1'
@@ -11885,6 +11891,105 @@ EOF
#/////////////////////////////////////////////////////////////////////////////
+=head2 get_provisioning_osinstalltype_info
+
+ Parameters : $provisioning_id
+ Returns : hash reference
+ Description : Retrieves information for all of the OSinstalltypes mapped to a
+ provisioning ID. A hash is returned:
+ }
+ 10 => {
+ "id" => 10,
+ "name" => "hyperv",
+ "provisioningOSinstalltype" => {
+ "OSinstalltypeid" => 10,
+ "provisioningid" => 8
+ }
+ },
+ 4 => {
+ "id" => 4,
+ "name" => "vmware",
+ "provisioningOSinstalltype" => {
+ "OSinstalltypeid" => 4,
+ "provisioningid" => 8
+ }
+ }
+ }
+
+=cut
+
+
+sub get_provisioning_osinstalltype_info {
+ my ($provisioning_id) = @_;
+ if (!defined($provisioning_id)) {
+ notify($ERRORS{'WARNING'}, 0, "provisioning ID argument was not
specified");
+ return;
+ }
+
+
+ # Get a hash ref containing the database column names
+ my $database_table_columns = get_database_table_columns();
+
+ my @tables = (
+ 'provisioningOSinstalltype',
+ 'OSinstalltype',
+ );
+
+ # Construct the select statement
+ my $select_statement = "SELECT DISTINCT\n";
+
+ # Get the column names for each table and add them to the select
statement
+ for my $table (@tables) {
+ my @columns = @{$database_table_columns->{$table}};
+ for my $column (@columns) {
+ $select_statement .= "$table.$column AS
'$table-$column',\n";
+ }
+ }
+
+ # Remove the comma after the last column line
+ $select_statement =~ s/,$//;
+
+ # Complete the select statement
+ $select_statement .= <<EOF;
+FROM
+provisioningOSinstalltype,
+OSinstalltype
+WHERE
+provisioningOSinstalltype.provisioningid = $provisioning_id
+AND provisioningOSinstalltype.OSinstalltypeid = OSinstalltype.id
+EOF
+
+ # Call the database select subroutine
+ my @selected_rows = database_select($select_statement);
+
+ my $info = {};
+ for my $row (@selected_rows) {
+ my $osinstalltype_id = $row->{'OSinstalltype-id'};
+
+ # Loop through all the columns returned
+ for my $key (keys %$row) {
+ my $value = $row->{$key};
+
+ # Split the table-column names
+ my ($table, $column) = $key =~ /^([^-]+)-(.+)/;
+
+ # Add the values for the primary table to the hash
+ # Add values for other tables under separate keys
+ if ($table eq 'OSinstalltype') {
+ $info->{$osinstalltype_id}{$column} = $value;
+ }
+ else {
+ $info->{$osinstalltype_id}{$table}{$column} =
$value;
+ }
+ }
+ }
+
+ notify($ERRORS{'DEBUG'}, 0, "retrieved info for OSinstalltypes mapped
to provisioning ID $provisioning_id: " . format_data($info));
+ return $info;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
1;
__END__