Author: fapeeler
Date: Thu Aug  7 19:25:12 2014
New Revision: 1616571

URL: http://svn.apache.org/r1616571
Log:
VCL-584

added delete_variable to utils:
used to remove variables as needed based on the input var

added method in Linux post_reserve routine to add userdata to the machine.


Modified:
    vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm
    vcl/trunk/managementnode/lib/VCL/utils.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=1616571&r1=1616570&r2=1616571&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux.pm Thu Aug  7 19:25:12 2014
@@ -451,6 +451,42 @@ sub post_reserve {
        my @post_reserve_script_paths = ('/usr/local/vcl/vcl_post_reserve', 
'/etc/init.d/vcl_post_reserve');
        
        notify($ERRORS{'OK'}, 0, "initiating Linux post_reserve: $image_name on 
$computer_short_name");
+
+
+       # User supplied data
+       #check if variable is set
+       #get variable from variable table related to server reservation id 
‘userdata|<reservation id>’
+       # write contents to local temp file 
/tmp/resrvationid_post_reserve_userdata
+       # scp tmpfile to ‘/root/.vclcontrol/post_reserve_userdata’
+       # assumes the image has the call in vcl_post_reserve to import/read the 
user data file
+       #
+       
+       my $reservation_id = $self->data->get_reservation_id();
+       my $variable_name = "userdata|$reservation_id"; 
+       my $variable_data;
+       my $target_location = "/root/.vclcontrol/post_reserve_userdata";
+
+       if ($self->data->is_variable_set($variable_name)) {
+               $variable_data = $self->data->get_variable($variable_name);
+               
+               #write to local temp file
+               my $tmpfile = "/tmp/$reservation_id" ."_post_reserve_userdata";
+               if(open(TMP, ">$tmpfile")){
+                       print TMP $variable_data;
+                       close(TMP);
+
+                       if ($self->copy_file_to($tmpfile, $target_location)) {
+                               notify($ERRORS{'DEBUG'}, 0, "copied $tmpfile to 
$target_location on $computer_short_name");     
+                       }
+               }
+               else {
+                       notify($ERRORS{'WARNING'}, 0, "failed to open $tmpfile 
for writing userdata");
+               }
+               #Clean variable from variable table
+               if(delete_variable($variable_name)){
+                       notify($ERRORS{'DEBUG'}, 0, "Deleted variable_name 
$variable_name from variable table");
+               }
+       }
        
        # Check if script exists
        foreach my $script_path (@post_reserve_script_paths) {

Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1616571&r1=1616570&r2=1616571&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Thu Aug  7 19:25:12 2014
@@ -98,6 +98,7 @@ our @EXPORT = qw(
        database_select
        delete_computerloadlog_reservation
        delete_request
+       delete_variable
        escape_file_path
        format_data
        format_hash_keys
@@ -10805,6 +10806,52 @@ EOF
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 delete_variable
+
+ Parameters  : variable name
+ Returns     : If successful: true
+               If failed: false
+ Description : Deletes record related to variable name from variable table
+
+=cut
+
+sub delete_variable {
+       # Check if 1st argument is a reference meaning this was called as an 
object method
+       # If so, ignore 1st reference argument
+       shift @_ if ($_[0] && ref($_[0]) && ref($_[0]) =~ /VCL/);
+       
+       my $variable_name = shift;
+       
+       # Check the arguments
+       if (!defined($variable_name)) {
+               notify($ERRORS{'WARNING'}, 0, "variable name argument was not 
supplied");
+               return;
+       }
+       
+       notify($ERRORS{'DEBUG'}, 0, "attempting to delete variable: 
$variable_name");
+       
+       # Assemble delete statement, if the variable already exists, update the 
existing row
+       my $delete_statement .= <<"EOF";
+DELETE 
+FROM 
+variable
+WHERE
+name = '$variable_name'
+EOF
+       
+       # Execute the delete statement, the return value should be the id of 
the row
+       if (database_execute($delete_statement)) {
+               notify($ERRORS{'OK'}, 0, "deleted variable '$variable_name' 
from variable table");
+       }
+       else {
+               notify($ERRORS{'WARNING'}, 0, "failed to delete variable 
'$variable_name'");
+               return;
+       }
+       
+       return 1;
+}
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 yaml_serialize
 
  Parameters  : Data


Reply via email to