[CRIU] [PATCH 02/10] p.haul: add p.haul-wrap script
Nikita Spiridonov
nspiridonov at odin.com
Fri Oct 9 10:11:34 PDT 2015
p.haul-wrap is a helper script which perform primitive connections
establishment and call p.haul or p.haul-service specifying created
connections via command line arguments. Needed for testing purposes.
Signed-off-by: Nikita Spiridonov <nspiridonov at odin.com>
---
p.haul-wrap | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 100 insertions(+), 0 deletions(-)
create mode 100755 p.haul-wrap
diff --git a/p.haul-wrap b/p.haul-wrap
new file mode 100755
index 0000000..1c78c56
--- /dev/null
+++ b/p.haul-wrap
@@ -0,0 +1,100 @@
+#!/usr/bin/env python
+
+import os
+import socket
+import argparse
+
+# Usage
+# p.haul-wrap service
+# p.haul-wrap client <destination> <type> <id>
+#
+# p.haul-wrap is a helper script which perform primitive connections
+# establishment and call p.haul or p.haul-service specifying created
+# connections via command line arguments. Use it exclusively for testing
+# purposes!
+#
+# E.g.
+# p.haul-wrap service
+# p.haul-wrap client 10.0.0.1 vz 100
+#
+
+default_rpc_port = 12345
+default_service_bind_addr = "0.0.0.0"
+
+def run_phaul_service(args, unknown_args):
+ """Run p.haul-service"""
+
+ print "Waiting for connection..."
+
+ # Establish connection
+ host = args.bind_addr, args.bind_port
+ server_sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ server_sk.bind(host)
+ server_sk.listen(8)
+ connection_sks = [None, None, None]
+ for i in range(len(connection_sks)):
+ connection_sks[i], dummy = server_sk.accept()
+
+ # Organize p.haul-service args
+ target_args = [args.path]
+ target_args.extend(unknown_args)
+ target_args.extend(["--fdrpc", str(connection_sks[0].fileno()),
+ "--fdmem", str(connection_sks[1].fileno()),
+ "--fdfs", str(connection_sks[2].fileno())])
+
+ # Call p.haul-service
+ print "Exec p.haul-service: {0}".format(" ".join(target_args))
+ os.system(" ".join(target_args))
+
+
+def run_phaul_client(args, unknown_args):
+ """Run p.haul"""
+
+ print "Establish connection..."
+
+ # Establish connection
+ dest_host = args.to, args.port
+
+ connection_sks = [None, None, None]
+ for i in range(len(connection_sks)):
+ connection_sks[i] = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ connection_sks[i].connect(dest_host)
+
+ # Organize p.haul args
+ target_args = [args.path]
+ target_args.extend(unknown_args)
+ target_args.extend(["--to", args.to,
+ "--fdrpc", str(connection_sks[0].fileno()),
+ "--fdmem", str(connection_sks[1].fileno()),
+ "--fdfs", str(connection_sks[2].fileno())])
+
+ # Call p.haul
+ print "Exec p.haul: {0}".format(" ".join(target_args))
+ os.system(" ".join(target_args))
+
+# Initialize arguments parser
+parser = argparse.ArgumentParser("Process HAULer wrap")
+subparsers = parser.add_subparsers(title="Subcommands")
+
+# Initialize service mode arguments parser
+service_parser = subparsers.add_parser("service", help="Service mode")
+service_parser.set_defaults(func=run_phaul_service)
+service_parser.add_argument("--bind-addr", help="IP to bind to", type=str,
+ default=default_service_bind_addr)
+service_parser.add_argument("--bind-port", help="Port to bind to", type=int,
+ default=default_rpc_port)
+service_parser.add_argument("--path", help="Path to p.haul-service script",
+ default=os.path.join(os.path.dirname(__file__), "p.haul-service"))
+
+# Initialize client mode arguments parser
+client_parser = subparsers.add_parser("client", help="Client mode")
+client_parser.set_defaults(func=run_phaul_client)
+client_parser.add_argument("to", help="IP where to haul")
+client_parser.add_argument("--port", help="Port where to haul", type=int,
+ default=default_rpc_port)
+client_parser.add_argument("--path", help="Path to p.haul script",
+ default=os.path.join(os.path.dirname(__file__), "p.haul"))
+
+# Parse arguments and run wrap in specified mode
+args, unknown_args = parser.parse_known_args()
+args.func(args, unknown_args)
--
1.7.1
More information about the CRIU
mailing list