From 477233cdb216399df00a0294c2bbdfaf4531aee6 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 6 Dec 2017 18:41:10 +0100 Subject: Add debian packaging files to .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 7a99e829a..9082493d3 100644 --- a/.gitignore +++ b/.gitignore @@ -106,3 +106,8 @@ ENV/ # Autogenerated files templates/* tests/templates/* + +# Debian packaging +debian/files +debian/vyos-1x +debian/vyos-1x.* -- cgit v1.2.3 From 8a482c1a98ec2959368eb9d3f88bf04358d90354 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 6 Dec 2017 18:44:22 +0100 Subject: Initial interface description for 'mdns repeater' --- interface-definitions/mdns-repeater.xml | 34 ++++++++++++++++++++++++++++++ src/conf-mode/vyos-update-mdns-repeater.py | 24 +++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 interface-definitions/mdns-repeater.xml create mode 100755 src/conf-mode/vyos-update-mdns-repeater.py diff --git a/interface-definitions/mdns-repeater.xml b/interface-definitions/mdns-repeater.xml new file mode 100644 index 000000000..abc5ee714 --- /dev/null +++ b/interface-definitions/mdns-repeater.xml @@ -0,0 +1,34 @@ + + + + + + + + + + Multicast DNS (mDNS) parameters + + + + + mDNS repeater configuration + 999 + + + + + Interface to repeat mdns advertisements to [REQUIRED] + + + + + + + + + + + + + diff --git a/src/conf-mode/vyos-update-mdns-repeater.py b/src/conf-mode/vyos-update-mdns-repeater.py new file mode 100755 index 000000000..56ccfb111 --- /dev/null +++ b/src/conf-mode/vyos-update-mdns-repeater.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2017 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# + +import os +import sys + +from vyos.config import Config +from vyos.util import ConfigError + -- cgit v1.2.3 From f5c24a9e91f8ea5e0983697e4350cead206cea4e Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 6 Dec 2017 19:01:29 +0100 Subject: Bugfix: 'multi:' statement must be on top of generated 'node.def' file If 'multi:' is not on the first line of the auto generated 'node.def' file, VyOS will throw a CLI error: get_parsed_tmpl: failed to parse tmpl [.../interfaces] DEBUG vexit_internal: get_parsed_tmpl: failed to parse tmpl [.../interfaces] --- scripts/build-command-templates | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/build-command-templates b/scripts/build-command-templates index 09c7dc8c4..ff0ce05f0 100755 --- a/scripts/build-command-templates +++ b/scripts/build-command-templates @@ -113,7 +113,7 @@ def get_properties(p): error_msg = p.find("constraintErrorMessage").text except: pass - + vce = p.findall("constraint") vc = [] for v in vce: @@ -180,12 +180,12 @@ def make_node_def(props): if "tag" in props: node_def += "tag:\n" - if "type" in props: - node_def += "type: {0}\n".format(props["type"]) - if "multi" in props: node_def += "multi:\n" + if "type" in props: + node_def += "type: {0}\n".format(props["type"]) + if "priority" in props: node_def += "priority: {0}\n".format(props["priority"]) @@ -236,7 +236,7 @@ def process_node(n, tmpl_dir): props["type"] = "txt" if node_type == "tagNode": props["tag"] = "True" - + with open(os.path.join(make_path(my_tmpl_dir), "node.def"), "w") as f: f.write(make_node_def(props)) -- cgit v1.2.3 From a545cd18f98ad747af26176f9b05cc325e4dd5ff Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 8 Dec 2017 18:54:15 +0100 Subject: Add 'vyos-update-mdns-repeater.py' functionality --- debian/control | 3 +- interface-definitions/mdns-repeater.xml | 2 +- src/conf-mode/vyos-config-mdns-repeater.py | 97 ++++++++++++++++++++++++++++++ src/conf-mode/vyos-update-mdns-repeater.py | 24 -------- 4 files changed, 100 insertions(+), 26 deletions(-) create mode 100755 src/conf-mode/vyos-config-mdns-repeater.py delete mode 100755 src/conf-mode/vyos-update-mdns-repeater.py diff --git a/debian/control b/debian/control index 33de6b7ef..a19cc80d4 100644 --- a/debian/control +++ b/debian/control @@ -8,6 +8,7 @@ Standards-Version: 3.9.6 Package: vyos-1x Architecture: all -Depends: python3, ${python3:Depends}, ${shlibs:Depends}, ${misc:Depends} +Depends: python3, ${python3:Depends}, python3-netifaces, + ${shlibs:Depends}, ${misc:Depends} Description: VyOS configuration scripts and data VyOS configuration scripts, interface definitions, and everything diff --git a/interface-definitions/mdns-repeater.xml b/interface-definitions/mdns-repeater.xml index abc5ee714..706906b37 100644 --- a/interface-definitions/mdns-repeater.xml +++ b/interface-definitions/mdns-repeater.xml @@ -10,7 +10,7 @@ Multicast DNS (mDNS) parameters - + mDNS repeater configuration 999 diff --git a/src/conf-mode/vyos-config-mdns-repeater.py b/src/conf-mode/vyos-config-mdns-repeater.py new file mode 100755 index 000000000..3f9eb1b2b --- /dev/null +++ b/src/conf-mode/vyos-config-mdns-repeater.py @@ -0,0 +1,97 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2017 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# + +import sys +import os +import netifaces +import time +import subprocess + +from vyos.config import Config +from vyos.util import ConfigError + +config_file = r'/etc/default/mdns-repeater' + +def get_config(): + interface_list = [] + + conf = Config() + conf.set_level('service mdns repeater') + if not conf.exists(''): + return interface_list + + if conf.exists('interfaces'): + intfs_names = conf.return_values('interfaces') + intfs_names=intfs_names.replace("'", "") + intfs_names=intfs_names.split() + + for name in intfs_names: + interface_list.append(name) + + return interface_list + +def verify(mdns): + # '0' interfaces are possible, think of service deletion. Only '1' is not supported! + if len(mdns) == 1: + raise ConfigError('At least 2 interfaces must be specified but %d given!' % len(mdns)) + + # For mdns-repeater to work it is essential that the interfaces + # have an IP address assigned + for intf in mdns: + try: + netifaces.ifaddresses(intf)[netifaces.AF_INET] + except KeyError as e: + raise ConfigError('No IP address configured for interface "%s"!' % intf) + + return None + +def generate(mdns): + config_header = '### Autogenerated by vyos-update-mdns-repeater.py on {tm} ###\n'.format(tm=time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())) + if len(mdns) > 0: + config_args = 'DAEMON_ARGS="' + ' '.join(str(e) for e in mdns) + '"\n' + else: + config_args = 'DAEMON_ARGS=""\n' + + # write new configuration file + f = open(config_file, 'w') + f.write(config_header) + f.write(config_args) + f.close() + + return None + +def apply(mdns): + systemd_cmd = ["sudo", "service", "mdns-repeater"] + + if len(mdns) == 0: + systemd_cmd.append("stop") + else: + systemd_cmd.append("restart") + + subprocess.call(systemd_cmd) + return None + +if __name__ == '__main__': + try: + c = get_config() + verify(c) + generate(c) + apply(c) + except ConfigError as e: + print(e) + sys.exit(1) diff --git a/src/conf-mode/vyos-update-mdns-repeater.py b/src/conf-mode/vyos-update-mdns-repeater.py deleted file mode 100755 index 56ccfb111..000000000 --- a/src/conf-mode/vyos-update-mdns-repeater.py +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env python3 -# -# Copyright (C) 2017 VyOS maintainers and contributors -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 or later as -# published by the Free Software Foundation. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . -# -# - -import os -import sys - -from vyos.config import Config -from vyos.util import ConfigError - -- cgit v1.2.3 From a919de476a97a9037c49207d04aae18118ef3fd7 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 9 Dec 2017 10:40:42 +0100 Subject: Update 'debian/changelog' --- debian/changelog | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/debian/changelog b/debian/changelog index 74d5f7148..bd910276b 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +vyos-1x (1.0.2) unstable; urgency=low + + * Added mdns-repeater configuration nodes + + -- Christian Poessinger Sat, 09 Dec 2017 10:39:35 +0100 + vyos-1x (1.0.1) unstable; urgency=low * Added the Python library for reading VyOS configs -- cgit v1.2.3