Author: arkurth Date: Thu Feb 24 19:39:43 2011 New Revision: 1074268 URL: http://svn.apache.org/viewvc?rev=1074268&view=rev Log: VCL-435 Created ESXi.pm OS module. It currently only implements a post_load subroutine in order to allow ESXi loads to work. Some functions in the Linux.pm post_load subroutine fail under ESXi.
Updated xCAT2.pm to handle ESXi 4.1 scripted installs: Loosened regex which attempts to locate the "Serving xcat" line in the /var/log/messages file. It was looking for initrd.img. The "Serving xcat" line appears for ESXi installs but the file is not named initrd.img. Updated node_status to return 'RELOAD' if the nodetype table doesn't match currentimage.txt. Updated regex's in _get_image_template_path to remove periods and the 'i' in ESXi. The OS source patch for ESXi is 'esxi4.1' but the template files reside in an 'esx' directory. Added code to create currentimage.txt in Linux.pm::post_load if the OS install type is Kickstart. This code exists in new.pm but should really only exist in Linux.pm since it's specific to Kickstart installs. Other Updated Linux.pm to call wait_for_power_off instead of simply waiting 60 seconds. This matches the Windows code. Added: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT2.pm Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm?rev=1074268&r1=1074267&r2=1074268&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Thu Feb 24 19:39:43 2011 @@ -178,12 +178,22 @@ sub pre_capture { # Shutdown node notify($ERRORS{'OK'}, 0, "shutting down node for Linux imaging sequence"); run_ssh_command($computer_node_name, $management_node_keys, "/sbin/shutdown -h now", "root"); - notify($ERRORS{'OK'}, 0, "sleeping for 60 seconds while machine shuts down"); - sleep 60; + + # Wait maximum of 5 minutes for computer to power off + my $power_off = $self->provisioner->wait_for_power_off(120, 3, 3); + if (!defined($power_off)) { + # wait_for_power_off result will be undefined if the provisioning module doesn't implement a power_status subroutine + notify($ERRORS{'OK'}, 0, "unable to determine power status of $computer_node_name from provisioning module, sleeping 1 minute to allow computer time to shutdown"); + sleep 60; + } + elsif (!$power_off) { + notify($ERRORS{'WARNING'}, 0, "$computer_node_name never powered off"); + return; + } notify($ERRORS{'OK'}, 0, "returning 1"); return 1; -} ## end sub capture_prepare +} #///////////////////////////////////////////////////////////////////////////// @@ -202,11 +212,12 @@ sub post_load { return 0; } - my $management_node_keys = $self->data->get_management_node_keys(); - my $image_name = $self->data->get_image_name(); - my $computer_short_name = $self->data->get_computer_short_name(); - my $computer_node_name = $self->data->get_computer_node_name(); - + my $management_node_keys = $self->data->get_management_node_keys(); + my $image_name = $self->data->get_image_name(); + my $computer_short_name = $self->data->get_computer_short_name(); + my $computer_node_name = $self->data->get_computer_node_name(); + my $image_os_install_type = $self->data->get_image_os_install_type(); + notify($ERRORS{'OK'}, 0, "initiating Linux post_load: $image_name on $computer_short_name"); # Wait for computer to respond to SSH @@ -214,7 +225,17 @@ sub post_load { notify($ERRORS{'WARNING'}, 0, "$computer_node_name never responded to SSH"); return 0; } - + + if ($image_os_install_type eq "kickstart"){ + notify($ERRORS{'OK'}, 0, "detected kickstart install on $computer_short_name, writing current_image.txt"); + if (write_currentimage_txt($self->data)){ + notify($ERRORS{'OK'}, 0, "wrote current_image.txt on $computer_short_name"); + } + else { + notify($ERRORS{'WARNING'}, 0, "failed to write current_image.txt on $computer_short_name"); + } + } + # Change password if ($self->changepasswd($computer_node_name, "root")) { notify($ERRORS{'OK'}, 0, "successfully changed root password on $computer_node_name"); @@ -223,6 +244,7 @@ sub post_load { else { notify($ERRORS{'OK'}, 0, "failed to edit root password on $computer_node_name"); } + #disable ext_sshd my @stopsshd = run_ssh_command($computer_short_name, $management_node_keys, "/etc/init.d/ext_sshd stop", "root"); foreach my $l (@{$stopsshd[1]}) { @@ -1984,13 +2006,10 @@ sub get_file_size { # Add the size to the total if the type is file if ($type =~ /file/) { - $total_bytes_used += ($file_blocks * $block_size); - $total_bytes_allocated += $file_bytes; + $total_bytes_allocated += ($file_blocks * $block_size); + $total_bytes_used += $file_bytes; } elsif ($type =~ /directory/) { - $total_bytes_used += ($file_blocks * $block_size); - $total_bytes_allocated += $file_bytes; - $path =~ s/[\\\/\*]+$//g; notify($ERRORS{'DEBUG'}, 0, "recursively retrieving size of files under directory: '$path'"); my ($subdirectory_bytes_used, $subdirectory_bytes_allocated) = $self->get_file_size("$path/*"); @@ -1999,7 +2018,8 @@ sub get_file_size { } } - if ((caller(1))[3] !~ /get_file_size/) { + my $calling_sub = (caller(1))[3] || ''; + if ($calling_sub !~ /get_file_size/) { notify($ERRORS{'DEBUG'}, 0, "size of '$file_path' on $computer_node_name:\n" . "used: " . get_file_size_info_string($total_bytes_used) . "\n" . "allocated: " . get_file_size_info_string($total_bytes_allocated)); @@ -2099,6 +2119,9 @@ sub set_file_permissions { return; } + # Escape the file path in case it contains spaces + $path = escape_file_path($path); + my $chmod_mode = shift; if (!defined($chmod_mode)) { notify($ERRORS{'WARNING'}, 0, "chmod mode argument was not specified"); @@ -2115,7 +2138,7 @@ sub set_file_permissions { # Run the chmod command my $command = "chmod "; $command .= "-R " if $recursive; - $command .= "$chmod_mode \"$path\""; + $command .= "$chmod_mode $path"; my ($exit_status, $output) = $self->execute($command, 0); if (!defined($output)) { Added: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm?rev=1074268&view=auto ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm (added) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ESXi.pm Thu Feb 24 19:39:43 2011 @@ -0,0 +1,110 @@ +#!/usr/bin/perl -w +############################################################################### +# $Id: $ +############################################################################### +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +############################################################################### + +=head1 NAME + +VCL::Module::OS::Linux::ESXi.pm + +=head1 SYNOPSIS + + Needs to be written + +=head1 DESCRIPTION + + This module provides VCL support for the Linux-based VMware ESXi operating + system. + +=cut + +############################################################################## +package VCL::Module::OS::Linux::ESXi; + +# Specify the lib path using FindBin +use FindBin; +use lib "$FindBin::Bin/../../../.."; + +# Configure inheritance +use base qw(VCL::Module::OS::Linux); + +# Specify the version of this module +our $VERSION = '2.00'; + +# Specify the version of Perl to use +use 5.008000; + +use strict; +use warnings; +use diagnostics; + +use VCL::utils; + +############################################################################## + +=head1 OBJECT METHODS + +=cut + +#///////////////////////////////////////////////////////////////////////////// + +=head2 post_load + + Parameters : + Returns : + Description : + +=cut + +sub post_load { + my $self = shift; + if (ref($self) !~ /VCL::Module/i) { + notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a function, it must be called as a class method"); + return 0; + } + + my $computer_short_name = $self->data->get_computer_short_name(); + + # Wait for computer to respond to SSH + if (!$self->wait_for_response(60, 600)) { + notify($ERRORS{'WARNING'}, 0, "$computer_short_name never responded to SSH"); + return 0; + } + + if (write_currentimage_txt($self->data)){ + notify($ERRORS{'OK'}, 0, "wrote current_image.txt on $computer_short_name"); + } + else { + notify($ERRORS{'WARNING'}, 0, "failed to write current_image.txt on $computer_short_name"); + } + + $self->set_vcld_post_load_status(); + + return 1; +} + +#///////////////////////////////////////////////////////////////////////////// + +1; +__END__ + +=head1 SEE ALSO + +L<http://cwiki.apache.org/VCL/> + +=cut Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT2.pm URL: http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT2.pm?rev=1074268&r1=1074267&r2=1074268&view=diff ============================================================================== --- incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT2.pm (original) +++ incubator/vcl/trunk/managementnode/lib/VCL/Module/Provisioning/xCAT2.pm Thu Feb 24 19:39:43 2011 @@ -464,7 +464,8 @@ sub load { sleep 65; my @TAILLOG; my $t; - my $maxloops = 45; + my $maxloops = ($image_reload_time * 6); + $maxloops = 60 if $maxloops < 60; if ($eth0MACaddress && $computer_private_ip_address) { @TAILLOG = 0; @@ -497,7 +498,7 @@ sub load { } } if (!$s4) { - if ($_ =~ /Serving xcat\/\w+\/x86(_64)?\/initrd.img to $computer_private_ip_address:/) { + if ($_ =~ /Serving xcat\/.+ to $computer_private_ip_address:/) { $s4 = 1; chomp($_); notify($ERRORS{'OK'}, 0, "$computer_node_name STAGE 4 set $_"); @@ -543,7 +544,7 @@ sub load { else { #keep checking the messages log $sloop++; - sleep 7; + sleep 10; seek TAIL, 0, 1; } } #for loop @@ -1869,6 +1870,10 @@ sub node_status { $status{status} = 'RELOAD'; notify($ERRORS{'OK'}, $log, "nodetype.tab does not match requested image, node needs to be reloaded"); } + if (!$nodetype_currentimage_match) { + $status{status} = 'RELOAD'; + notify($ERRORS{'OK'}, $log, "currentimage.txt does not match requested image, node needs to be reloaded"); + } # Node is up and doesn't need to be reloaded if ($status{status} =~ /ready/i) { @@ -2098,10 +2103,14 @@ sub _get_image_template_path { # Fix the image OS source path for xCAT 2.x my $xcat2_image_os_source_path = $image_os_source_path; + # Remove periods + $xcat2_image_os_source_path =~ s/\.//g; # centos5 --> centos - $xcat2_image_os_source_path =~ s/\d+$//; + $xcat2_image_os_source_path =~ s/\d+$//g; # rhas5 --> rh $xcat2_image_os_source_path =~ s/^rh.*/rh/; + # esxi --> esx + $xcat2_image_os_source_path =~ s/^esx.*/esx/i; notify($ERRORS{'DEBUG'}, 0, "attempting to determine template path for image: image name: $image_name