Author: fapeeler
Date: Wed May 14 15:41:28 2014
New Revision: 1594610

URL: http://svn.apache.org/r1594610
Log:
VCL-760

code for vcl_post_reservation


Modified:
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
    vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
    vcl/trunk/managementnode/lib/VCL/reclaim.pm

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm?rev=1594610&r1=1594609&r2=1594610&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Wed May 14 15:41:28 2014
@@ -458,6 +458,50 @@ sub post_reserve {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 post_reservation
+
+ Parameters  : none
+ Returns     : boolean 1 or 0
+ Description : Checks for and runs vcl_post_reservation script at the end of a 
reservation
+
+=cut
+
+sub post_reservation {
+       my $self = shift;
+       if (ref($self) !~ /linux/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return 0;
+       }
+       
+       my $image_name          = $self->data->get_image_name();
+       my $computer_short_name = $self->data->get_computer_short_name();
+       my $script_path         = '/etc/init.d/vcl_post_reservation';
+       
+       notify($ERRORS{'OK'}, 0, "initiating Linux post_reservation: 
$image_name on $computer_short_name");
+       
+       # Check if script exists
+       if (!$self->file_exists($script_path)) {
+               notify($ERRORS{'DEBUG'}, 0, "script does NOT exist: 
$script_path");
+               return 1;
+       }
+       
+       # Run the vcl_post_reserve script if it exists in the image
+       my $result = $self->run_script($script_path, '1', '300', '1');
+       if (!defined($result)) {
+               notify($ERRORS{'WARNING'}, 0, "error occurred running 
$script_path");
+       }
+       elsif ($result == 0) {
+               notify($ERRORS{'DEBUG'}, 0, "$script_path does not exist in 
image: $image_name");
+       }
+       else {
+               notify($ERRORS{'DEBUG'}, 0, "ran $script_path");
+       }
+
+       return 1;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 update_public_hostname
 
  Parameters  : none

Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=1594610&r1=1594609&r2=1594610&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Wed May 14 15:41:28 
2014
@@ -982,6 +982,49 @@ sub post_reserve {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 post_reservation
+
+ Parameters  : none
+ Returns     : boolean
+ Description : Runs $SYSTEMROOT/vcl_post_reservation.cmd if it exists in the 
image.
+               Does not check if the actual script succeeded or not.
+
+=cut
+
+sub post_reservation {
+       my $self = shift;
+       if (ref($self) !~ /windows/i) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a 
function, it must be called as a class method");
+               return 0;
+       }
+       
+       my $image_name = $self->data->get_image_name();
+       my $computer_short_name = $self->data->get_computer_short_name();
+       my $script_path = '$SYSTEMROOT/vcl_post_reservation.cmd';
+       
+       # Check if script exists
+       if (!$self->file_exists($script_path)) {
+               notify($ERRORS{'DEBUG'}, 0, "post_reservation script does NOT 
exist: $script_path");
+               return 1;
+       }
+       
+       # Run the vcl_post_reserve.cmd script if it exists in the image
+       my $result = $self->run_script($script_path);
+       if (!defined($result)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to run post_reservation 
script: $script_path");
+       }
+       elsif ($result == 0) {
+               notify($ERRORS{'DEBUG'}, 0, "$script_path does not exist in 
image: $image_name");
+       }
+       else {
+               notify($ERRORS{'DEBUG'}, 0, "ran $script_path");
+       }
+       
+       return 1;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 sanitize
 
  Parameters  :

Modified: vcl/trunk/managementnode/lib/VCL/reclaim.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/reclaim.pm?rev=1594610&r1=1594609&r2=1594610&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/reclaim.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/reclaim.pm Wed May 14 15:41:28 2014
@@ -207,6 +207,14 @@ sub insert_reload_and_exit {
        my $self = shift;
        my $request_data               = $self->data->get_request_data;
        my $computer_id                = $self->data->get_computer_id();
+       my $computer_shortname                   = 
$self->data->get_computer_short_name();
+       
+       # Run any vcl_post_reservation scripts (if exists)
+       if ($self->os->can("post_reservation")) {
+               if ($self->os->post_reservation()) {
+                       notify($ERRORS{'OK'}, 0, "post_reservation script has 
been executed on $computer_shortname prior to reloading");
+               }
+       }
        
        # Retrieve next image
        my ($next_image_name, $next_image_id, $next_imagerevision_id) = 
$self->data->get_next_image_dataStructure();


Reply via email to