summaryrefslogtreecommitdiff
path: root/src/migration-scripts/dns-forwarding/3-to-4
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-03-29 10:33:30 +0200
committerGitHub <noreply@github.com>2023-03-29 10:33:30 +0200
commitc675fbf336365f70a7f783590daf70efca0f4941 (patch)
tree71acf469350c926780b1377d0dcc21568a290abd /src/migration-scripts/dns-forwarding/3-to-4
parent454a49dfc1e2c08f72e9f9ae9a4a90818be76ae3 (diff)
parent2bb5c5d0fd9ed07649b81a61e9c1a78a9f222405 (diff)
downloadvyos-1x-c675fbf336365f70a7f783590daf70efca0f4941.tar.gz
vyos-1x-c675fbf336365f70a7f783590daf70efca0f4941.zip
Merge pull request #1915 from indrajitr/pdns-port-round2
dns: T5115: Support custom port for name servers for forwarding zones
Diffstat (limited to 'src/migration-scripts/dns-forwarding/3-to-4')
-rwxr-xr-xsrc/migration-scripts/dns-forwarding/3-to-449
1 files changed, 49 insertions, 0 deletions
diff --git a/src/migration-scripts/dns-forwarding/3-to-4 b/src/migration-scripts/dns-forwarding/3-to-4
new file mode 100755
index 000000000..55165c2c5
--- /dev/null
+++ b/src/migration-scripts/dns-forwarding/3-to-4
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+# Copyright (C) 2023 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 <http://www.gnu.org/licenses/>.
+
+# T5115: migrate "service dns forwarding domain example.com server" to
+# "service dns forwarding domain example.com name-server"
+
+import sys
+from vyos.configtree import ConfigTree
+
+if (len(sys.argv) < 1):
+ print("Must specify file name!")
+ sys.exit(1)
+
+file_name = sys.argv[1]
+
+with open(file_name, 'r') as f:
+ config_file = f.read()
+
+config = ConfigTree(config_file)
+
+base = ['service', 'dns', 'forwarding', 'domain']
+if not config.exists(base):
+ # Nothing to do
+ sys.exit(0)
+
+for domain in config.list_nodes(base):
+ if config.exists(base + [domain, 'server']):
+ config.copy(base + [domain, 'server'], base + [domain, 'name-server'])
+ config.delete(base + [domain, 'server'])
+
+try:
+ with open(file_name, 'w') as f:
+ f.write(config.to_string())
+except OSError as e:
+ print("Failed to save the modified config: {}".format(e))
+ sys.exit(1)