Skip to content

Commit

Permalink
0.8.14
Browse files Browse the repository at this point in the history
  • Loading branch information
akarneliuk committed Mar 9, 2024
1 parent 049b327 commit ed5227f
Show file tree
Hide file tree
Showing 10 changed files with 3,817 additions and 2,439 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ Dev Log

Release **0.8.14**:
- Number of minor bug fixes and improvements.
- Adding support of `prefix` to `pygnmicli`.
- `Adding error propagation from child thread to main thread <https://github.com/akarneliuk/pygnmi/pull/142>`
- `Changes to u_val <https://github.com/akarneliuk/pygnmi/pull/144>`
- `Adding Master Arbitration support for Set <https://github.com/akarneliuk/pygnmi/pull/146>`
- `Adding bytes_val and leaflist_val with string_val parsing <https://github.com/akarneliuk/pygnmi/pull/151>`

Release **0.8.13**:
- Number of minor bug fixes and improvements.
Expand Down
28 changes: 14 additions & 14 deletions pygnmi/artefacts/messages.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#(c)2020, Anton Karneliuk
# (c)2020, Anton Karneliuk

msg = {
'unknown_arg': 'There is no such argument. Run \'--help\' for details.',
'help': 'The following keys are availble:\n\n -u (--user): Provide the username to connect to the network element\n -p (--pass): Provide the password to connect to the network element\n -h (--help): Provide the help on the available keys\n -t (--target): Provide the list of endpoint in \'host:port\' format\n -o (--operation): Prvoide the type of gNMI request\n -c (--cert): Provide the path towards the certificate\n --insecure: Define whether gRPC channel is encrypted or not\n --gnmi-path: Provide path to the resource at the network function\n --print: Define whether Protobuf messages shall be printed in the STDOUT',
'bad_host': 'The host address is malformed. It shall be provided in a format \'ip_address:grpc_port\'.',
'not_defined_user': 'The username is not defined. The execution is terminated.',
'not_defined_pass': 'The password is not defined.',
'not_defined_target': 'There are no hosts provided. The execution is terminated.',
'not_enough_arg': 'There are not enough arguments.',
'wrong_data': 'The argument is provided in the wrong type (e.g. string instead of integer).',
'not_allowed_op': 'The request gNMI operation type is now allowed.',
'not_defined_op': 'The gNMI operation type is not defined.',
'not_defined_path': 'The gNMI path is ot defined with Get or Set operation.',
'not_defined_set': 'The gNMI path (for delete operation) or update messages (for update or replace operation) are not defined.'
}
"unknown_arg": "There is no such argument. Run '--help' for details.",
"help": "The following keys are availble:\n\n -u (--user): Provide the username to connect to the network element\n -p (--pass): Provide the password to connect to the network element\n -h (--help): Provide the help on the available keys\n -t (--target): Provide the list of endpoint in 'host:port' format\n -o (--operation): Prvoide the type of gNMI request\n -c (--cert): Provide the path towards the certificate\n --insecure: Define whether gRPC channel is encrypted or not\n --gnmi-path: Provide path to the resource at the network function\n --print: Define whether Protobuf messages shall be printed in the STDOUT",
"bad_host": "The host address is malformed. It shall be provided in a format 'ip_address:grpc_port'.",
"not_defined_user": "The username is not defined. The execution is terminated.",
"not_defined_pass": "The password is not defined.",
"not_defined_target": "There are no hosts provided. The execution is terminated.",
"not_enough_arg": "There are not enough arguments.",
"wrong_data": "The argument is provided in the wrong type (e.g. string instead of integer).",
"not_allowed_op": "The request gNMI operation type is now allowed.",
"not_defined_op": "The gNMI operation type is not defined.",
"not_defined_path": "The gNMI path is ot defined with Get or Set operation.",
"not_defined_set": "The gNMI path (for delete operation) or update messages (for update or replace operation) are not defined.",
}
76 changes: 59 additions & 17 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ def configureKeepalive(
self.__options += [
("grpc.keepalive_time_ms", keepalive_time_ms),
("grpc.keepalive_timeout_ms", keepalive_timeout_ms),
("grpc.keepalive_permit_without_calls", 1 if keepalive_permit_without_calls else 0),
(
"grpc.keepalive_permit_without_calls",
1 if keepalive_permit_without_calls else 0,
),
("grpc.http2.max_pings_without_data", max_pings_without_data),
]

Expand Down Expand Up @@ -200,7 +203,10 @@ def connect(self, timeout: int = None):

except Exception as e:
logger.error(f"The SSL certificate cannot be retrieved from {self.__target}")
raise gNMIException(f"The SSL certificate cannot be retrieved from {self.__target}", e)
raise gNMIException(
f"The SSL certificate cannot be retrieved from {self.__target}",
e,
)

if self.__skip_verify:
# Work with the certificate contents
Expand Down Expand Up @@ -257,7 +263,9 @@ def connect(self, timeout: int = None):
# Set up SSL channel credentials
if self.__path_key and self.__path_root:
cert = grpc.ssl_channel_credentials(
root_certificates=root_cert, private_key=key, certificate_chain=ssl_cert
root_certificates=root_cert,
private_key=key,
certificate_chain=ssl_cert,
)

else:
Expand Down Expand Up @@ -340,7 +348,11 @@ def capabilities(self):

for ree in gnmi_message_response.supported_models:
response["supported_models"].append(
{"name": ree.name, "organization": ree.organization, "version": ree.version}
{
"name": ree.name,
"organization": ree.organization,
"version": ree.version,
}
)

if gnmi_message_response.supported_encodings:
Expand Down Expand Up @@ -390,7 +402,14 @@ def convert_encoding(self, requested_encoding: str, is_encoding_explicitly_set:
encoding = requested_encoding or self.__encoding
return Encoding.Value(encoding.upper()) # may raise ValueError

def get(self, prefix: str = "", path: list = None, target: str = None, datatype: str = "all", encoding: str = None):
def get(
self,
prefix: str = "",
path: list = None,
target: str = None,
datatype: str = "all",
encoding: str = None,
):
"""
Collecting the information about the resources from defined paths.
Expand Down Expand Up @@ -453,7 +472,10 @@ def get(self, prefix: str = "", path: list = None, target: str = None, datatype:

try:
gnmi_message_request = GetRequest(
prefix=protobuf_prefix, path=protobuf_paths, type=pb_datatype, encoding=pb_encoding
prefix=protobuf_prefix,
path=protobuf_paths,
type=pb_datatype,
encoding=pb_encoding,
)
debug_gnmi_msg(self.__debug, gnmi_message_request, "gNMI request")

Expand Down Expand Up @@ -644,7 +666,10 @@ def set(
paths_to_collect_list.extend([path_tuple[0] for path_tuple in replace])

pre_change_dict = self.get(
prefix=prefix, path=paths_to_collect_list, encoding=encoding, datatype="config"
prefix=prefix,
path=paths_to_collect_list,
encoding=encoding,
datatype="config",
)

if gnmi_extension:
Expand All @@ -657,7 +682,10 @@ def set(
)
else:
gnmi_message_request = SetRequest(
prefix=protobuf_prefix, delete=del_protobuf_paths, update=update_msg, replace=replace_msg
prefix=protobuf_prefix,
delete=del_protobuf_paths,
update=update_msg,
replace=replace_msg,
)
debug_gnmi_msg(self.__debug, gnmi_message_request, "gNMI request")

Expand Down Expand Up @@ -716,7 +744,9 @@ def set(
is_printable = True if self.__show_diff == "print" else False

diff_list = diff_openconfig(
pre_dict=pre_change_dict, post_dict=post_change_dict, is_printable=is_printable
pre_dict=pre_change_dict,
post_dict=post_change_dict,
is_printable=is_printable,
)

if diff_list and self.__show_diff == "get":
Expand All @@ -737,7 +767,12 @@ def set(
raise gNMIException(f"Set failed: {e}", e)

def set_with_retry(
self, delete: list = None, replace: list = None, update: list = None, encoding: str = None, retry_delay: int = 3
self,
delete: list = None,
replace: list = None,
update: list = None,
encoding: str = None,
retry_delay: int = 3,
):
"""
Performs a set and retries (once) after a temporary failure with StatusCode.FAILED_PRECONDITION
Expand Down Expand Up @@ -890,7 +925,13 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens
else:
return SubscribeRequest(subscribe=request)

def subscribe(self, subscribe: dict = None, poll: bool = False, aliases: list = None, timeout: float = 0.0):
def subscribe(
self,
subscribe: dict = None,
poll: bool = False,
aliases: list = None,
timeout: float = 0.0,
):
"""
Implementation of the subscribe gNMI RPC to pool
"""
Expand Down Expand Up @@ -1113,7 +1154,8 @@ def next(self):
Blocks until one is available."""
return self._next_update(timeout=None)

def _next_update(self, timeout=None): ...
def _next_update(self, timeout=None):
...

# Overridden by each concrete class, as they each have slightly different
# behaviour around waiting (or not) for a sync_response flag
Expand Down Expand Up @@ -1298,16 +1340,16 @@ def telemetryParser(in_message=None, debug: bool = False):
update_container.update({"val": update_msg.val.proto_bytes})

elif update_msg.val.HasField("bytes_val"):
val_binary = ''.join(format(byte, '08b') for byte in update_msg.val.bytes_val)
val_binary = "".join(format(byte, "08b") for byte in update_msg.val.bytes_val)
val_decimal = struct.unpack("f", struct.pack("I", int(val_binary, 2)))[0]
update_container.update({'val': val_decimal})
elif update_msg.val.HasField('leaflist_val'):
update_container.update({"val": val_decimal})

elif update_msg.val.HasField("leaflist_val"):
val_leaflist = update_msg.val
element_str = ""
for element in val_leaflist.leaflist_val.element:
element_str += element
update_container.update({'val': element_str})
update_container.update({"val": element_str})

response["update"]["update"].append(update_container)

Expand Down
Loading

0 comments on commit ed5227f

Please sign in to comment.