--- /dev/null
+# This is part of "osstest", an automated testing framework for Xen.
+# Copyright (C) 2009-2013 Citrix Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+package Osstest::PDU::ssh;
+
+# This power method is used automatically, even when not configured.
+
+use strict;
+use warnings;
+
+use Osstest;
+use Osstest::TestSupport;
+
+use parent qw(Osstest::PDU::unsupported);
+
+our $tty;
+
+sub pdu_sleep_required {
+ return 0;
+}
+
+sub pdu_power_state {
+ my ($mo, $on) = @_;
+
+ if (!$on) {
+ logm("power: request to turn off via SSH method, ignored");
+ return;
+ }
+
+ # These games with ( )& are needed because the command to request
+ # a hard reboot request will not return, so the tcp connection
+ # carrying our ssh command request would just hang.
+
+ my $delay = 5;
+
+ target_cmd_root($mo->{Host}, <<'END', 60);
+ set -e
+ type reboot
+ exec >>/var/log/osstest-reboot.log
+ date
+ exec </dev/null 2>&1
+ set -x
+ (
+ set +e
+ sleep $delay
+ reboot -f -n -d # Linux sysvinit/systemd
+ reboot -nq # FreeBSD (rejects above due to -f)
+ )&
+END
+
+ sleep($delay);
+}
+
+sub instantaneous {
+ my ($mo) = @_;
+ # This does not need any more sleep, if it worked.
+ return 1;
+}
+
+1;