Author: fapeeler
Date: Wed Jul 15 17:42:02 2009
New Revision: 794333

URL: http://svn.apache.org/viewvc?rev=794333&view=rev
Log:
VCL-169

added routine, set_managementnode_state that accepts Management node
info hash and desired state.

This is to be used in placing a given management node into maintenance
state if an datacenter shutdown event is triggered.


Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/utils.pm

Modified: incubator/vcl/trunk/managementnode/lib/VCL/utils.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=794333&r1=794332&r2=794333&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/utils.pm Wed Jul 15 17:42:02 2009
@@ -174,6 +174,7 @@
   run_ssh_command
   set_hash_process_id
   set_logfile_path
+  set_managementnode_state
   setimageid
   setpreferredimage
   setstaticaddress
@@ -6010,6 +6011,60 @@
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 set_managementnode_state
+
+ Parameters  : management node info, state
+ Returns     : 1 or 0
+ Description : sets a given management node to maintenance
+
+=cut
+
+sub set_managementnode_state {
+       my ($mninfo, $state) = @_;
+
+       if(!(defined($state))){
+               notify($ERRORS{'WARNING'}, 0, "state was not specified");
+               return ();
+       }
+       if(!(defined($mninfo->{hostname}))){
+               notify($ERRORS{'WARNING'}, 0, "management node hostname was not 
specified");
+               return ();
+       }
+       if(!(defined($mninfo->{id}))){
+               notify($ERRORS{'WARNING'}, 0, "management node ID was not 
specified");
+               return ();
+       }
+
+       my $mn_ID = $mninfo->{id};
+       my $mn_hostname = $mninfo->{hostname};
+
+       # Construct the update statement
+       my $update_statement = "
+          UPDATE
+               managementnode,
+               state
+               SET
+               managementnode.stateid = state.id
+               WHERE
+               state.name = '$state' AND 
+               managementnode.id = '$mn_ID'
+        ";
+
+
+       # Call the database execute subroutine
+       if (database_execute($update_statement)) {
+               # Update successful, return timestamp
+               notify($ERRORS{'OK'}, 0, "Successfully updated management node 
$mn_hostname state to $state");
+               return 1;
+       }
+       else {
+               notify($ERRORS{'CRITICAL'}, 0, "unable to update database, 
management node $mn_hostname state to $state");
+               return 0;
+       }
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 =head2 get_requests
 
  Parameters  : management node id


Reply via email to