# Copyright 2019-2024 VyOS maintainers and contributors # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this library. If not, see . # 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! import re from vyos.configtree import ConfigTree from vyos.utils.process import cmd tz_base = ['system', 'time-zone'] def migrate(config: ConfigTree) -> None: if not config.exists(tz_base): # Nothing to do return tz = config.return_value(tz_base) # retrieve all valid timezones try: tz_datas = cmd('timedatectl list-timezones') 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)