Commit 3b38d346 authored by Lluis Gifre Renom's avatar Lluis Gifre Renom
Browse files

Common - Tools - Rest Conf

- Added restconf version to RestConf client
- Added method to register custom endpoints
parent 4ab38947
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ class RestConfClient(RestApiClient):
    def __init__(
        self, address : str, port : int = 8080, scheme : str = 'http',
        username : Optional[str] = None, password : Optional[str] = None,
        restconf_version : Optional[str] = None,
        timeout : int = 30, verify_certs : bool = True, allow_redirects : bool = True,
        logger : Optional[logging.Logger] = None
    ) -> None:
@@ -34,6 +35,8 @@ class RestConfClient(RestApiClient):
        )

        self._discover_base_url()
        if restconf_version is not None:
            self._base_url += '/{:s}'.format(restconf_version)


    def _discover_base_url(self) -> None:
+16 −1
Original line number Diff line number Diff line
@@ -14,8 +14,9 @@


import json, logging, time
from typing import Any, Dict, Tuple, Type
from flask import Flask, request
from flask_restful import Api
from flask_restful import Api, Resource
from .Callbacks import CallbackDispatcher
from .Config import RESTCONF_PREFIX, SECRET_KEY, STARTUP_FILE, YANG_SEARCH_PATH
from .DispatchData import RestConfDispatchData
@@ -82,6 +83,20 @@ class RestConfServerApplication:
            resource_class_args=(self._yang_handler, self._callback_dispatcher)
        )

    def register_custom(
        self, resource_class : Type[Resource],
        *urls : str, add_prefix_to_urls : bool = True,
        resource_class_args : Tuple[Any, ...] = tuple(),
        resource_class_kwargs : Dict[str, Any] = dict()
    ) -> None:
        if add_prefix_to_urls:
            urls = [RESTCONF_PREFIX + u for u in urls]
        self._api.add_resource(
            resource_class, *urls,
            resource_class_args=resource_class_args,
            resource_class_kwargs=resource_class_kwargs
        )

    def get_flask_app(self) -> Flask:
        return self._app