コード例 #1
0
ファイル: network.py プロジェクト: martinpitt/anaconda-1
def _set_ntp_servers_from_dhcp():
    """Set NTP servers of timezone module from dhcp if not set by kickstart."""
    # FIXME - do it only if they will be applied (the guard at the end of the function)
    timezone_proxy = TIMEZONE.get_proxy()
    ntp_servers = get_ntp_servers_from_dhcp(get_nm_client())
    log.info("got %d NTP servers from DHCP", len(ntp_servers))
    hostnames = []
    for server_address in ntp_servers:
        try:
            hostname = socket.gethostbyaddr(server_address)[0]
        except socket.error:
            # getting hostname failed, just use the address returned from DHCP
            log.debug("getting NTP server host name failed for address: %s",
                      server_address)
            hostname = server_address
        hostnames.append(hostname)

    # check if some NTP servers were specified from kickstart
    if not timezone_proxy.TimeSources and conf.target.is_hardware:
        # no NTP servers were specified, add those from DHCP
        servers = []

        for hostname in hostnames:
            server = TimeSourceData()
            server.type = TIME_SOURCE_SERVER
            server.hostname = hostname
            server.options = ["iburst"]
            servers.append(server)

        timezone_proxy.SetTimeSources(
            TimeSourceData.to_structure_list(servers))
コード例 #2
0
    def on_add_button_clicked(self, *args):
        """Handler for Add button.

        Tries to add a new server for editing, or reuse an existing server that was not edited
        after adding.
        """
        # check if there is any unedited server
        # exactly zero or one such server can exist, at last position only
        if not self._servers[-1].hostname == SERVER_STARTING_STRING:
            # no unedited leftover, so make a new server with a reasonable guess about the defaults
            server = TimeSourceData()
            server.type = TIME_SOURCE_SERVER
            server.hostname = SERVER_STARTING_STRING
            server.options = ["iburst"]
            # add the (still invalid) server
            self._servers.append(server)
            self._states.check_status(server)
            self._add_row(server)

        # select the correct row - it is always the last one
        num = len(self._serversStore)
        path = Gtk.TreePath(num - 1)
        itr = self._serversStore.get_iter(path)
        selection = self._serversView.get_selection()
        selection.select_iter(itr)
        self._serversView.grab_focus()

        # start editing the newly added server hostname
        # it is already selected so just "press" the edit button
        self.on_edit_button_clicked(*args)
コード例 #3
0
    def on_entry_activated(self, entry, *args):
        # Check that the input check has passed
        if self._serverCheck.check_status != InputCheck.CHECK_OK:
            return

        server = TimeSourceData()

        if self._poolCheckButton.get_active():
            server.type = TIME_SOURCE_POOL
        else:
            server.type = TIME_SOURCE_SERVER

        server.hostname = entry.get_text()
        server.options = ["iburst"]

        if self._ntsCheckButton.get_active():
            server.options.append("nts")

        self._servers.append(server)
        self._states.check_status(server)
        self._add_row(server)

        entry.set_text("")
        self._poolCheckButton.set_active(False)
        self._ntsCheckButton.set_active(False)
コード例 #4
0
def get_servers_from_config(conf_file_path=NTP_CONFIG_FILE):
    """Get NTP servers from a configuration file.

    Goes through the chronyd's configuration file looking for lines starting
    with 'server'.

    :param conf_file_path: a path to the chronyd's configuration file
    :return: servers found in the chronyd's configuration
    :rtype: a list of TimeSourceData instances
    """
    servers = []

    try:
        with open(conf_file_path, "r") as conf_file:
            for line in conf_file:
                match = SRV_LINE_REGEXP.match(line)

                if not match:
                    continue

                server = TimeSourceData()
                server.type = match.group(1).upper()
                server.hostname = match.group(2)
                server.options = ["iburst"]
                servers.append(server)

    except IOError as ioerr:
        msg = "Cannot open config file {} for reading ({})."
        raise NTPconfigError(msg.format(conf_file_path, ioerr.strerror))

    return servers
コード例 #5
0
    def process_kickstart(self, data):
        """Process the kickstart data."""
        self.set_timezone(data.timezone.timezone)
        self.set_is_utc(data.timezone.isUtc)
        self.set_ntp_enabled(not data.timezone.nontp)

        sources = []

        for hostname in data.timezone.ntpservers:
            source = TimeSourceData()
            source.type = TIME_SOURCE_SERVER
            source.hostname = hostname
            source.options = ["iburst"]
            sources.append(source)

        for source_data in data.timesource.dataList():
            if source_data.ntp_disable:
                self.set_ntp_enabled(False)
                continue

            source = TimeSourceData()
            source.options = ["iburst"]

            if source_data.ntp_server:
                source.type = TIME_SOURCE_SERVER
                source.hostname = source_data.ntp_server
            elif source_data.ntp_pool:
                source.type = TIME_SOURCE_POOL
                source.hostname = source_data.ntp_pool
            else:
                KickstartParseError(
                    _("Invalid time source."),
                    lineno=source_data.lineno
                )

            if source_data.nts:
                source.options.append("nts")

            sources.append(source)

        self.set_time_sources(sources)
コード例 #6
0
ファイル: time_spoke.py プロジェクト: sundeep-anand/anaconda
    def _add_ntp_server(self, server_hostname):
        for server in self._servers:
            if server.hostname == server_hostname:
                return

        server = TimeSourceData()
        server.type = TIME_SOURCE_SERVER
        server.hostname = server_hostname
        server.options = ["iburst"]

        self._servers.append(server)
        self._states.check_status(server)
コード例 #7
0
    def _get_test_sources(self):
        """Get a list of sources"""
        server = TimeSourceData()
        server.type = TIME_SOURCE_SERVER
        server.hostname = "unique.ntp.server"
        server.options = ["iburst"]

        pool = TimeSourceData()
        pool.type = TIME_SOURCE_POOL
        pool.hostname = "another.unique.server"

        return [server, pool]
コード例 #8
0
ファイル: ntp.py プロジェクト: cheese/anaconda
def get_servers_from_config(conf_file_path=NTP_CONFIG_FILE):
    """Get NTP servers from a configuration file.

    Goes through the chronyd's configuration file looking for lines starting
    with 'server'.

    :param conf_file_path: a path to the chronyd's configuration file
    :return: servers found in the chronyd's configuration
    :rtype: a list of TimeSourceData instances
    """
    servers = []

    try:
        with open(conf_file_path, "r") as conf_file:
            for line in conf_file:
                match = SRV_LINE_REGEXP.match(line)

                if not match:
                    continue

                server = TimeSourceData()
                server.type = match.group(1).upper()
                server.hostname = match.group(2)
                server.options = []

                words = match.group(3).lower().split()
                skip_argument = False

                for i in range(len(words)):
                    if skip_argument:
                        skip_argument = False
                        continue
                    if words[i] in SRV_NOARG_OPTIONS:
                        server.options.append(words[i])
                    elif words[i] in SRV_ARG_OPTIONS and i + 1 < len(words):
                        server.options.append(' '.join(words[i:i + 2]))
                        skip_argument = True
                    else:
                        log.debug("Unknown NTP server option %s", words[i])

                servers.append(server)

    except IOError as ioerr:
        msg = "Cannot open config file {} for reading ({})."
        raise NTPconfigError(msg.format(conf_file_path, ioerr.strerror))

    return servers
コード例 #9
0
    def test_install_with_tasks_configured(self, publisher):
        """Test install tasks - module in configured state."""

        self.timezone_interface.SetIsUTC(True)
        self.timezone_interface.SetTimezone("Asia/Tokyo")
        self.timezone_interface.SetNTPEnabled(False)
        # --nontp and --ntpservers are mutually exclusive in kicstart but
        # there is no such enforcement in the module so for testing this is ok

        server = TimeSourceData()
        server.type = TIME_SOURCE_SERVER
        server.hostname = "clock1.example.com"
        server.options = ["iburst"]

        pool = TimeSourceData()
        pool.type = TIME_SOURCE_POOL
        pool.hostname = "clock2.example.com"

        self.timezone_interface.SetTimeSources(
            TimeSourceData.to_structure_list([server, pool])
        )

        task_classes = [
            ConfigureHardwareClockTask,
            ConfigureTimezoneTask,
            ConfigureNTPTask,
        ]
        task_paths = self.timezone_interface.InstallWithTasks()
        task_objs = check_task_creation_list(task_paths, publisher, task_classes)

        # ConfigureHardwareClockTask
        obj = task_objs[0]
        assert obj.implementation._is_utc is True

        # ConfigureTimezoneTask
        obj = task_objs[1]
        assert obj.implementation._timezone == "Asia/Tokyo"
        assert obj.implementation._is_utc is True

        # ConfigureNTPTask
        obj = task_objs[2]
        assert obj.implementation._ntp_enabled is False
        assert len(obj.implementation._ntp_servers) == 2
        assert compare_data(obj.implementation._ntp_servers[0], server)
        assert compare_data(obj.implementation._ntp_servers[1], pool)