From 6a88f32eea3850d58411b854ba102a2baa978158 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Mon, 14 May 2018 04:47:12 +0200 Subject: T633: build integration and minor fixes in the op mode command generator. --- .gitignore | 3 ++- Makefile | 18 ++++++++++++++++-- debian/rules | 13 ++++++++++--- python/vyos/util.py | 37 ------------------------------------- python/vyos/version.py | 37 +++++++++++++++++++++++++++++++++++++ schema/op-mode-definition.rnc | 5 ++--- schema/op-mode-definition.rng | 10 +++++++--- scripts/build-command-op-templates | 2 +- 8 files changed, 75 insertions(+), 50 deletions(-) delete mode 100644 python/vyos/util.py create mode 100644 python/vyos/version.py diff --git a/.gitignore b/.gitignore index 9082493d3..ff15b4fbb 100644 --- a/.gitignore +++ b/.gitignore @@ -104,7 +104,8 @@ ENV/ .mypy_cache/ # Autogenerated files -templates/* +templates-cfg/* +templates-op/* tests/templates/* # Debian packaging diff --git a/Makefile b/Makefile index de7c136eb..ad7107d3d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -TMPL_DIR := templates +TMPL_DIR := templates-cfg +OP_TMPL_DIR := templates-op .PHONY: interface_definitions .ONESHELL: @@ -13,9 +14,22 @@ interface_definitions: rm -f $(TMPL_DIR)/service/dns/node.def rm -f $(TMPL_DIR)/protocols/node.def +.PHONY: op_mode_definitions +.ONESHELL: +op_mode_definitions: + mkdir -p $(OP_TMPL_DIR) + + find $(CURDIR)/op-mode-definitions/ -type f | xargs -I {} $(CURDIR)/scripts/build-command-op-templates {} $(CURDIR)/schema/op-mode-definition.rng $(OP_TMPL_DIR) + + # XXX: delete top level op mode node.def's that now live in other packages + rm -f $(OP_TMPL_DIR)/show/node.def + rm -f $(OP_TMPL_DIR)/reset/node.def + rm -f $(OP_TMPL_DIR)/restart/node.def + .PHONY: all -all: interface_definitions +all: interface_definitions op_mode_definitions .PHONY: clean clean: rm -rf $(TMPL_DIR)/* + rm -rf $(OP_TMPL_DIR)/* diff --git a/debian/rules b/debian/rules index 5c3aab7f6..d10f6f450 100755 --- a/debian/rules +++ b/debian/rules @@ -2,26 +2,33 @@ DIR := debian/vyos-1x VYOS_SBIN_DIR := opt/vyatta/sbin/ +VYOS_BIN_DIR := opt/vyatta/bin/ VYOS_LIBEXEC_DIR := opt/vyatta/libexec VYOS_CFG_TMPL_DIR := /opt/vyatta/share/vyatta-cfg/templates +VYOS_OP_TMPL_DIR := /opt/vyatta/share/vyatta-op/templates %: dh $@ --with python3, --with quilt override_dh_auto_build: - make + make all override_dh_auto_install: dh_install -pvyos-1x cd python; python3 setup.py install --install-layout=deb --root ../$(DIR); cd .. - # Install configuration scripts + # Install scripts mkdir -p $(DIR)/$(VYOS_SBIN_DIR) + mkdir -p $(DIR)/$(VYOS_BIN_DIR) cp -r src/conf-mode/* $(DIR)/$(VYOS_SBIN_DIR) + cp -r src/op-mode/* $(DIR)/$(VYOS_BIN_DIR) # Install validators mkdir -p $(DIR)/$(VYOS_LIBEXEC_DIR)/validators cp -r src/validators/* $(DIR)/$(VYOS_LIBEXEC_DIR)/validators mkdir -p $(DIR)/$(VYOS_CFG_TMPL_DIR) - cp -r templates/* $(DIR)/$(VYOS_CFG_TMPL_DIR) + cp -r templates-cfg/* $(DIR)/$(VYOS_CFG_TMPL_DIR) + + mkdir -p $(DIR)/$(VYOS_OP_TMPL_DIR) + cp -r templates-op/* $(DIR)/$(VYOS_OP_TMPL_DIR) diff --git a/python/vyos/util.py b/python/vyos/util.py deleted file mode 100644 index b3eff3965..000000000 --- a/python/vyos/util.py +++ /dev/null @@ -1,37 +0,0 @@ -# Copyright (c) 2017 VyOS maintainers and contributors -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, including without limitation -# the rights to use, copy, modify, merge, publish, distribute, sublicense, -# and/or sell copies of the Software, and to permit persons to whom the Software -# is furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included -# in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS -# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -import json - -class ConfigError(Exception): - pass - - -def get_version_data(file='/opt/vyatta/etc/version.json'): - with open(file, 'r') as f: - version_data = json.load(f) - return version_data - -def get_version(file=None): - version_data = None - if file: - version_data = get_version_data(file=file) - else: - version_data = get_version_data() - return version_data["version"] diff --git a/python/vyos/version.py b/python/vyos/version.py new file mode 100644 index 000000000..b3eff3965 --- /dev/null +++ b/python/vyos/version.py @@ -0,0 +1,37 @@ +# Copyright (c) 2017 VyOS maintainers and contributors +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the Software +# is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +# OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +# IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import json + +class ConfigError(Exception): + pass + + +def get_version_data(file='/opt/vyatta/etc/version.json'): + with open(file, 'r') as f: + version_data = json.load(f) + return version_data + +def get_version(file=None): + version_data = None + if file: + version_data = get_version_data(file=file) + else: + version_data = get_version_data() + return version_data["version"] diff --git a/schema/op-mode-definition.rnc b/schema/op-mode-definition.rnc index 01276123c..9c84de0e4 100644 --- a/schema/op-mode-definition.rnc +++ b/schema/op-mode-definition.rnc @@ -52,8 +52,7 @@ tagNode = element tagNode leafNode = element leafNode { nodeNameAttr, - command, - properties + (command & properties) } # Normal and tag nodes may have children @@ -105,4 +104,4 @@ completionHelp = element completionHelp (element list { text })* & (element path { text })* & (element script { text })* -} \ No newline at end of file +} diff --git a/schema/op-mode-definition.rng b/schema/op-mode-definition.rng index 98a231e53..e9e7887cf 100644 --- a/schema/op-mode-definition.rng +++ b/schema/op-mode-definition.rng @@ -67,7 +67,9 @@ - + + + @@ -81,8 +83,10 @@ - - + + + + diff --git a/scripts/build-command-op-templates b/scripts/build-command-op-templates index 6b6688fba..72879fe74 100755 --- a/scripts/build-command-op-templates +++ b/scripts/build-command-op-templates @@ -145,7 +145,7 @@ def make_node_def(props, command): if command is not None: - node_def += "run: sudo sh -c {0}\n".format(command.text) + node_def += "run: sudo sh -c \"{0}\"\n".format(command.text) if debug: -- cgit v1.2.3