summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzsdc <taras@vyos.io>2019-12-20 13:17:44 +0200
committerzsdc <taras@vyos.io>2019-12-20 13:17:44 +0200
commit7b07a466a07735277757e38d3eed39a96c0b50ed (patch)
tree6056d89fe28f29fca6acbe8c478ac9c1b3105ead
parentf8bdac63d636bd035ee4bcd45b61dcaf9137ee86 (diff)
parent8f66317eacbce914e727c25744de2e54f300cab2 (diff)
downloadvyos-1x-7b07a466a07735277757e38d3eed39a96c0b50ed.tar.gz
vyos-1x-7b07a466a07735277757e38d3eed39a96c0b50ed.zip
Merge remote-tracking branch 'upstream/current' into T1890
-rw-r--r--debian/control1
-rwxr-xr-xsrc/services/vyos-hostsd36
2 files changed, 24 insertions, 13 deletions
diff --git a/debian/control b/debian/control
index fa9f3b489..06eb1b8df 100644
--- a/debian/control
+++ b/debian/control
@@ -73,6 +73,7 @@ Depends: python3,
iw,
crda,
wireless-regdb,
+ pmacct (>= 1.6.0),
${shlibs:Depends},
${misc:Depends}
Description: VyOS configuration scripts and data
diff --git a/src/services/vyos-hostsd b/src/services/vyos-hostsd
index 5fb7a68ab..a655762e9 100755
--- a/src/services/vyos-hostsd
+++ b/src/services/vyos-hostsd
@@ -23,13 +23,25 @@ import json
import signal
import traceback
import re
-
+import logging
import zmq
import jinja2
debug = True
+# Configure logging
+logger = logging.getLogger(__name__)
+# set stream as output
+logs_handler = logging.StreamHandler()
+logger.addHandler(logs_handler)
+
+if debug:
+ logger.setLevel(logging.DEBUG)
+else:
+ logger.setLevel(logging.INFO)
+
+
DATA_DIR = "/var/lib/vyos/"
STATE_FILE = os.path.join(DATA_DIR, "hostsd.state")
@@ -107,12 +119,12 @@ STATE = {
def make_resolv_conf(data):
resolv_conf = resolv_tmpl.render(data)
- print("Writing /etc/resolv.conf")
+ logger.info("Writing /etc/resolv.conf")
with open(RESOLV_CONF_FILE, 'w') as f:
f.write(resolv_conf)
def make_hosts_file(state):
- print("Writing /etc/hosts")
+ logger.info("Writing /etc/hosts")
hosts = hosts_tmpl.render(state)
with open(HOSTS_FILE, 'w') as f:
f.write(hosts)
@@ -228,13 +240,13 @@ def handle_message(msg_json):
make_resolv_conf(STATE)
make_hosts_file(STATE)
- print("Saving state to {0}".format(STATE_FILE))
+ logger.info("Saving state to {0}".format(STATE_FILE))
with open(STATE_FILE, 'w') as f:
json.dump(STATE, f)
def exit_handler(sig, frame):
""" Clean up the state when shutdown correctly """
- print("Cleaning up state")
+ logger.info("Cleaning up state")
os.unlink(STATE_FILE)
sys.exit(0)
@@ -250,8 +262,8 @@ if __name__ == '__main__':
data = json.load(f)
STATE = data
except:
- print(traceback.format_exc())
- print("Failed to load the state file, using default")
+ logger.exception(traceback.format_exc())
+ logger.exception("Failed to load the state file, using default")
context = zmq.Context()
socket = context.socket(zmq.REP)
@@ -260,9 +272,8 @@ if __name__ == '__main__':
while True:
# Wait for next request from client
message = socket.recv().decode()
- print("Received a configuration change request")
- if debug:
- print("Request data: {0}".format(message))
+ logger.info("Received a configuration change request")
+ logger.debug("Request data: {0}".format(message))
resp = {}
@@ -272,11 +283,10 @@ if __name__ == '__main__':
except ValueError as e:
resp['error'] = str(e)
except:
- print(traceback.format_exc())
+ logger.exception(traceback.format_exc())
resp['error'] = "Internal error"
- if debug:
- print("Sent response: {0}".format(resp))
+ logger.debug("Sent response: {0}".format(resp))
# Send reply back to client
socket.send(json.dumps(resp).encode())