aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelley Spoon <kelley.spoon@linaro.org>2018-04-05 11:30:59 -0500
committerKelley Spoon <kelley.spoon@linaro.org>2018-04-05 11:30:59 -0500
commita463dc9bd72d223425dc05a588555690a9187b9b (patch)
treeb8f70d59b9e459727907e34dfca1694d7725c225
parent07b8429f06f87b27771d9375764a293c319be761 (diff)
hostsdns: add support for command line args
Add ability for event-watcher.py to run in host-only mode and to run without continuous polling. Change-Id: Idd08a2bc1849af37c2c0e82ee1ef7b1e9c4c2e0c
-rwxr-xr-xhostsdns/event-watcher.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/hostsdns/event-watcher.py b/hostsdns/event-watcher.py
index b51ec76..3446777 100755
--- a/hostsdns/event-watcher.py
+++ b/hostsdns/event-watcher.py
@@ -1,16 +1,19 @@
#!/usr/bin/env python
-import os
-import sys
+import os, sys, json, re
import docker
-import json
-import re
+import argparse
-if os.path.exists("/.dockerenv"):
+parser = argparse.ArgumentParser( description="Manage host entries for docker containers")
+parser.add_argument('-n', '--native', help='run service on docker host', action='store_true' , dest='NATIVE_MODE')
+parser.add_argument('-o','-1', '--once', help='run once and exit (no continuous polling)', action='store_true', dest='ONCE_MODE')
+args = parser.parse_args()
+
+if not args.NATIVE_MODE and os.path.exists("/.dockerenv"):
print "Found /.dockerenv... reading from /tmp/hosts"
HOSTS_FILE="/tmp/hosts"
else:
- print "No /.dockerenv found... reading from /etc/hosts"
+ print "Running in native mode... reading from /etc/hosts"
HOSTS_FILE="/etc/hosts"
if os.environ.get("DOCKER_HOST"):
@@ -93,6 +96,9 @@ def container_remove(name):
for container in client.containers.list():
container_add(container.name)
+if args.ONCE_MODE:
+ sys.exit(0)
+
# calling events will basically poll forever, so after this we're
# essentially in not-quite-a-daemon mode
for event_json in client.events():