Author: arkurth
Date: Fri Jan 14 15:33:52 2011
New Revision: 1059044

URL: http://svn.apache.org/viewvc?rev=1059044&view=rev
Log:
VCL-393
Added disable_sleep subroutines to Version_5.pm and Version_6.pm. Added call to 
disable_sleep in post_load and pre_capture in Windows.pm.

Modified:
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm
    incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_6.pm

Modified: incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=1059044&r1=1059043&r2=1059044&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Fri Jan 14 
15:33:52 2011
@@ -361,6 +361,16 @@ sub pre_capture {
 
 =item *
 
+ Disable sleep
+
+=cut
+
+       if (!$self->disable_sleep()) {
+               notify($ERRORS{'WARNING'}, 0, "unable to disable sleep");
+       }
+
+=item *
+
  Disable Windows Customer Experience Improvement program
 
 =cut
@@ -761,6 +771,16 @@ sub post_load {
 
 =item *
 
+ Disable sleep
+
+=cut
+
+       if (!$self->disable_sleep()) {
+               notify($ERRORS{'WARNING'}, 0, "unable to disable sleep");
+       }
+
+=item *
+
  Check if the imagemeta postoption is set to reboot, reboot if necessary
 
 =cut

Modified: 
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm?rev=1059044&r1=1059043&r2=1059044&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm 
(original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_5.pm 
Fri Jan 14 15:33:52 2011
@@ -649,6 +649,71 @@ sub sanitize_files {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 disable_sleep
+
+ Parameters  : None
+ Returns     : If successful: true
+               If failed: false
+ Description : Disables the sleep power mode.
+
+=cut
+
+sub disable_sleep {
+       my $self = shift;
+       unless (ref($self) && $self->isa('VCL::Module')) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine can only be called 
as a VCL::Module module object method");
+               return; 
+       }
+       
+       my $management_node_keys = $self->data->get_management_node_keys();
+       my $computer_node_name   = $self->data->get_computer_node_name();
+       my $system32_path        = $self->get_system32_path() || return;
+       
+       my $query_command = "$system32_path/powercfg.exe /QUERY";
+       my ($query_exit_status, $query_output) = 
run_ssh_command($computer_node_name, $management_node_keys, $query_command, '', 
'', 1);
+       if (!defined($query_output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to run SSH command to 
retrieve power scheme name");
+               return;
+       }
+       
+       # Join the powercfg.exe output lines into a string then parse the line 
beginning with 'Name '
+       join("\n", @$query_output) =~ /Name\s+(.*)/;
+       my $scheme_name = $1;
+       if (!$scheme_name) {
+               notify($ERRORS{'WARNING'}, 0, "failed to retrieve power scheme 
name from powercfg.exe query output:\n" . join("\n", @$query_output));
+               return;
+       }
+       notify($ERRORS{'DEBUG'}, 0, "retrieved power scheme name: 
'$scheme_name'");
+       
+       # Run powercfg.exe to disable sleep
+       my $powercfg_command;
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /monitor-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /monitor-timeout-dc 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /disk-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /disk-timeout-dc 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /standby-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /standby-timeout-dc 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /hibernate-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe /CHANGE 
\"$scheme_name\" /hibernate-timeout-dc 0";
+       
+       my ($powercfg_exit_status, $powercfg_output) = 
run_ssh_command($computer_node_name, $management_node_keys, $powercfg_command, 
'', '', 1);
+       if (!defined($powercfg_output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to run SSH command to 
disable sleep");
+               return;
+       }
+       elsif (grep(/(error|invalid|not found)/i, @$powercfg_output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to disable sleep, 
powercfg.exe output:\n" . join("\n", @$powercfg_output));
+               return;
+       }
+       else {
+               notify($ERRORS{'OK'}, 0, "disabled sleep");
+       }
+       
+       return 1;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 1;
 __END__
 

Modified: 
incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_6.pm
URL: 
http://svn.apache.org/viewvc/incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_6.pm?rev=1059044&r1=1059043&r2=1059044&view=diff
==============================================================================
--- incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_6.pm 
(original)
+++ incubator/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows/Version_6.pm 
Fri Jan 14 15:33:52 2011
@@ -1795,6 +1795,55 @@ sub sanitize_files {
 
 #/////////////////////////////////////////////////////////////////////////////
 
+=head2 disable_sleep
+
+ Parameters  : None
+ Returns     : If successful: true
+               If failed: false
+ Description : Disables the sleep power mode.
+
+=cut
+
+sub disable_sleep {
+       my $self = shift;
+       unless (ref($self) && $self->isa('VCL::Module')) {
+               notify($ERRORS{'CRITICAL'}, 0, "subroutine can only be called 
as a VCL::Module module object method");
+               return; 
+       }
+       
+       my $management_node_keys = $self->data->get_management_node_keys();
+       my $computer_node_name   = $self->data->get_computer_node_name();
+       my $system32_path        = $self->get_system32_path() || return;
+
+       # Run powercfg.exe to disable sleep
+       my $powercfg_command;
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-monitor-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-monitor-timeout-dc 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-disk-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-disk-timeout-dc 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-standby-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-standby-timeout-dc 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-hibernate-timeout-ac 0 ; ";
+       $powercfg_command .= "$system32_path/powercfg.exe -CHANGE 
-hibernate-timeout-dc 0";
+       
+       my ($powercfg_exit_status, $powercfg_output) = 
run_ssh_command($computer_node_name, $management_node_keys, $powercfg_command, 
'', '', 1);
+       if (!defined($powercfg_output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to run SSH command to 
disable sleep");
+               return;
+       }
+       elsif (grep(/(error|invalid|not found)/i, @$powercfg_output)) {
+               notify($ERRORS{'WARNING'}, 0, "failed to disable sleep, 
powercfg.exe output:\n" . join("\n", @$powercfg_output));
+               return;
+       }
+       else {
+               notify($ERRORS{'OK'}, 0, "disabled sleep");
+       }
+       
+       return 1;
+}
+
+#/////////////////////////////////////////////////////////////////////////////
+
 1;
 __END__
 


Reply via email to