Edward Haas has uploaded a new change for review.

Change subject: hooks: Relocate hooking (api) module under lib
......................................................................

hooks: Relocate hooking (api) module under lib

Relocate hooking module under lib/vdsm in order to allow its usage from
any location/path.

A proxy hooking module is left under vdsm/ , pointing to the new
location.

Note: The module depends on other vdsm modules that are not in common and
therefore it cannot be located under vdsm/common.

Change-Id: I5f2e0ed06d5f17885b5892bb8659c52f4542a9d9
Signed-off-by: Edward Haas <[email protected]>
---
M Makefile.am
M lib/vdsm/Makefile.am
A lib/vdsm/hooking.py
M vdsm/Makefile.am
M vdsm/hooking.py
5 files changed, 97 insertions(+), 66 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/44/55544/1

diff --git a/Makefile.am b/Makefile.am
index 8b7422a..055dca8 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -82,6 +82,10 @@
        vdsm-tool/vdsm-tool \
        $(NULL)
 
+PYFLAKES_BLACKLIST = \
+       ./vdsm/hooking.py \
+       $(NULL)
+
 
 .PHONY: gitignore
 gitignore:
@@ -104,7 +108,7 @@
 pyflakes: all
        python -c 'import pyflakes; print("pyflakes-%s" % pyflakes.__version__)'
        ( find . -path './.git' -prune -type f -o \
-               -name '*.py' && \
+               -name '*.py' ! -path $(PYFLAKES_BLACKLIST) && \
                echo $(WHITELIST) ) | xargs $(PYFLAKES)
 
 .PHONY: pep8
diff --git a/lib/vdsm/Makefile.am b/lib/vdsm/Makefile.am
index e807586..2cff2a2 100644
--- a/lib/vdsm/Makefile.am
+++ b/lib/vdsm/Makefile.am
@@ -21,6 +21,8 @@
 
 SUBDIRS=common netinfo netlink tool infra profiling rpc tc network virt storage
 
+dist_vdsm_PYTHON = hooking.py
+
 dist_vdsmpylib_PYTHON = \
        __init__.py \
        cmdutils.py \
@@ -34,6 +36,7 @@
        exception.py \
        executor.py \
        health.py \
+       hooking.py \
        hooks.py \
        host.py \
        hostdev.py \
diff --git a/lib/vdsm/hooking.py b/lib/vdsm/hooking.py
new file mode 100644
index 0000000..db7ab5d
--- /dev/null
+++ b/lib/vdsm/hooking.py
@@ -0,0 +1,85 @@
+#
+# Copyright 2011 Red Hat, Inc.
+#
+# 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 program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+"""
+hooking - various stuff useful when writing vdsm hooks
+
+A vm hook expects domain xml in a file named by an environment variable called
+_hook_domxml. The hook may change the xml, but the "china store rule" applies -
+if you break something, you own it.
+
+before_migration_destination hook receives the xml of the domain from the
+source host. The xml of the domain at the destination will differ in various
+details.
+
+Return codes:
+0 - the hook ended successfully.
+1 - the hook failed, other hooks should be processed.
+2 - the hook failed, no further hooks should be processed.
+>2 - reserved
+"""
+
+from __future__ import absolute_import
+
+import json
+import os
+import sys
+from xml.dom import minidom
+
+from vdsm.commands import execCmd
+from vdsm.utils import tobool
+
+# make pyflakes happy
+execCmd
+tobool
+
+
+def read_domxml():
+    with open(os.environ['_hook_domxml']) as f:
+        return minidom.parseString(f.read())
+
+
+def write_domxml(domxml):
+    with open(os.environ['_hook_domxml'], 'w') as f:
+        f.write(domxml.toxml(encoding='utf-8'))
+
+
+def read_json():
+    with open(os.environ['_hook_json']) as f:
+        return json.loads(f.read())
+
+
+def write_json(data):
+    with open(os.environ['_hook_json'], 'w') as f:
+        f.write(json.dumps(data))
+
+
+def log(message):
+    sys.stderr.write(message + '\n')
+
+
+def exit_hook(message, return_code=2):
+    """
+    Exit the hook with a given message, which will be printed to the standard
+    error stream. A newline will be printed at the end.
+    The default return code is 2 for signaling that an error occurred.
+    """
+    sys.stderr.write(message + "\n")
+    sys.exit(return_code)
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
index 7000369..be4afe1 100644
--- a/vdsm/Makefile.am
+++ b/vdsm/Makefile.am
@@ -28,7 +28,6 @@
        blkid.py \
        caps.py \
        clientIF.py \
-       hooking.py \
        mkimage.py \
        momIF.py \
        numaUtils.py \
diff --git a/vdsm/hooking.py b/vdsm/hooking.py
index 97bf13d..f04460d 100644
--- a/vdsm/hooking.py
+++ b/vdsm/hooking.py
@@ -1,5 +1,5 @@
 #
-# Copyright 2011 Red Hat, Inc.
+# Copyright 2016 Red Hat, Inc.
 #
 # 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
@@ -18,66 +18,6 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
-"""
-hooking - various stuff useful when writing vdsm hooks
-
-A vm hook expects domain xml in a file named by an environment variable called
-_hook_domxml. The hook may change the xml, but the "china store rule" applies -
-if you break something, you own it.
-
-before_migration_destination hook receives the xml of the domain from the
-source host. The xml of the domain at the destination will differ in various
-details.
-
-Return codes:
-0 - the hook ended successfully.
-1 - the hook failed, other hooks should be processed.
-2 - the hook failed, no further hooks should be processed.
->2 - reserved
-"""
-
-import json
-import os
-import sys
-from xml.dom import minidom
-
-from vdsm.commands import execCmd
-from vdsm.utils import tobool
-
-# make pyflakes happy
-execCmd
-tobool
-
-
-def read_domxml():
-    with open(os.environ['_hook_domxml']) as f:
-        return minidom.parseString(f.read())
-
-
-def write_domxml(domxml):
-    with open(os.environ['_hook_domxml'], 'w') as f:
-        f.write(domxml.toxml(encoding='utf-8'))
-
-
-def read_json():
-    with open(os.environ['_hook_json']) as f:
-        return json.loads(f.read())
-
-
-def write_json(data):
-    with open(os.environ['_hook_json'], 'w') as f:
-        f.write(json.dumps(data))
-
-
-def log(message):
-    sys.stderr.write(message + '\n')
-
-
-def exit_hook(message, return_code=2):
-    """
-    Exit the hook with a given message, which will be printed to the standard
-    error stream. A newline will be printed at the end.
-    The default return code is 2 for signaling that an error occurred.
-    """
-    sys.stderr.write(message + "\n")
-    sys.exit(return_code)
+# This is a proxy to the hooking module, supporting existing code
+# TODO: When all refferences to hooking are fixed, this proxy can be removed.
+from vdsm.hooking import *


-- 
To view, visit https://gerrit.ovirt.org/55544
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5f2e0ed06d5f17885b5892bb8659c52f4542a9d9
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Edward Haas <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to