def process(self, data):
        if not self.been_greeted:
            self.logger.info("Client's greeting received")
            self.been_greeted = True
            return

        xml_request_root = remove_namespaces(etree.fromstring(data))
        message_id = xml_request_root.get("message-id")
        operation = xml_request_root[0]
        self.logger.info("Operation requested %s" % repr(operation.tag))

        handled = False
        operation_name = normalize_operation_name(operation)
        for capability in self.capabilities:
            if hasattr(capability, operation_name):
                try:
                    self.reply(message_id,
                               getattr(capability, operation_name)(operation))
                except NetconfError as e:
                    self.reply(message_id, error_to_response(e))
                except MultipleNetconfErrors as e:
                    self.reply(message_id, errors_to_response(e.errors))
                except FailingCommitResults as e:
                    self.reply(message_id, commit_results_error_to_response(e))
                handled = True

        if not handled:
            self.reply(
                message_id,
                error_to_response(OperationNotSupported(operation_name)))
Exemple #2
0
    def get_configuration(self, request):
        if "compare" not in request.attrib:
            raise OperationNotSupported("get_configuration without a compare")

        running = self.datastore.to_etree(RUNNING)
        candidate = self.datastore.to_etree(CANDIDATE)

        data = etree.fromstring(textwrap.dedent("""
            <configuration-information>
                <configuration-output>
            {0}</configuration-output>
            </configuration-information>
            """).format("There were some changes"
                        if not xml_equals(running, candidate) else ""),
                                parser=etree.XMLParser(recover=True))

        return Response(data)
    def get_configuration(self, request):
        if "compare" not in request.attrib:
            raise OperationNotSupported("get_configuration without a compare")

        running = self.datastore.to_etree(RUNNING)
        candidate = self.datastore.to_etree(CANDIDATE)

        # NOTE(lindycoder): Not actually computing the diff, not needed so far, just show that there's a change
        data_string = textwrap.dedent("""
            <configuration-information>
                <configuration-output>{0}</configuration-output>
            </configuration-information>
            """).format("There were some changes"
                        if not xml_equals(running, candidate) else "")
        data = etree.fromstring(data_string,
                                parser=etree.XMLParser(recover=True))

        return Response(data)