def validate_conf(self):

        valid = True
        messages = []

        if not self.server_conf.get_chef_conf().validate():
            valid = False
            messages.append({'type': 'error', 'message': _('Chef and Chef Cert URLs must be valid URLs.')})

        hostname = self.server_conf.get_chef_conf().get_hostname()

        if not validation.is_qname(hostname):
            valid = False
            messages.append({'type': 'error', 'message': _('Host name is empty or contains invalid characters.')})

        try:
            used_hostnames = serverconf.get_chef_hostnames(self.server_conf.get_chef_conf())

        except Exception as e:
            used_hostnames = []
            # IMPORTANT: Append the error but don't touch the variable "valid" here,
            # just because if we can't get the hostnames here,
            # Chef will inform us about that later, while we are registering
            # the client.
            messages.append({'type': 'error', 'message': str(e)})

        if hostname in used_hostnames:
            valid = False
            messages.append({'type': 'error', 'message': _('Node name already exists in the Chef server. Choose a different one.')})

        return valid, messages
    def next_page(self, load_page_callback):

        if not self.unlink_from_chef:
            # The unique host name for Chef is mandatory, so we need
            # to ask for it before the setup.

            try:

                if not self.server_conf.get_chef_conf().validate():
                    raise serverconf.ServerConfException(_('The fields are mandatory.'))

                used_hostnames = serverconf.get_chef_hostnames(self.server_conf.get_chef_conf())

                load_page_callback(LinkToChefHostnamePage, {
                    'server_conf': self.server_conf,
                    'link_chef': not self.unlink_from_chef,
                    'unlink_chef': self.unlink_from_chef,
                    'used_hostnames': used_hostnames
                })

            except serverconf.ServerConfException as e:
                messages = [{'type': 'error', 'message': str(e)}]

                load_page_callback(LinkToChefResultsPage, {
                    'result': False,
                    'server_conf': self.server_conf,
                    'messages': messages
                })

        else:
            result, messages = serverconf.setup_server(
                server_conf=self.server_conf,
                link_chef=not self.unlink_from_chef,
                unlink_chef=self.unlink_from_chef
            )

            load_page_callback(LinkToChefResultsPage, {
                'result': result,
                'server_conf': self.server_conf,
                'messages': messages
            })
    def next_page(self, load_page_callback):

        if not self.unlink_from_chef and self.ui.chkChef.get_active():
            # The unique host name for Chef is mandatory, so we need
            # to ask for it before the setup.

            try:
                used_hostnames = serverconf.get_chef_hostnames(self.server_conf.get_chef_conf())

                load_page_callback(
                    LinkToServerHostnamePage,
                    {
                        "server_conf": self.server_conf,
                        "link_ldap": self.ui.chkLDAP.get_active(),
                        "unlink_ldap": self.unlink_from_ldap,
                        "link_chef": self.ui.chkChef.get_active(),
                        "unlink_chef": self.unlink_from_chef,
                        "used_hostnames": used_hostnames,
                    },
                )

            except serverconf.ServerConfException as e:
                messages = [{"type": "error", "message": str(e)}]

                load_page_callback(
                    LinkToServerResultsPage, {"result": False, "server_conf": self.server_conf, "messages": messages}
                )

        else:
            result, messages = serverconf.setup_server(
                server_conf=self.server_conf,
                link_ldap=self.ui.chkLDAP.get_active(),
                unlink_ldap=self.unlink_from_ldap,
                link_chef=self.ui.chkChef.get_active(),
                unlink_chef=self.unlink_from_chef,
            )

            load_page_callback(
                LinkToServerResultsPage, {"result": result, "server_conf": self.server_conf, "messages": messages}
            )