[CRIU] [PATCH 3/3] p.haul: allow pass module specific command line arguments

Nikita Spiridonov nspiridonov at odin.com
Thu Nov 26 04:52:19 PST 2015


Implement module specific arguments feature. For example, with
current patch we can define some Virtuozzo specific command
line arguments and hauler can access such options further in its
'set_options' function.

Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
 phaul/args_parser.py |    5 +++++
 phaul/htype.py       |   21 +++++++++++++++++----
 phaul/p_haul_vz.py   |    5 +++++
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/phaul/args_parser.py b/phaul/args_parser.py
index cbe306b..8e519b4 100644
--- a/phaul/args_parser.py
+++ b/phaul/args_parser.py
@@ -2,6 +2,7 @@
 # p.haul command line arguments parsers
 #
 
+import sys
 import argparse
 import htype
 import images
@@ -37,6 +38,10 @@ def parse_client_args():
 	parser.add_argument('--pre-dump', dest='pre_dump', action='store_const',
 		const=iters.PRE_DUMP_ENABLE, help='Force enable pre-dumps')
 
+	# Add haulers specific arguments
+	if len(sys.argv) > 1 and sys.argv[1] in htype.get_haul_names():
+		htype.add_hauler_args(sys.argv[1], parser)
+
 	return parser.parse_args()
 
 
diff --git a/phaul/htype.py b/phaul/htype.py
index e6104b3..65829f2 100644
--- a/phaul/htype.py
+++ b/phaul/htype.py
@@ -21,6 +21,15 @@ def get_haul_names():
 	return __haul_modules.keys()
 
 
+def add_hauler_args(hauler_name, parser):
+	"""Add hauler specific command line arguments"""
+
+	hauler_module = __get_module(hauler_name)
+	add_args_func = getattr(hauler_module, "add_hauler_args", None)
+	if add_args_func:
+		add_args_func(parser)
+
+
 def get_src(id):
 	ht = __get(id)
 	ht.init_src()
@@ -39,10 +48,14 @@ def __get(id):
 		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__)
+	hauler_module = __get_module(hauler_name)
 	logging.debug("%s hauler imported from %s", hauler_name,
 		hauler_module.__file__)
-
 	return hauler_module.p_haul_type(haulee_id)
+
+
+def __get_module(hauler_name):
+	"""Import specified haulers module relatively and return module object"""
+	module_name = ".{0}".format(__haul_modules[hauler_name])
+	module = importlib.import_module(module_name, __package__)
+	return module
diff --git a/phaul/p_haul_vz.py b/phaul/p_haul_vz.py
index b9ca5b7..f1d8b31 100644
--- a/phaul/p_haul_vz.py
+++ b/phaul/p_haul_vz.py
@@ -240,6 +240,11 @@ class p_haul_type:
 		return True
 
 
+def add_hauler_args(parser):
+	"""Add Virtuozzo specific command line arguments"""
+	parser.add_argument("--vz-dst-ctid", help="ctid at destination")
+
+
 def _parse_vz_config(body):
 	"""Parse shell-like virtuozzo config file"""
 
-- 
1.7.1



More information about the CRIU mailing list