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

Nikita Spiridonov nspiridonov at odin.com
Fri Nov 20 08:49:03 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.

Current implementation needed just to divide common phaul arguments
from module specific details. At the present moment it don't verify
that passed specific arguments actual for selected phaul module.

Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
 phaul/args_parser.py |   35 +++++++++++++++++++++++++++++++++++
 phaul/htype.py       |   13 +++++++++----
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/phaul/args_parser.py b/phaul/args_parser.py
index cbe306b..5877933 100644
--- a/phaul/args_parser.py
+++ b/phaul/args_parser.py
@@ -15,6 +15,7 @@ def parse_client_args():
 	parser = argparse.ArgumentParser("Process HAULer")
 	parser.set_defaults(pre_dump=iters.PRE_DUMP_AUTO_DETECT)
 
+	# Add common arguments
 	parser.add_argument("type", choices=htype.get_haul_names(),
 		help="Type of hat to haul, e.g. vz, lxc, or docker")
 	parser.add_argument("id", help="ID of what to haul")
@@ -37,6 +38,9 @@ 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
+	__add_haulers_args(__client_args_funcs, parser)
+
 	return parser.parse_args()
 
 
@@ -45,9 +49,40 @@ def parse_service_args():
 
 	parser = argparse.ArgumentParser("Process HAULer service server")
 
+	# Add common arguments
 	parser.add_argument("--fdrpc", type=int, required=True, help="File descriptor of rpc socket")
 	parser.add_argument("--fdmem", type=int, required=True, help="File descriptor of memory socket")
 	parser.add_argument("--fdfs", type=int, required=True, help="File descriptor of fs socket")
 	parser.add_argument("--log-file", help="Write logging messages to specified file")
 
+	# Add haulers specific arguments
+	__add_haulers_args(__service_args_funcs, parser)
+
 	return parser.parse_args()
+
+
+def __add_haulers_args(funcs, parser):
+	for hauler_name in htype.get_haul_names():
+		if hauler_name in funcs:
+			group = parser.add_argument_group(hauler_name)
+			funcs[hauler_name](group)
+
+
+def __add_vz_client_args(parser):
+	"""Add Virtuozzo client-specific arguments"""
+	parser.add_argument("--vz-dst-ctid", help="ctid at destination")
+
+
+__client_args_funcs = {
+	htype.VZ_NAME: __add_vz_client_args,
+}
+
+
+def __add_vz_service_args(parser):
+	"""Add Virtuozzo service-specific arguments"""
+	pass
+
+
+__service_args_funcs = {
+	htype.VZ_NAME: __add_vz_service_args,
+}
diff --git a/phaul/htype.py b/phaul/htype.py
index 77a7e32..7b274e2 100644
--- a/phaul/htype.py
+++ b/phaul/htype.py
@@ -8,11 +8,16 @@ import logging
 import importlib
 
 
+VZ_NAME = "vz"
+PID_NAME = "pid"
+LXC_NAME = "lxc"
+DOCKER_NAME = "docker"
+
 __haul_modules = {
-	"vz": "p_haul_vz",
-	"pid": "p_haul_pid",
-	"lxc": "p_haul_lxc",
-	"docker": "p_haul_docker",
+	VZ_NAME: "p_haul_vz",
+	PID_NAME: "p_haul_pid",
+	LXC_NAME: "p_haul_lxc",
+	DOCKER_NAME: "p_haul_docker",
 }
 
 
-- 
1.7.1



More information about the CRIU mailing list