Beispiel #1
0
    def refresh(self):
        self._shown = True

        #update the displayed time
        self._update_datetime_timer_id = GLib.timeout_add_seconds(1,
                                                    self._update_datetime)
        self._start_updating_timer_id = None

        if is_valid_timezone(self.data.timezone.timezone):
            self._tzmap.set_timezone(self.data.timezone.timezone)

        self._update_datetime()

        has_active_network = nm.nm_is_connected()
        if not has_active_network:
            self._show_no_network_warning()
        else:
            self.clear_info()
            gtk_call_once(self._config_dialog.refresh_servers_state)

        if flags.can_touch_runtime_system("get NTP service state"):
            ntp_working = has_active_network and iutil.service_running(NTP_SERVICE)
        else:
            ntp_working = not self.data.timezone.nontp

        self._ntpSwitch.set_active(ntp_working)
Beispiel #2
0
    def _refresh(self):
        try:
            reply = urllib2.urlopen(
                self.API_URL, timeout=constants.NETWORK_CONNECTION_TIMEOUT)
            if reply:
                json_reply = json.load(reply)
                territory = json_reply.get("country_code", None)
                timezone_source = "GeoIP"
                timezone_code = json_reply.get("time_zone", None)

                if timezone_code is not None:
                    # the timezone code is returned as Unicode,
                    # it needs to be converted to UTF-8 encoded string,
                    # otherwise some string processing in Anaconda might fail
                    timezone_code = timezone_code.encode("utf8")

                # check if the timezone returned by the API is valid
                if not is_valid_timezone(timezone_code):
                    # try to get a timezone from the territory code
                    timezone_code = get_preferred_timezone(territory)
                    timezone_source = "territory code"
                if territory or timezone_code:
                    self._set_result(
                        LocationResult(territory_code=territory,
                                       timezone=timezone_code,
                                       timezone_source=timezone_source))
        except urllib2.HTTPError as e:
            log.debug("Geoloc: HTTPError for Fedora GeoIP API lookup:\n%s", e)
        except urllib2.URLError as e:
            log.debug("Geoloc: URLError for Fedora GeoIP API lookup:\n%s", e)
        except ValueError as e:
            log.debug("Geoloc: Unable to decode GeoIP JSON:\n%s", e)
Beispiel #3
0
    def _refresh(self):
        try:
            reply = requests.get(self.API_URL, timeout=constants.NETWORK_CONNECTION_TIMEOUT, verify=True)
            if reply.status_code == requests.codes.ok:
                json_reply = reply.json()
                territory = json_reply.get("country_code", None)
                timezone_source = "GeoIP"
                timezone_code = json_reply.get("time_zone", None)

                if timezone_code is not None:
                    # the timezone code is returned as Unicode,
                    # it needs to be converted to UTF-8 encoded string,
                    # otherwise some string processing in Anaconda might fail
                    timezone_code = timezone_code.encode("utf8")

                # check if the timezone returned by the API is valid
                if not is_valid_timezone(timezone_code):
                    # try to get a timezone from the territory code
                    timezone_code = get_preferred_timezone(territory)
                    timezone_source = "territory code"
                if territory or timezone_code:
                    self._set_result(LocationResult(
                        territory_code=territory,
                        timezone=timezone_code,
                        timezone_source=timezone_source))
            else:
                log.error("Geoloc: Fedora GeoIP API lookup failed with status code: %s", reply.status_code)
        except requests.exceptions.RequestException as e:
            log.debug("Geoloc: RequestException for Fedora GeoIP API lookup:\n%s", e)
        except ValueError as e:
            log.debug("Geoloc: Unable to decode GeoIP JSON:\n%s", e)
Beispiel #4
0
    def refresh(self):
        self._shown = True

        # update the displayed time
        self._update_datetime_timer = Timer()
        self._update_datetime_timer.timeout_sec(1, self._update_datetime)
        self._start_updating_timer = None

        kickstart_timezone = self._timezone_module.proxy.Timezone

        if is_valid_timezone(kickstart_timezone):
            self._tzmap.set_timezone(kickstart_timezone)
            time.tzset()

        self._update_datetime()

        has_active_network = self._network_module.proxy.Connected
        if not has_active_network:
            self._show_no_network_warning()
        else:
            self.clear_info()
            gtk_call_once(self._config_dialog.refresh_servers_state)

        if conf.system.can_set_time_synchronization:
            ntp_working = has_active_network and util.service_running(
                NTP_SERVICE)
        else:
            ntp_working = self._timezone_module.proxy.NTPEnabled

        self._ntpSwitch.set_active(ntp_working)
Beispiel #5
0
 def _correct_timezone(self):
     """Ensure the timezone is valid."""
     if not is_valid_timezone(self._timezone):
         # this should never happen, but for pity's sake
         log.warning("Timezone %s set in kickstart is not valid, "
                     "falling back to default (America/New_York).", self._timezone)
         self._timezone = "America/New_York"
Beispiel #6
0
    def refresh(self):
        self._shown = True

        # update the displayed time
        self._update_datetime_timer = Timer()
        self._update_datetime_timer.timeout_sec(1, self._update_datetime)
        self._start_updating_timer = None

        kickstart_timezone = self._timezone_module.proxy.Timezone

        if is_valid_timezone(kickstart_timezone):
            self._tzmap.set_timezone(kickstart_timezone)
            time.tzset()

        self._update_datetime()

        has_active_network = self._network_module.proxy.Connected
        if not has_active_network:
            self._show_no_network_warning()
        else:
            self.clear_info()
            gtk_call_once(self._config_dialog.refresh_servers_state)

        if conf.system.can_set_time_synchronization:
            ntp_working = has_active_network and util.service_running(NTP_SERVICE)
        else:
            ntp_working = self._timezone_module.proxy.NTPEnabled

        self._ntpSwitch.set_active(ntp_working)
Beispiel #7
0
    def _refresh(self):
        try:
            reply = self._session.get(
                self.API_URL,
                timeout=constants.NETWORK_CONNECTION_TIMEOUT,
                verify=True)
            if reply.status_code == requests.codes.ok:
                json_reply = reply.json()
                territory = json_reply.get("country_code", None)
                timezone_source = "GeoIP"
                timezone_code = json_reply.get("time_zone", None)

                # check if the timezone returned by the API is valid
                if not is_valid_timezone(timezone_code):
                    # try to get a timezone from the territory code
                    timezone_code = get_preferred_timezone(territory)
                    timezone_source = "territory code"
                if territory or timezone_code:
                    self._set_result(
                        LocationResult(territory_code=territory,
                                       timezone=timezone_code,
                                       timezone_source=timezone_source))
            else:
                log.error(
                    "Geoloc: Fedora GeoIP API lookup failed with status code: %s",
                    reply.status_code)
        except requests.exceptions.RequestException as e:
            log.debug(
                "Geoloc: RequestException for Fedora GeoIP API lookup:\n%s", e)
        except ValueError as e:
            log.debug("Geoloc: Unable to decode GeoIP JSON:\n%s", e)
Beispiel #8
0
    def refresh(self):
        self._shown = True

        #update the displayed time
        self._update_datetime_timer_id = GLib.timeout_add_seconds(
            1, self._update_datetime)
        self._start_updating_timer_id = None

        if is_valid_timezone(self.data.timezone.timezone):
            self._tzmap.set_timezone(self.data.timezone.timezone)

        self._update_datetime()

        has_active_network = nm.nm_is_connected()
        if not has_active_network:
            self._show_no_network_warning()
        else:
            self.clear_info()
            gtk_call_once(self._config_dialog.refresh_servers_state)

        if flags.can_touch_runtime_system("get NTP service state"):
            ntp_working = has_active_network and iutil.service_running(
                NTP_SERVICE)
        else:
            ntp_working = not self.data.timezone.nontp

        self._ntpSwitch.set_active(ntp_working)
Beispiel #9
0
    def _refresh(self):
        try:
            reply = urllib2.urlopen(self.API_URL, timeout=
                                    constants.NETWORK_CONNECTION_TIMEOUT)
            if reply:
                json_reply = json.load(reply)
                territory = json_reply.get("country_code", None)
                timezone_source = "GeoIP"
                timezone_code = json_reply.get("time_zone", None)

                if timezone_code is not None:
                    # the timezone code is returned as Unicode,
                    # it needs to be converted to UTF-8 encoded string,
                    # otherwise some string processing in Anaconda might fail
                    timezone_code = timezone_code.encode("utf8")

                # check if the timezone returned by the API is valid
                if not is_valid_timezone(timezone_code):
                    # try to get a timezone from the territory code
                    timezone_code = get_preferred_timezone(territory)
                    timezone_source = "territory code"
                if territory or timezone_code:
                    self._set_result(LocationResult(
                        territory_code=territory,
                        timezone=timezone_code,
                        timezone_source=timezone_source))
        except urllib2.HTTPError as e:
            log.debug("Geoloc: HTTPError for Fedora GeoIP API lookup:\n%s (%s)",
                      e, self.API_URL)
        except urllib2.URLError as e:
            log.debug("Geoloc: URLError for Fedora GeoIP API lookup:\n%s (%s)",
                      e, self.API_URL)
    def test_all_timezones_valid(self):
        """Check if all returned timezones are considered valid timezones."""

        for (region,
             zones) in timezone.get_all_regions_and_timezones().items():
            for zone in zones:
                assert timezone.is_valid_timezone(region + "/" + zone)
Beispiel #11
0
 def status(self):
     if self.data.timezone.timezone:
         if is_valid_timezone(self.data.timezone.timezone):
             return _("%s timezone") % self.data.timezone.timezone
         else:
             return _("Invalid timezone")
     elif self._tzmap.get_timezone():
         return _("%s timezone") % self._tzmap.get_timezone()
     else:
         return _("Nothing selected")
 def status(self):
     if self.data.timezone.timezone:
         if timezone.is_valid_timezone(self.data.timezone.timezone):
             return _("%s timezone") % self.data.timezone.timezone
         else:
             return _("Invalid timezone")
     elif self._tzmap.get_timezone():
         return _("%s timezone") % self._tzmap.get_timezone()
     else:
         return _("Nothing selected")
    def refresh(self):
        self._shown = True

        # update the displayed time
        self._update_datetime_timer_id = GLib.timeout_add_seconds(1, self._update_datetime)
        self._start_updating_timer_id = None

        if is_valid_timezone(self.data.timezone.timezone):
            self._tzmap.set_timezone(self.data.timezone.timezone)

        self._update_datetime()
    def refresh(self):
        self._shown = True

        #update the displayed time
        self._update_datetime_timer_id = GLib.timeout_add_seconds(
            1, self._update_datetime)
        self._start_updating_timer_id = None

        if is_valid_timezone(self.data.timezone.timezone):
            self._tzmap.set_timezone(self.data.timezone.timezone)

        self._update_datetime()
Beispiel #15
0
 def status(self):
     if self.data.timezone.timezone:
         if is_valid_timezone(self.data.timezone.timezone):
             return _("%s timezone") % get_xlated_timezone(self.data.timezone.timezone)
         else:
             return _("Invalid timezone")
     else:
         location = self._tzmap.get_location()
         if location and location.get_property("zone"):
             return _("%s timezone") % get_xlated_timezone(location.get_property("zone"))
         else:
             return _("Nothing selected")
Beispiel #16
0
    def _initialize(self):
        for day in xrange(1, 32):
            self.add_to_store(self._daysStore, day)

        for i in xrange(1, 13):
            #a bit hacky way, but should return the translated string
            #TODO: how to handle language change? Clear and populate again?
            month = datetime.date(2000, i, 1).strftime('%B')
            self.add_to_store(self._monthsStore, month)
            self._months_nums[month] = i

        for year in xrange(1990, 2051):
            self.add_to_store(self._yearsStore, year)

        cities = set()
        xlated_regions = ((region, get_xlated_timezone(region))
                          for region in self._regions_zones.iterkeys())
        for region, xlated in sorted(xlated_regions, cmp=_compare_regions):
            self.add_to_store_xlated(self._regionsStore, region, xlated)
            for city in self._regions_zones[region]:
                cities.add((city, get_xlated_timezone(city)))

        for city, xlated in sorted(cities, cmp=_compare_cities):
            self.add_to_store_xlated(self._citiesStore, city, xlated)

        if self._radioButton24h.get_active():
            self._set_amPm_part_sensitive(False)

        self._update_datetime_timer_id = None
        if is_valid_timezone(self.data.timezone.timezone):
            self._set_timezone(self.data.timezone.timezone)
        elif not flags.flags.automatedInstall:
            log.warning(
                "%s is not a valid timezone, falling back to default (%s)",
                self.data.timezone.timezone, DEFAULT_TZ)
            self._set_timezone(DEFAULT_TZ)
            self.data.timezone.timezone = DEFAULT_TZ

        if not flags.can_touch_runtime_system("modify system time and date"):
            self._set_date_time_setting_sensitive(False)

        self._config_dialog = NTPconfigDialog(self.data)
        self._config_dialog.initialize()

        time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT)
        if time_init_thread is not None:
            hubQ.send_message(self.__class__.__name__,
                              _("Restoring hardware time..."))
            threadMgr.wait(constants.THREAD_TIME_INIT)

        hubQ.send_ready(self.__class__.__name__, False)
Beispiel #17
0
    def status(self):
        kickstart_timezone = self._timezone_module.Timezone

        if kickstart_timezone:
            if is_valid_timezone(kickstart_timezone):
                return _("%s timezone") % get_xlated_timezone(kickstart_timezone)
            else:
                return _("Invalid timezone")
        else:
            location = self._tzmap.get_location()
            if location and location.get_property("zone"):
                return _("%s timezone") % get_xlated_timezone(location.get_property("zone"))
            else:
                return _("Nothing selected")
Beispiel #18
0
    def status(self):
        kickstart_timezone = self._timezone_module.proxy.Timezone

        if kickstart_timezone:
            if is_valid_timezone(kickstart_timezone):
                return _("%s timezone") % get_xlated_timezone(kickstart_timezone)
            else:
                return _("Invalid timezone")
        else:
            location = self._tzmap.get_location()
            if location and location.get_property("zone"):
                return _("%s timezone") % get_xlated_timezone(location.get_property("zone"))
            else:
                return _("Nothing selected")
    def _initialize(self):
        for day in xrange(1, 32):
            self.add_to_store(self._daysStore, day)

        for i in xrange(1, 13):
            #a bit hacky way, but should return the translated string
            #TODO: how to handle language change? Clear and populate again?
            month = datetime.date(2000, i, 1).strftime('%B')
            self.add_to_store(self._monthsStore, month)
            self._months_nums[month] = i

        for year in xrange(1990, 2051):
            self.add_to_store(self._yearsStore, year)

        cities = set()
        xlated_regions = ((region, get_xlated_timezone(region))
                          for region in self._regions_zones.iterkeys())
        for region, xlated in sorted(xlated_regions, cmp=_compare_regions):
            self.add_to_store_xlated(self._regionsStore, region, xlated)
            for city in self._regions_zones[region]:
                cities.add((city, get_xlated_timezone(city)))

        for city, xlated in sorted(cities, cmp=_compare_cities):
            self.add_to_store_xlated(self._citiesStore, city, xlated)

        if self._radioButton24h.get_active():
            self._set_amPm_part_sensitive(False)

        self._update_datetime_timer_id = None
        if is_valid_timezone(self.data.timezone.timezone):
            self._set_timezone(self.data.timezone.timezone)
        elif not flags.flags.automatedInstall:
            log.warning("%s is not a valid timezone, falling back to default (%s)",
                        self.data.timezone.timezone, DEFAULT_TZ)
            self._set_timezone(DEFAULT_TZ)
            self.data.timezone.timezone = DEFAULT_TZ

        if not flags.can_touch_runtime_system("modify system time and date"):
            self._set_date_time_setting_sensitive(False)

        self._config_dialog = NTPconfigDialog(self.data)
        self._config_dialog.initialize()

        time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT)
        if time_init_thread is not None:
            hubQ.send_message(self.__class__.__name__,
                             _("Restoring hardware time..."))
            threadMgr.wait(constants.THREAD_TIME_INIT)

        hubQ.send_ready(self.__class__.__name__, False)
Beispiel #20
0
    def _initialize(self):
        # a bit hacky way, but should return the translated strings
        for i in range(1, 32):
            day = datetime.date(2000, 1, i).strftime(self._day_format)
            self.add_to_store_idx(self._daysStore, i, day)

        for i in range(1, 13):
            month = datetime.date(2000, i, 1).strftime(self._month_format)
            self.add_to_store_idx(self._monthsStore, i, month)

        for i in range(1990, 2051):
            year = datetime.date(i, 1, 1).strftime(self._year_format)
            self.add_to_store_idx(self._yearsStore, i, year)

        cities = set()
        xlated_regions = ((region, get_xlated_timezone(region))
                          for region in self._regions_zones.keys())
        for region, xlated in sorted(
                xlated_regions, key=functools.cmp_to_key(_compare_regions)):
            self.add_to_store_xlated(self._regionsStore, region, xlated)
            for city in self._regions_zones[region]:
                cities.add((city, get_xlated_timezone(city)))

        for city, xlated in sorted(cities,
                                   key=functools.cmp_to_key(_compare_cities)):
            self.add_to_store_xlated(self._citiesStore, city, xlated)

        self._update_datetime_timer = None
        kickstart_timezone = self._timezone_module.proxy.Timezone
        if is_valid_timezone(kickstart_timezone):
            self._set_timezone(kickstart_timezone)
        elif not flags.flags.automatedInstall:
            log.warning(
                "%s is not a valid timezone, falling back to default (%s)",
                kickstart_timezone, DEFAULT_TZ)
            self._set_timezone(DEFAULT_TZ)
            self._timezone_module.proxy.SetTimezone(DEFAULT_TZ)

        time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT)
        if time_init_thread is not None:
            hubQ.send_message(self.__class__.__name__,
                              _("Restoring hardware time..."))
            threadMgr.wait(constants.THREAD_TIME_INIT)

        hubQ.send_ready(self.__class__.__name__, False)

        # report that we are done
        self.initialize_done()
Beispiel #21
0
    def execute(self):
        # get the DBus proxies
        timezone_proxy = TIMEZONE.get_proxy()

        # write out timezone configuration
        kickstart_timezone = timezone_proxy.Timezone

        if not timezone.is_valid_timezone(kickstart_timezone):
            # this should never happen, but for pity's sake
            timezone_log.warning(
                "Timezone %s set in kickstart is not valid, falling "
                "back to default (America/New_York).", kickstart_timezone)
            timezone_proxy.SetTimezone("America/New_York")

        timezone.write_timezone_config(timezone_proxy, conf.target.system_root)

        # write out NTP configuration (if set) and --nontp is not used
        kickstart_ntp_servers = timezone_proxy.NTPServers

        if timezone_proxy.NTPEnabled and kickstart_ntp_servers:
            chronyd_conf_path = os.path.normpath(conf.target.system_root +
                                                 ntp.NTP_CONFIG_FILE)
            pools, servers = ntp.internal_to_pools_and_servers(
                kickstart_ntp_servers)
            if os.path.exists(chronyd_conf_path):
                timezone_log.debug("Modifying installed chrony configuration")
                try:
                    ntp.save_servers_to_config(
                        pools, servers, conf_file_path=chronyd_conf_path)
                except ntp.NTPconfigError as ntperr:
                    timezone_log.warning(
                        "Failed to save NTP configuration: %s", ntperr)
            # use chrony conf file from installation environment when
            # chrony is not installed (chrony conf file is missing)
            else:
                timezone_log.debug(
                    "Creating chrony configuration based on the "
                    "configuration from installation environment")
                try:
                    ntp.save_servers_to_config(
                        pools,
                        servers,
                        conf_file_path=ntp.NTP_CONFIG_FILE,
                        out_file_path=chronyd_conf_path)
                except ntp.NTPconfigError as ntperr:
                    timezone_log.warning(
                        "Failed to save NTP configuration without chrony package: %s",
                        ntperr)
    def refresh(self):
        self._shown = True

        # update the displayed time
        self._update_datetime_timer = Timer()
        self._update_datetime_timer.timeout_sec(1, self._update_datetime)
        self._start_updating_timer = None

        kickstart_timezone = self._timezone_module.Timezone

        if is_valid_timezone(kickstart_timezone):
            self._tzmap.set_timezone(kickstart_timezone)
            time.tzset()

        self._update_datetime()

        # update the ntp configuration
        self._ntp_servers = TimeSourceData.from_structure_list(
            self._timezone_module.TimeSources)

        if not self._ntp_servers:
            try:
                self._ntp_servers = ntp.get_servers_from_config()
            except ntp.NTPconfigError:
                log.warning("Failed to load NTP servers configuration")

        self._ntp_servers_states = NTPServerStatusCache()
        self._ntp_servers_states.changed.connect(
            self._update_ntp_server_warning)

        has_active_network = self._network_module.Connected

        if not has_active_network:
            self._show_no_network_warning()
        else:
            self.clear_info()

            for server in self._ntp_servers:
                self._ntp_servers_states.check_status(server)

        if conf.system.can_set_time_synchronization:
            ntp_working = has_active_network and is_service_running(
                NTP_SERVICE)
        else:
            ntp_working = self._timezone_module.NTPEnabled

        self._ntpSwitch.set_active(ntp_working)
Beispiel #23
0
    def _initialize(self):
        # a bit hacky way, but should return the translated strings
        for i in range(1, 32):
            day = datetime.date(2000, 1, i).strftime(self._day_format)
            self.add_to_store_idx(self._daysStore, i, day)

        for i in range(1, 13):
            month = datetime.date(2000, i, 1).strftime(self._month_format)
            self.add_to_store_idx(self._monthsStore, i, month)

        for i in range(1990, 2051):
            year = datetime.date(i, 1, 1).strftime(self._year_format)
            self.add_to_store_idx(self._yearsStore, i, year)

        cities = set()
        xlated_regions = ((region, get_xlated_timezone(region))
                          for region in self._regions_zones.keys())
        for region, xlated in sorted(xlated_regions, key=functools.cmp_to_key(_compare_regions)):
            self.add_to_store_xlated(self._regionsStore, region, xlated)
            for city in self._regions_zones[region]:
                cities.add((city, get_xlated_timezone(city)))

        for city, xlated in sorted(cities, key=functools.cmp_to_key(_compare_cities)):
            self.add_to_store_xlated(self._citiesStore, city, xlated)

        self._update_datetime_timer = None
        kickstart_timezone = self._timezone_module.proxy.Timezone
        if is_valid_timezone(kickstart_timezone):
            self._set_timezone(kickstart_timezone)
        elif not flags.flags.automatedInstall:
            log.warning("%s is not a valid timezone, falling back to default (%s)",
                        kickstart_timezone, DEFAULT_TZ)
            self._set_timezone(DEFAULT_TZ)
            self._timezone_module.proxy.SetTimezone(DEFAULT_TZ)

        time_init_thread = threadMgr.get(constants.THREAD_TIME_INIT)
        if time_init_thread is not None:
            hubQ.send_message(self.__class__.__name__,
                             _("Restoring hardware time..."))
            threadMgr.wait(constants.THREAD_TIME_INIT)

        hubQ.send_ready(self.__class__.__name__, False)

        # report that we are done
        self.initialize_done()
Beispiel #24
0
    def execute(self):
        # get the DBus proxies
        timezone_proxy = TIMEZONE.get_proxy()

        # write out timezone configuration
        kickstart_timezone = timezone_proxy.Timezone

        if not timezone.is_valid_timezone(kickstart_timezone):
            # this should never happen, but for pity's sake
            timezone_log.warning("Timezone %s set in kickstart is not valid, falling "
                                 "back to default (America/New_York).", kickstart_timezone)
            timezone_proxy.SetTimezone("America/New_York")

        timezone.write_timezone_config(timezone_proxy, util.getSysroot())

        # write out NTP configuration (if set) and --nontp is not used
        kickstart_ntp_servers = timezone_proxy.NTPServers

        if timezone_proxy.NTPEnabled and kickstart_ntp_servers:
            chronyd_conf_path = os.path.normpath(util.getSysroot() + ntp.NTP_CONFIG_FILE)
            pools, servers = ntp.internal_to_pools_and_servers(kickstart_ntp_servers)
            if os.path.exists(chronyd_conf_path):
                timezone_log.debug("Modifying installed chrony configuration")
                try:
                    ntp.save_servers_to_config(pools, servers, conf_file_path=chronyd_conf_path)
                except ntp.NTPconfigError as ntperr:
                    timezone_log.warning("Failed to save NTP configuration: %s", ntperr)
            # use chrony conf file from installation environment when
            # chrony is not installed (chrony conf file is missing)
            else:
                timezone_log.debug("Creating chrony configuration based on the "
                                   "configuration from installation environment")
                try:
                    ntp.save_servers_to_config(pools, servers,
                                               conf_file_path=ntp.NTP_CONFIG_FILE,
                                               out_file_path=chronyd_conf_path)
                except ntp.NTPconfigError as ntperr:
                    timezone_log.warning("Failed to save NTP configuration without chrony package: %s", ntperr)
    def _locate(self, url):
        """Geolocate the computer using the service at given URL

        :param str url: URL to query
        :return GeolocationData: data structure describing geolocation results
        """
        try:
            log.info("Geoloc: querying the API")
            reply = requests.get(url,
                                 timeout=NETWORK_CONNECTION_TIMEOUT,
                                 verify=True)
            if reply.status_code == requests.codes.ok:  # pylint: disable=no-member
                json_reply = reply.json()
                territory = json_reply.get("country_code", "")
                timezone = json_reply.get("time_zone", "")

                # check if the timezone returned by the API is valid
                if not is_valid_timezone(timezone):
                    # try to get a timezone from the territory code
                    timezone = get_preferred_timezone(territory)

                if territory or timezone:
                    return GeolocationData.from_values(
                        territory=territory,
                        timezone=timezone,
                    )
            else:
                log.error("Geoloc: API lookup failed with status code: %s",
                          reply.status_code)

        except requests.exceptions.RequestException as exc:
            log.debug("Geoloc: RequestException for API lookup:\n%s", exc)
        except ValueError as exc:
            log.debug("Geoloc: Unable to decode JSON:\n%s", exc)

        return GeolocationData()
Beispiel #26
0
 def completed(self):
     if self._kickstarted and not self.data.timezone.seen:
         # taking values from kickstart, but not specified
         return False
     else:
         return is_valid_timezone(self.data.timezone.timezone)
Beispiel #27
0
 def completed(self):
     if self._kickstarted and not self._timezone_module.proxy.Kickstarted:
         # taking values from kickstart, but not specified
         return False
     else:
         return is_valid_timezone(self._timezone_module.proxy.Timezone)
Beispiel #28
0
 def completed(self):
     if self._kickstarted and not self._timezone_module.proxy.Kickstarted:
         # taking values from kickstart, but not specified
         return False
     else:
         return is_valid_timezone(self._timezone_module.proxy.Timezone)
 def completed(self):
     if self._kickstarted and not self.data.timezone.seen:
         # taking values from kickstart, but not specified
         return False
     else:
         return timezone.is_valid_timezone(self.data.timezone.timezone)
Beispiel #30
0
    def all_timezones_valid_test(self):
        """Check if all returned timezones are considered valid timezones."""

        for (region, zones) in timezone.get_all_regions_and_timezones().iteritems():
            for zone in zones:
                self.assertTrue(timezone.is_valid_timezone(region + "/" + zone))