Exemple #1
0
    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.encode()))
        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, Response(e.to_etree()))

                handled = True

        if not handled:
            self.reply(
                message_id,
                Response(OperationNotSupported(operation_name).to_etree()))
Exemple #2
0
 def get_config(self, request):
     source = first(request.xpath("source"))
     content = self.datastore.to_etree(resolve_source_name(source[0].tag))
     filtering = first(request.xpath("filter"))
     if filtering is not None:
         filter_content(content, filtering)
     return Response(content)
    def get_interface_information(self, request):
        if len(request) == 1 and request[0].tag == "terse":
            return Response(self.datastore.get_interface_information_terse())

        raise NetconfError("syntax error",
                           err_type="protocol",
                           tag="operation-failed")
def commit_results_error_to_response(commit_results_error):
    return Response(
        dict_2_etree({
            'commit-results': [
                error_to_rpcerror_dict(e)
                for e in commit_results_error.netconf_errors
            ]
        }))
Exemple #5
0
def error_to_response(error):
    error_specs = {"error-message": error.message}

    if error.type: error_specs["error-type"] = error.type
    if error.tag: error_specs["error-tag"] = error.tag
    if error.severity: error_specs["error-severity"] = error.severity
    if error.info: error_specs["error-info"] = error.info

    return Response(dict_2_etree({"rpc-error": error_specs}))
Exemple #6
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)
Exemple #8
0
 def commit(self, *args, **kwargs):
     self.datastore.commit_candidate()
     self.datastore.configurations.get('candidate').commit()
     return Response(etree.Element("ok"))
Exemple #9
0
    def edit_config(self, request):
        target = first(request.xpath("target"))
        config = first(request.xpath("config"))
        self.datastore.edit(resolve_source_name(target[0].tag), config[0])

        return Response(etree.Element("ok"))
Exemple #10
0
 def discard_changes(self, _):
     self.datastore.reset()
     return Response(etree.Element("ok"))
Exemple #11
0
 def load_configuration(self, request):
     return Response(etree.Element("ok"), require_disconnect=False)
Exemple #12
0
 def unlock(self, request):
     target = first(request.xpath("target"))
     self.datastore.unlock(resolve_source_name(target[0].tag))
     return Response(etree.Element("ok"))
Exemple #13
0
 def close_session(self, _):
     return Response(etree.Element("ok"), require_disconnect=True)
def errors_to_response(errors):
    return Response(
        [dict_2_etree(error_to_rpcerror_dict(error)) for error in errors])
def error_to_response(error):
    return Response(dict_2_etree(error_to_rpcerror_dict(error)))
Exemple #16
0
 def commit(self, _):
     self.datastore.commit_candidate()
     return Response(etree.Element("ok"))