summaryrefslogtreecommitdiff
path: root/src/migration-scripts/system/12-to-13
diff options
context:
space:
mode:
authorMarcus Hoff <marcus.hoff@ring2.dk>2020-09-26 13:19:37 +0200
committerMarcus Hoff <marcus.hoff@ring2.dk>2020-09-26 13:19:37 +0200
commit1141bee72677b25d18436975625d2d298be503ff (patch)
tree4b6dc8fe1a8ced931e1ba08c58a348abfcd85a6b /src/migration-scripts/system/12-to-13
parent45b30adfaaec7065f768d04085138a75a76ed376 (diff)
parent374724be64728101c262fcac1579beece63ee651 (diff)
downloadvyos-1x-1141bee72677b25d18436975625d2d298be503ff.tar.gz
vyos-1x-1141bee72677b25d18436975625d2d298be503ff.zip
Merge remote-tracking branch 'upstream/current' into current
Diffstat (limited to 'src/migration-scripts/system/12-to-13')
-rwxr-xr-xsrc/migration-scripts/system/12-to-1385
1 files changed, 31 insertions, 54 deletions
diff --git a/src/migration-scripts/system/12-to-13 b/src/migration-scripts/system/12-to-13
index 5b068f4fc..36311a19d 100755
--- a/src/migration-scripts/system/12-to-13
+++ b/src/migration-scripts/system/12-to-13
@@ -1,70 +1,47 @@
#!/usr/bin/env python3
-# Fixup non existent time-zones. Some systems have time-zone set to: Los*
-# (Los_Angeles), Den* (Denver), New* (New_York) ... but those are no real IANA
-# assigned time zones. In the past they have been silently remapped.
-#
-# Time to clean it up!
-#
-# Migrate all configured timezones to real IANA assigned timezones!
+# converts 'set system syslog host <address>:<port>'
+# to 'set system syslog host <address> port <port>'
-import re
import sys
+import re
from vyos.configtree import ConfigTree
-from vyos.util import cmd
-
if (len(sys.argv) < 1):
- print("Must specify file name!")
- sys.exit(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_file = f.read()
config = ConfigTree(config_file)
-tz_base = ['system', 'time-zone']
-if not config.exists(tz_base):
- # Nothing to do
- sys.exit(0)
-else:
- tz = config.return_value(tz_base)
+cbase = ['system', 'syslog', 'host']
- # retrieve all valid timezones
- try:
- tz_datas = cmd('find /usr/share/zoneinfo/posix -type f -or -type l | sed -e s:/usr/share/zoneinfo/posix/::')
- except OSError:
- tz_datas = ''
- tz_data = tz_datas.split('\n')
-
- if re.match(r'[Ll][Oo][Ss].+', tz):
- tz = 'America/Los_Angeles'
- elif re.match(r'[Dd][Ee][Nn].+', tz):
- tz = 'America/Denver'
- elif re.match(r'[Hh][Oo][Nn][Oo].+', tz):
- tz = 'Pacific/Honolulu'
- elif re.match(r'[Nn][Ee][Ww].+', tz):
- tz = 'America/New_York'
- elif re.match(r'[Cc][Hh][Ii][Cc]*.+', tz):
- tz = 'America/Chicago'
- elif re.match(r'[Aa][Nn][Cc].+', tz):
- tz = 'America/Anchorage'
- elif re.match(r'[Pp][Hh][Oo].+', tz):
- tz = 'America/Phoenix'
- elif re.match(r'GMT(.+)?', tz):
- tz = 'Etc/' + tz
- elif tz not in tz_data:
- # assign default UTC timezone
- tz = 'UTC'
-
- # replace timezone data is required
- config.set(tz_base, value=tz)
+if not config.exists(cbase):
+ sys.exit(0)
- 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)
+for host in config.list_nodes(cbase):
+ if re.search(':[0-9]{1,5}$',host):
+ h = re.search('^[a-zA-Z\-0-9\.]+', host).group(0)
+ p = re.sub(':', '', re.search(':[0-9]+$', host).group(0))
+ config.set(cbase + [h])
+ config.set(cbase + [h, 'port'], value=p)
+ for fac in config.list_nodes(cbase + [host, 'facility']):
+ config.set(cbase + [h, 'facility', fac])
+ config.set_tag(cbase + [h, 'facility'])
+ if config.exists(cbase + [host, 'facility', fac, 'protocol']):
+ proto = config.return_value(cbase + [host, 'facility', fac, 'protocol'])
+ config.set(cbase + [h, 'facility', fac, 'protocol'], value=proto)
+ if config.exists(cbase + [host, 'facility', fac, 'level']):
+ lvl = config.return_value(cbase + [host, 'facility', fac, 'level'])
+ config.set(cbase + [h, 'facility', fac, 'level'], value=lvl)
+ config.delete(cbase + [host])
+
+try:
+ open(file_name,'w').write(config.to_string())
+except OSError as e:
+ print("Failed to save the modified config: {}".format(e))
+ sys.exit(1)