Skip to content
Snippets Groups Projects
Commit b3c1be1e authored by Georgios Katsikas's avatar Georgios Katsikas
Browse files

style: changes in parent Driver API documentation

parent de07e72e
No related branches found
No related tags found
2 merge requests!54Release 2.0.0,!4Compute component:
...@@ -15,16 +15,18 @@ ...@@ -15,16 +15,18 @@
import threading import threading
from typing import Any, Iterator, List, Optional, Tuple, Union from typing import Any, Iterator, List, Optional, Tuple, Union
# Special resource names to request to the driver to retrieve the specified configuration/structural resources. # Special resource names to request to the driver to retrieve the specified
# configuration/structural resources.
# These resource names should be used with GetConfig() method. # These resource names should be used with GetConfig() method.
RESOURCE_ENDPOINTS = '__endpoints__' RESOURCE_ENDPOINTS = '__endpoints__'
RESOURCE_INTERFACES = '__interfaces__' RESOURCE_INTERFACES = '__interfaces__'
RESOURCE_NETWORK_INSTANCES = '__network_instances__' RESOURCE_NETWORK_INSTANCES = '__network_instances__'
RESOURCE_ROUTING_POLICIES = '__routing_policies__' RESOURCE_ROUTING_POLICIES = '__routing_policies__'
RESOURCE_ACL = '__acl__' RESOURCE_ACL = '__acl__'
class _Driver: class _Driver:
def __init__(self, address : str, port : int, **settings) -> None: def __init__(self, address: str, port: int, **settings) -> None:
""" Initialize Driver. """ Initialize Driver.
Parameters: Parameters:
address : str address : str
...@@ -56,92 +58,122 @@ class _Driver: ...@@ -56,92 +58,122 @@ class _Driver:
""" Retrieve initial configuration of entire device. """ Retrieve initial configuration of entire device.
Returns: Returns:
values : List[Tuple[str, Any]] values : List[Tuple[str, Any]]
List of tuples (resource key, resource value) for resource keys. List of tuples (resource key, resource value) for
resource keys.
""" """
raise NotImplementedError() raise NotImplementedError()
def GetConfig(self, resource_keys : List[str] = []) -> List[Tuple[str, Union[Any, None, Exception]]]: def GetConfig(self, resource_keys: List[str] = []) -> \
""" Retrieve running configuration of entire device, or selected resource keys. List[Tuple[str, Union[Any, None, Exception]]]:
""" Retrieve running configuration of entire device or
selected resource keys.
Parameters: Parameters:
resource_keys : List[str] resource_keys : List[str]
List of keys pointing to the resources to be retrieved. List of keys pointing to the resources to be retrieved.
Returns: Returns:
values : List[Tuple[str, Union[Any, None, Exception]]] values : List[Tuple[str, Union[Any, None, Exception]]]
List of tuples (resource key, resource value) for resource keys requested. If a resource is found, List of tuples (resource key, resource value) for
the appropriate value type must be retrieved. If a resource is not found, None must be retrieved as resource keys requested. If a resource is found,
value for that resource. In case of Exception, the Exception must be retrieved as value. the appropriate value type must be retrieved.
If a resource is not found, None must be retrieved as
value for that resource. In case of Exception,
the Exception must be retrieved as value.
""" """
raise NotImplementedError() raise NotImplementedError()
def SetConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: def SetConfig(self, resources: List[Tuple[str, Any]]) -> \
List[Union[bool, Exception]]:
""" Create/Update configuration for a list of resources. """ Create/Update configuration for a list of resources.
Parameters: Parameters:
resources : List[Tuple[str, Any]] resources : List[Tuple[str, Any]]
List of tuples, each containing a resource_key pointing the resource to be modified, and a List of tuples, each containing a resource_key pointing the
resource_value containing the new value to be set. resource to be modified, and a resource_value containing
the new value to be set.
Returns: Returns:
results : List[Union[bool, Exception]] results : List[Union[bool, Exception]]
List of results for resource key changes requested. Return values must be in the same order than List of results for resource key changes requested.
resource keys requested. If a resource is properly set, True must be retrieved; otherwise, the Return values must be in the same order as the
Exception that is raised during the processing must be retrieved. resource keys requested. If a resource is properly set,
True must be retrieved; otherwise, the Exception that is
raised during the processing must be retrieved.
""" """
raise NotImplementedError() raise NotImplementedError()
def DeleteConfig(self, resources : List[Tuple[str, Any]]) -> List[Union[bool, Exception]]: def DeleteConfig(self, resources: List[Tuple[str, Any]]) -> \
List[Union[bool, Exception]]:
""" Delete configuration for a list of resources. """ Delete configuration for a list of resources.
Parameters: Parameters:
resources : List[Tuple[str, Any]] resources : List[Tuple[str, Any]]
List of tuples, each containing a resource_key pointing the resource to be modified, and a List of tuples, each containing a resource_key pointing the
resource_value containing possible additionally required values to locate the value to be removed. resource to be modified, and a resource_value containing
possible additionally required values to locate
the value to be removed.
Returns: Returns:
results : List[bool] results : List[Union[bool, Exception]]
List of results for resource key deletions requested. Return values must be in the same order than List of results for resource key deletions requested.
resource keys requested. If a resource is properly deleted, True must be retrieved; otherwise, the Return values must be in the same order as the resource keys
Exception that is raised during the processing must be retrieved. requested. If a resource is properly deleted, True must be
retrieved; otherwise, the Exception that is raised during
the processing must be retrieved.
""" """
raise NotImplementedError() raise NotImplementedError()
def SubscribeState(self, subscriptions : List[Tuple[str, float, float]]) -> List[Union[bool, Exception]]: def SubscribeState(self, subscriptions: List[Tuple[str, float, float]]) -> \
""" Subscribe to state information of entire device, or selected resources. Subscriptions are incremental. List[Union[bool, Exception]]:
""" Subscribe to state information of entire device or
selected resources. Subscriptions are incremental.
Driver should keep track of requested resources. Driver should keep track of requested resources.
Parameters: Parameters:
subscriptions : List[Tuple[str, float, float]] subscriptions : List[Tuple[str, float, float]]
List of tuples, each containing a resource_key pointing the resource to be subscribed, a List of tuples, each containing a resource_key pointing the
sampling_duration, and a sampling_interval (both in seconds with float representation) defining, resource to be subscribed, a sampling_duration, and a
respectively, for how long monitoring should last, and the desired monitoring interval for the sampling_interval (both in seconds with float
resource specified. representation) defining, respectively, for how long
monitoring should last, and the desired monitoring interval
for the resource specified.
Returns: Returns:
results : List[bool] results : List[Union[bool, Exception]]
List of results for resource key subscriptions requested. Return values must be in the same order List of results for resource key subscriptions requested.
than resource keys requested. If a resource is properly subscribed, True must be retrieved; Return values must be in the same order as the resource keys
otherwise, the Exception that is raised during the processing must be retrieved. requested. If a resource is properly subscribed,
True must be retrieved; otherwise, the Exception that is
raised during the processing must be retrieved.
""" """
raise NotImplementedError() raise NotImplementedError()
def UnsubscribeState(self, subscriptions : List[Tuple[str, float, float]]) -> List[Union[bool, Exception]]: def UnsubscribeState(self, subscriptions: List[Tuple[str, float, float]]) \
""" Unsubscribe from state information of entire device, or selected resources. Subscriptions are incremental. -> List[Union[bool, Exception]]:
""" Unsubscribe from state information of entire device
or selected resources. Subscriptions are incremental.
Driver should keep track of requested resources. Driver should keep track of requested resources.
Parameters: Parameters:
subscriptions : List[str] subscriptions : List[str]
List of tuples, each containing a resource_key pointing the resource to be subscribed, a List of tuples, each containing a resource_key pointing the
sampling_duration, and a sampling_interval (both in seconds with float representation) defining, resource to be subscribed, a sampling_duration, and a
respectively, for how long monitoring should last, and the desired monitoring interval for the sampling_interval (both in seconds with float
resource specified. representation) defining, respectively, for how long
monitoring should last, and the desired monitoring interval
for the resource specified.
Returns: Returns:
results : List[Union[bool, Exception]] results : List[Union[bool, Exception]]
List of results for resource key unsubscriptions requested. Return values must be in the same order List of results for resource key un-subscriptions requested.
than resource keys requested. If a resource is properly unsubscribed, True must be retrieved; Return values must be in the same order as the resource keys
otherwise, the Exception that is raised during the processing must be retrieved. requested. If a resource is properly unsubscribed,
True must be retrieved; otherwise, the Exception that is
raised during the processing must be retrieved.
""" """
raise NotImplementedError() raise NotImplementedError()
def GetState( def GetState(
self, blocking=False, terminate : Optional[threading.Event] = None self, blocking=False, terminate : Optional[threading.Event] = None
) -> Iterator[Tuple[float, str, Any]]: ) -> Iterator[Tuple[float, str, Any]]:
""" Retrieve last collected values for subscribed resources. Operates as a generator, so this method should be """ Retrieve last collected values for subscribed resources.
called once and will block until values are available. When values are available, it should yield each of Operates as a generator, so this method should be called once and will
them and block again until new values are available. When the driver is destroyed, GetState() can return block until values are available. When values are available,
instead of yield to terminate the loop. Terminate enables to request interruption of the generation. it should yield each of them and block again until new values are
available. When the driver is destroyed, GetState() can return instead
of yield to terminate the loop.
Terminate enables to request interruption of the generation.
Examples: Examples:
# keep looping waiting for extra samples (generator loop) # keep looping waiting for extra samples (generator loop)
terminate = threading.Event() terminate = threading.Event()
...@@ -161,20 +193,27 @@ class _Driver: ...@@ -161,20 +193,27 @@ class _Driver:
if i == 10: terminate.set() if i == 10: terminate.set()
Parameters: Parameters:
blocking : bool blocking : bool
Select the driver behaviour. In both cases, the driver will first retrieve the samples accumulated Select the driver behaviour. In both cases, the driver will
and available in the internal queue. Then, if blocking, the driver does not terminate the loop and first retrieve the samples accumulated and available in the
waits for additional samples to come, thus behaving as a generator. If non-blocking, the driver internal queue. Then, if blocking, the driver does not
terminates the loop and returns. Non-blocking behaviour can be used for periodically polling the terminate the loop and waits for additional samples to come,
driver, while blocking can be used when a separate thread is in charge of collecting the samples thus behaving as a generator. If non-blocking, the driver
produced by the driver. terminates the loop and returns. Non-blocking behaviour can
be used for periodically polling the driver, while blocking
can be used when a separate thread is in charge of
collecting the samples produced by the driver.
terminate : threading.Event terminate : threading.Event
Signals the interruption of the GetState method as soon as possible. Signals the interruption of the GetState method as soon as
possible.
Returns: Returns:
results : Iterator[Tuple[float, str, Any]] results : Iterator[Tuple[float, str, Any]]
Sequences of state sample. Each State sample contains a float Unix-like timestamps of the samples in Sequences of state sample. Each State sample contains a
seconds with up to microsecond resolution, the resource_key of the sample, and its resource_value. float Unix-like timestamps of the samples in seconds with up
Only resources with an active subscription must be retrieved. Interval and duration of the sampling to microsecond resolution, the resource_key of the sample,
process are specified when creating the subscription using method SubscribeState(). Order of values and its resource_value.
yielded is arbitrary. Only resources with an active subscription must be
retrieved. Interval and duration of the sampling process are
specified when creating the subscription using method
SubscribeState(). Order of values yielded is arbitrary.
""" """
raise NotImplementedError() raise NotImplementedError()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment