Author: arkurth
Date: Mon Jul 26 19:42:35 2010
New Revision: 979417
URL: http://svn.apache.org/viewvc?rev=979417&view=rev
Log:
VCL-221
Added set_vcld_post_load_status() and get_vcld_post_load_status() subroutines
to OS.pm. They set and retrieve a vcld_post_load= line in currentimage.txt.
This line is used to determine whether or not the OS post-load tasks have run
for a loaded image.
Added call to set_vcld_post_load_status() at the end of new.pm::reload_image().
This essentially tags the loaded computer so that the OS post-load tasks aren't
run again.
Added call to get_vcld_post_load_status() to the beginning of
new.pm::reserve_computer(). If the post-load tasks have not been run, the OS
module's post_load() subroutine is called before a computer is reserved.
Modified:
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm
incubator/vcl/trunk/managementnode/lib/VCL/new.pm
Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm?rev=979417&r1=979416&r2=979417&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS.pm Mon Jul 26 19:42:35
2010
@@ -677,6 +677,114 @@ sub update_public_ip_address {
#/////////////////////////////////////////////////////////////////////////////
+=head2 get_vcld_post_load_status
+
+ Parameters : None
+ Returns : If vcld_post_load line exists: 1
+ If vcld_post_load line exists: 0
+ If an error occurred: undefined
+ Description : Checks the currentimage.txt file on the computer for a line
+ beginning with 'vcld_post_load='. Returns 1 if this line is
found
+ indicating that the OS module's post_load tasks have
successfully
+ run. Returns 0 if the line is not found, and undefined if an
+ error occurred.
+
+=cut
+
+sub get_vcld_post_load_status {
+ 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;
+ }
+
+ my $management_node_keys = $self->data->get_management_node_keys();
+ my $computer_node_name = $self->data->get_computer_node_name();
+
+ # Add a line to the end of currentimage.txt
+ my $command = "grep vcld_post_load= currentimage.txt";
+
+
+ my ($exit_status, $output) = run_ssh_command($computer_node_name,
$management_node_keys, $command, '', '', 0);
+ if (defined($output)) {
+ if (my ($status_line) = grep(/vcld_post_load=/, @$output)) {
+ notify($ERRORS{'DEBUG'}, 0, "vcld post load tasks have
run on $computer_node_name: $status_line");
+ return 1;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "vcld post load tasks have
NOT run on $computer_node_name");
+ return 0;
+ }
+ }
+ elsif ($exit_status) {
+ notify($ERRORS{'WARNING'}, 0, "failed to retrieve
vcld_post_load status line from currentimage.txt on $computer_node_name, exit
status: $exit_status, output:\n" . join("\n", @$output));
+ return;
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed to run SSH command to
retrieve vcld_post_load status line from currentimage.txt on
$computer_node_name");
+ return;
+ }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
+=head2 set_vcld_post_load_status
+
+ Parameters : none
+ Returns : boolean
+ Description : Adds a line to currentimage.txt indicating the vcld OS post_load
+ tasks have run. The format of the line added is:
+ vcld_post_load=success (<time>)
+
+ This line is checked when a computer is reserved to make sure
the
+ post_load tasks have run. A computer may be loaded but the
+ post_load tasks may not run if it is loaded manually or by some
+ other means not controlled by vcld.
+
+=cut
+
+sub set_vcld_post_load_status {
+ 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;
+ }
+
+ my $management_node_keys = $self->data->get_management_node_keys();
+ my $computer_node_name = $self->data->get_computer_node_name();
+
+ my $time = localtime;
+
+ my $post_load_line = "vcld_post_load=success ($time)";
+
+ # Assemble the command
+ my $command;
+
+ # Remove existing lines beginning with vcld_post_load
+ $command .= "sed -ie \"/^vcld_post_load.*/d\" currentimage.txt";
+
+ # Add a line to the end of currentimage.txt
+ $command .= " && echo -E \"$post_load_line\" >> currentimage.txt";
+
+ my ($exit_status, $output) = run_ssh_command($computer_node_name,
$management_node_keys, $command, '', '', 1);
+ if (defined($exit_status) && $exit_status == 0) {
+ notify($ERRORS{'DEBUG'}, 0, "added line to currentimage.txt on
$computer_node_name: $post_load_line");
+ }
+ elsif ($exit_status) {
+ notify($ERRORS{'WARNING'}, 0, "failed to add line to
currentimage.txt on $computer_node_name: $post_load_line, exit status:
$exit_status, output:\n" . join("\n", @$output));
+ return;
+ }
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed to run SSH command to add
line to currentimage.txt on $computer_node_name");
+ return;
+ }
+
+ return 1;
+}
+
+
+#/////////////////////////////////////////////////////////////////////////////
+
1;
__END__
Modified: incubator/vcl/trunk/managementnode/lib/VCL/new.pm
URL:
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/new.pm?rev=979417&r1=979416&r2=979417&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/new.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/new.pm Mon Jul 26 19:42:35 2010
@@ -86,7 +86,7 @@ use VCL::utils;
sub process {
my $self = shift;
-
+
my $request_data = $self->data->get_request_data();
my $request_id = $self->data->get_request_id();
my $request_logid = $self->data->get_request_log_id();
@@ -659,7 +659,7 @@ sub reload_image {
#Post operations not to be handled by provisioning modules
if($image_os_install_type eq "kickstart"){
- notify($ERRORS{'OK'}, 0, "Detected kickstart install on
$computer_short_name, writing current_image.txt");
+ 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, "Successfully wrote
current_image.txt on $computer_short_name");
}
@@ -677,6 +677,9 @@ sub reload_image {
notify($ERRORS{'WARNING'}, 0, "failed to update computer table
for $computer_short_name: currentimageid=$image_id");
}
+ # Add the vcld_post_load line to currentimage.txt
+ $self->os->set_vcld_post_load_status();
+
notify($ERRORS{'OK'}, 0, "returning 1");
return 1;
} ## end sub reload_image
@@ -989,6 +992,20 @@ sub reserve_computer {
if ($computer_type =~ /blade|virtualmachine/) {
+ # Check if the OS module implements a post_load subroutine and
that post_load has been run
+ if ($self->os->can('post_load') &&
!$self->os->get_vcld_post_load_status()) {
+ # The OS module's post_load() tasks have not run
+ notify($ERRORS{'DEBUG'}, 0, "calling OS module's
post_load() subroutine because currentimage.txt does not contain a
vcld_post_load= line");
+
+ # Call OS::post_load()
+ if ($self->os->post_load()) {
+ # Add the vcld_post_load line to
currentimage.txt
+ $self->os->set_vcld_post_load_status();}
+ else {
+ notify($ERRORS{'WARNING'}, 0, "failed to
execute OS module's post_load() subroutine");
+ }
+ }
+
if (!$self->os->update_public_ip_address()) {
$self->reservation_failed("failed to update private IP
address");
}