[Pkg-ganeti-devel] [ganeti] 02/02: Add molly-guard helper script

Apollon Oikonomopoulos apoikos at moszumanska.debian.org
Wed Mar 19 17:10:22 UTC 2014


This is an automated email from the git hooks/post-receive script.

apoikos pushed a commit to branch master
in repository ganeti.

commit 023fe82bdb346e3f8ae7826271844251ed34905f
Author: Apollon Oikonomopoulos <apoikos at debian.org>
Date:   Wed Mar 19 18:17:54 2014 +0200

    Add molly-guard helper script
    
    Add a script to prevent system shutdown/reboot if instances are
    currently running using molly-guard.
    
    Also suggest molly-guard.
---
 debian/control                      |  2 +-
 debian/ganeti-2.10.install          |  1 +
 debian/ganeti.dirs                  |  1 +
 debian/ganeti.links                 |  1 +
 debian/molly-guard-helper           | 96 +++++++++++++++++++++++++++++++++++++
 debian/templates/ganeti-VER.install |  1 +
 6 files changed, 101 insertions(+), 1 deletion(-)

diff --git a/debian/control b/debian/control
index 4663ba9..18302f4 100644
--- a/debian/control
+++ b/debian/control
@@ -40,7 +40,7 @@ Depends: ganeti-2.10 (= ${source:Version}),
 Recommends: drbd8-utils (>= 8.0.7), qemu-kvm |
  xen-linux-system-amd64 | xen-linux-system-686-pae,
  ganeti-instance-debootstrap, ndisc6
-Suggests: ganeti-doc, blktap-dkms
+Suggests: ganeti-doc, blktap-dkms, molly-guard
 Conflicts: ganeti-htools
 Provides: ${python:Provides}, ganeti-htools
 Description: Cluster-based virtualization management software
diff --git a/debian/ganeti-2.10.install b/debian/ganeti-2.10.install
index 67d1033..c06b1d8 100644
--- a/debian/ganeti-2.10.install
+++ b/debian/ganeti-2.10.install
@@ -2,3 +2,4 @@ usr/share/ganeti/2.10
 usr/lib/ganeti/2.10/usr/lib/ganeti
 usr/lib/ganeti/2.10/usr/sbin/ganeti-cleaner
 usr/lib/ganeti/2.10/usr/sbin/ganeti-listrunner
+debian/molly-guard-helper usr/share/ganeti/2.10/
diff --git a/debian/ganeti.dirs b/debian/ganeti.dirs
index 4a71bb4..c0b05fb 100644
--- a/debian/ganeti.dirs
+++ b/debian/ganeti.dirs
@@ -1,4 +1,5 @@
 etc/ganeti
+etc/molly-guard/run.d
 usr/lib/ganeti/iallocators
 usr/share/ganeti/extstorage
 var/lib/ganeti
diff --git a/debian/ganeti.links b/debian/ganeti.links
new file mode 100644
index 0000000..37083a2
--- /dev/null
+++ b/debian/ganeti.links
@@ -0,0 +1 @@
+usr/share/ganeti/default/molly-guard-helper	etc/molly-guard/run.d/15-ganeti
diff --git a/debian/molly-guard-helper b/debian/molly-guard-helper
new file mode 100755
index 0000000..b8a7d72
--- /dev/null
+++ b/debian/molly-guard-helper
@@ -0,0 +1,96 @@
+#!/usr/bin/python
+#
+# molly-guard helper script to detect running Ganeti instances.
+#
+# Copyright (c) 2014 Apollon Oikonomopoulos <apoikos at debian.org>
+#
+# This program is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2 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 General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this package; if not, write to the Free
+# Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA  02110-1301 USA
+#
+
+import os
+import sys
+import signal
+import socket
+
+
+try:
+    from ganeti.ssconf import SimpleStore
+    from ganeti.hypervisor import GetHypervisor
+    from ganeti.errors import HypervisorError, ConfigurationError
+except ImportError:
+    sys.stderr.write("W: unable to import Ganeti code\n")
+    sys.exit(0)
+
+
+def sigh(action, hostname):
+    """ Exit with an error code to prevent system shutdown/reboot """
+    sys.stdout.write("Good thing I asked; I won't %s %s ...\n" %
+                     (action, hostname))
+    sys.exit(1)
+
+
+def main():
+    action = os.environ.get("MOLLYGUARD_CMD", "?")
+    hostname = socket.gethostname()
+
+    for sig in (signal.SIGHUP, signal.SIGTERM, signal.SIGQUIT):
+        signal.signal(sig, lambda frame, stack: sigh(action, hostname))
+
+    conf = SimpleStore()
+
+    instances = []
+    try:
+        enabled_hvs = conf.GetHypervisorList()
+    except ConfigurationError:
+        # Cluster is probably not initialized
+        sys.stderr.write("W: failed to get hypervisor list"
+                         " (not part of a cluster?)\n")
+        sys.exit(0)
+
+    for hv_type in enabled_hvs:
+        hv = GetHypervisor(hv_type)
+
+        try:
+            instances += hv.ListInstances()
+        except HypervisorError as err:
+            sys.stderr.write("W: unable to list %s instances: %s\n" %
+                             (hv_type, str(err)))
+
+    if instances:
+        sys.stdout.write("W: The following Ganeti instances will be"
+                         " terminated abnormally if you %s this system:\n" %
+                         action)
+        for instance in sorted(instances):
+            sys.stdout.write("   - %s\n" % instance)
+
+        try:
+            response = raw_input("Type YES to %s the system: " % action)
+        except KeyboardInterrupt:
+            sigh(action, hostname)
+
+        if response.lower().strip() != "yes":
+            sigh(action, hostname)
+
+    sys.exit(0)
+
+
+if __name__ == "__main__":
+    if not sys.stdin.isatty():
+        sys.exit(0)
+
+    main()
diff --git a/debian/templates/ganeti-VER.install b/debian/templates/ganeti-VER.install
index 56e6a64..1592cb6 100644
--- a/debian/templates/ganeti-VER.install
+++ b/debian/templates/ganeti-VER.install
@@ -2,3 +2,4 @@ usr/share/ganeti/@version@
 usr/lib/ganeti/@version@/usr/lib/ganeti
 usr/lib/ganeti/@version@/usr/sbin/ganeti-cleaner
 usr/lib/ganeti/@version@/usr/sbin/ganeti-listrunner
+debian/molly-guard-helper usr/share/ganeti/@version@/

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ganeti/ganeti.git



More information about the Pkg-ganeti-devel mailing list