[CRIU] [PATCH 2/6] p.haul: rework haulers modules import
Nikita Spiridonov
nspiridonov at odin.com
Mon Oct 12 10:32:17 PDT 2015
Rework haulers modules import to import only single required hauler
according to specified in command line hauler name, e.g. vz or lxc.
For example, for command line "./phaul vz ..." during migration p.haul
import p_haul_vz.py module only and don't import p_haul_lxc.py and
p_haul_pid.py.
This change is needed since certain module can import some specific
python libraries useless for other modules. For example vz module
use libploop python library and with current patch all other-than-vz
modules can work correctly even if libploop missing.
Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
phaul/p_haul_lxc.py | 1 -
phaul/p_haul_pid.py | 2 --
phaul/p_haul_type.py | 34 +++++++++++++++++++++-------------
phaul/p_haul_vz.py | 1 -
4 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/phaul/p_haul_lxc.py b/phaul/p_haul_lxc.py
index d94841b..e3bbb48 100644
--- a/phaul/p_haul_lxc.py
+++ b/phaul/p_haul_lxc.py
@@ -12,7 +12,6 @@ import fs_haul_shared
import fs_haul_subtree
from subprocess import Popen, PIPE
-name = "lxc"
lxc_dir = "/var/lib/lxc/"
lxc_rootfs_dir = "/usr/lib64/lxc/rootfs"
cg_image_name = "lxccg.img"
diff --git a/phaul/p_haul_pid.py b/phaul/p_haul_pid.py
index e604991..e0f9d2f 100644
--- a/phaul/p_haul_pid.py
+++ b/phaul/p_haul_pid.py
@@ -6,8 +6,6 @@ import logging
import p_haul_module
import fs_haul_shared
-name = "pid"
-
class p_haul_type:
def __init__(self, id):
self.pid = int(id)
diff --git a/phaul/p_haul_type.py b/phaul/p_haul_type.py
index 4fa2833..7e05a7b 100644
--- a/phaul/p_haul_type.py
+++ b/phaul/p_haul_type.py
@@ -5,24 +5,32 @@
#
import logging
-import p_haul_vz
-import p_haul_pid
-import p_haul_lxc
-
-haul_types = {
- p_haul_vz.name: p_haul_vz,
- p_haul_pid.name: p_haul_pid,
- p_haul_lxc.name: p_haul_lxc,
+import importlib
+
+__haul_modules = {
+ "vz": "p_haul_vz",
+ "pid": "p_haul_pid",
+ "lxc": "p_haul_lxc",
}
def __get(id):
- if haul_types.has_key(id[0]):
- h_type = haul_types[id[0]]
- return h_type.p_haul_type(id[1])
- else:
- logging.info("Unknown type. Try one of %s", str(haul_types.keys()))
+ hauler_name, haulee_id = id[0], id[1]
+ if not __haul_modules.has_key(hauler_name):
+ logging.error("Unknown type. Try one of %s", str(get_haul_names()))
return None
+ # Import specified haulers module relatively
+ hauler_module_name = ".{0}".format(__haul_modules[hauler_name])
+ hauler_module = importlib.import_module(hauler_module_name, __package__)
+ logging.debug("%s hauler imported from %s", hauler_name,
+ hauler_module.__file__)
+
+ return hauler_module.p_haul_type(haulee_id)
+
+def get_haul_names():
+ """Return list of available haulers"""
+ return __haul_modules.keys()
+
def get_src(id):
ht = __get(id)
ht.init_src()
diff --git a/phaul/p_haul_vz.py b/phaul/p_haul_vz.py
index f25c1a0..a781bd5 100644
--- a/phaul/p_haul_vz.py
+++ b/phaul/p_haul_vz.py
@@ -13,7 +13,6 @@ import fs_haul_shared
import fs_haul_subtree
import pycriu.rpc
-name = "vz"
vz_global_conf = "/etc/vz/vz.conf"
vz_conf_dir = "/etc/vz/conf/"
cg_image_name = "ovzcg.img"
--
1.7.1
More information about the CRIU
mailing list