Martin Beták has uploaded a new change for review.

Change subject: agent: [WIP] Support reboot as optional shutdown parameter
......................................................................

agent: [WIP] Support reboot as optional shutdown parameter

Added optional boolean parameter determining whether to pass the '-r'
parameter to the appropriate shutdown script.

Change-Id: I94929ff49677ee79569117158c53bdaf086b3ae8
Signed-off-by: Martin Betak <mbe...@redhat.com>
---
M ovirt-guest-agent/GuestAgentLinux2.py
M ovirt-guest-agent/GuestAgentWin32.py
M ovirt-guest-agent/OVirtAgentLogic.py
3 files changed, 22 insertions(+), 10 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-guest-agent 
refs/changes/55/15855/1

diff --git a/ovirt-guest-agent/GuestAgentLinux2.py 
b/ovirt-guest-agent/GuestAgentLinux2.py
index 9c5ec0e..c11bad7 100644
--- a/ovirt-guest-agent/GuestAgentLinux2.py
+++ b/ovirt-guest-agent/GuestAgentLinux2.py
@@ -163,13 +163,16 @@
     def logoff(self):
         pass
 
-    def shutdown(self, timeout, msg):
+    def shutdown(self, timeout, msg, reboot=False):
         # The shutdown command works with minutes while vdsm send value in
         # seconds, so we round up the value to minutes.
         delay = (int(timeout) + 59) / 60
-        cmd = ['/usr/share/ovirt-guest-agent/ovirt-shutdown', '-h',
+        param = '-r' if reboot else '-h'
+        cmd = ['/usr/share/ovirt-guest-agent/ovirt-shutdown', param,
                "+%d" % (delay), "\"%s\"" % (msg)]
-        logging.debug("Executing shutdown command: %s", cmd)
+
+        action = 'reboot' if reboot else 'shutdown'
+        logging.debug("Executing %s command: %s", action, cmd)
         subprocess.call(cmd)
 
     def hibernate(self, state):
diff --git a/ovirt-guest-agent/GuestAgentWin32.py 
b/ovirt-guest-agent/GuestAgentWin32.py
index 328657e..3715555 100644
--- a/ovirt-guest-agent/GuestAgentWin32.py
+++ b/ovirt-guest-agent/GuestAgentWin32.py
@@ -200,10 +200,13 @@
         else:
             logging.debug("No active session. Ignoring log off command.")
 
-    def shutdown(self, timeout, msg):
-        cmd = "%s\\system32\\shutdown.exe -s -t %d -f -c \"%s\"" \
-            % (os.environ['WINDIR'], timeout, msg)
-        logging.debug("Executing shutdown command: '%s'", cmd)
+    def shutdown(self, timeout, msg, reboot=False):
+        param = '-r' if reboot else '-s'
+        cmd = "%s\\system32\\shutdown.exe %s -t %d -f -c \"%s\"" \
+            % (os.environ['WINDIR'], param, timeout, msg)
+
+        action = 'reboot' if reboot else 'shutdown'
+        logging.debug("Executing %s command: '%s'", action, cmd)
 
         # Since we're a 32-bit application that sometimes is executed on
         # Windows 64-bit, executing C:\Windows\system32\shutdown.exe is
diff --git a/ovirt-guest-agent/OVirtAgentLogic.py 
b/ovirt-guest-agent/OVirtAgentLogic.py
index 43c9635..1b6d56d 100644
--- a/ovirt-guest-agent/OVirtAgentLogic.py
+++ b/ovirt-guest-agent/OVirtAgentLogic.py
@@ -175,9 +175,15 @@
                 msg = args['message']
             except:
                 msg = 'System is going down'
-            logging.info("Shutting down (timeout = %d, message = '%s')"
-                         % (timeout, msg))
-            self.commandHandler.shutdown(timeout, msg)
+            try:
+                reboot = args['reboot'].lower() == 'true'
+            except:
+                reboot = False
+
+            action = 'Rebooting' if reboot else 'Shutting down'
+            logging.info("%s (timeout = %d, message = '%s')"
+                         % (action, timeout, msg))
+            self.commandHandler.shutdown(timeout, msg, reboot)
         elif command == 'login':
             username = args['username'].encode('utf8')
             password = args['password'].encode('utf8')


-- 
To view, visit http://gerrit.ovirt.org/15855
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I94929ff49677ee79569117158c53bdaf086b3ae8
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-guest-agent
Gerrit-Branch: master
Gerrit-Owner: Martin Beták <mbe...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to