| |
@@ -19,14 +19,16 @@
|
| |
parser = argparse.ArgumentParser(description="Inventory for a container image in a registry")
|
| |
parser.add_argument("--list", action="store_true", help="Verbose output")
|
| |
parser.add_argument('--host', help="Get host variables")
|
| |
+ parser.add_argument('--docker-extra-args', help="Extra docker arguments for launching container",
|
| |
+ default=os.environ.get("TEST_DOCKER_EXTRA_ARGS", ""))
|
| |
parser.add_argument("subjects", nargs="*", default=shlex.split(os.environ.get("TEST_SUBJECTS", "")))
|
| |
opts = parser.parse_args()
|
| |
|
| |
try:
|
| |
if opts.host:
|
| |
- name, data = host(opts.host)
|
| |
+ name, data = host(opts.host, opts.docker_extra_args)
|
| |
else:
|
| |
- data = list(opts.subjects)
|
| |
+ data = list(opts.subjects, opts.docker_extra_args)
|
| |
sys.stdout.write(json.dumps(data, indent=4, separators=(',', ': ')))
|
| |
except RuntimeError, ex:
|
| |
sys.stderr.write("{0}: {1}\n".format(os.path.basename(sys.argv[0]), str(ex)))
|
| |
@@ -34,19 +36,19 @@
|
| |
|
| |
return 0
|
| |
|
| |
- def list(subjects):
|
| |
+ def list(subjects, docker_extra_args):
|
| |
hosts = [ ]
|
| |
variables = { }
|
| |
for subject in subjects:
|
| |
if subject.startswith("docker:"):
|
| |
image = subject[7:]
|
| |
- name, vars = host(image)
|
| |
+ name, vars = host(image, docker_extra_args)
|
| |
if vars:
|
| |
hosts.append(name)
|
| |
variables[name] = vars
|
| |
return { "localhost": { "hosts": hosts, "vars": { } }, "subjects": { "hosts": hosts, "vars": { } }, "_meta": { "hostvars": variables } }
|
| |
|
| |
- def host(image):
|
| |
+ def host(image, docker_extra_args):
|
| |
null = open(os.devnull, 'w')
|
| |
|
| |
try:
|
| |
@@ -65,11 +67,18 @@
|
| |
except ValueError:
|
| |
diagnose = 0
|
| |
|
| |
+ # Check for any additional arguments to include when starting docker container
|
| |
+ try:
|
| |
+ extra_arg_list = shlex.split(docker_extra_args)
|
| |
+ except ValueError:
|
| |
+ raise RuntimeError("Could not parse DOCKER_EXTRA_ARGS")
|
| |
+
|
| |
sys.stderr.write("Launching Docker container for {0}\n".format(image))
|
| |
|
| |
# And launch the actual container
|
| |
cmd = [
|
| |
"/usr/bin/docker", "run", "--detach", "--cidfile={0}".format(cidfile),
|
| |
+ ] + extra_arg_list + [
|
| |
"--entrypoint=/bin/sh", image, "-c", "sleep 1000000"
|
| |
]
|
| |
|
| |
This is the first step needed to address issue #30. Actually, it's all that's needed to address the issue--the rest is left up to a custom inventory script to be written and included in the
tests/inventory
directory.