Skip to content

Commit ed5227f

Browse files
committed
0.8.14
1 parent 049b327 commit ed5227f

File tree

10 files changed

+3817
-2439
lines changed

10 files changed

+3817
-2439
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ Dev Log
8888

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

9297
Release **0.8.13**:
9398
- Number of minor bug fixes and improvements.

pygnmi/artefacts/messages.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
#(c)2020, Anton Karneliuk
1+
# (c)2020, Anton Karneliuk
22

33
msg = {
4-
'unknown_arg': 'There is no such argument. Run \'--help\' for details.',
5-
'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',
6-
'bad_host': 'The host address is malformed. It shall be provided in a format \'ip_address:grpc_port\'.',
7-
'not_defined_user': 'The username is not defined. The execution is terminated.',
8-
'not_defined_pass': 'The password is not defined.',
9-
'not_defined_target': 'There are no hosts provided. The execution is terminated.',
10-
'not_enough_arg': 'There are not enough arguments.',
11-
'wrong_data': 'The argument is provided in the wrong type (e.g. string instead of integer).',
12-
'not_allowed_op': 'The request gNMI operation type is now allowed.',
13-
'not_defined_op': 'The gNMI operation type is not defined.',
14-
'not_defined_path': 'The gNMI path is ot defined with Get or Set operation.',
15-
'not_defined_set': 'The gNMI path (for delete operation) or update messages (for update or replace operation) are not defined.'
16-
}
4+
"unknown_arg": "There is no such argument. Run '--help' for details.",
5+
"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",
6+
"bad_host": "The host address is malformed. It shall be provided in a format 'ip_address:grpc_port'.",
7+
"not_defined_user": "The username is not defined. The execution is terminated.",
8+
"not_defined_pass": "The password is not defined.",
9+
"not_defined_target": "There are no hosts provided. The execution is terminated.",
10+
"not_enough_arg": "There are not enough arguments.",
11+
"wrong_data": "The argument is provided in the wrong type (e.g. string instead of integer).",
12+
"not_allowed_op": "The request gNMI operation type is now allowed.",
13+
"not_defined_op": "The gNMI operation type is not defined.",
14+
"not_defined_path": "The gNMI path is ot defined with Get or Set operation.",
15+
"not_defined_set": "The gNMI path (for delete operation) or update messages (for update or replace operation) are not defined.",
16+
}

pygnmi/client.py

Lines changed: 59 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ def configureKeepalive(
128128
self.__options += [
129129
("grpc.keepalive_time_ms", keepalive_time_ms),
130130
("grpc.keepalive_timeout_ms", keepalive_timeout_ms),
131-
("grpc.keepalive_permit_without_calls", 1 if keepalive_permit_without_calls else 0),
131+
(
132+
"grpc.keepalive_permit_without_calls",
133+
1 if keepalive_permit_without_calls else 0,
134+
),
132135
("grpc.http2.max_pings_without_data", max_pings_without_data),
133136
]
134137

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

201204
except Exception as e:
202205
logger.error(f"The SSL certificate cannot be retrieved from {self.__target}")
203-
raise gNMIException(f"The SSL certificate cannot be retrieved from {self.__target}", e)
206+
raise gNMIException(
207+
f"The SSL certificate cannot be retrieved from {self.__target}",
208+
e,
209+
)
204210

205211
if self.__skip_verify:
206212
# Work with the certificate contents
@@ -257,7 +263,9 @@ def connect(self, timeout: int = None):
257263
# Set up SSL channel credentials
258264
if self.__path_key and self.__path_root:
259265
cert = grpc.ssl_channel_credentials(
260-
root_certificates=root_cert, private_key=key, certificate_chain=ssl_cert
266+
root_certificates=root_cert,
267+
private_key=key,
268+
certificate_chain=ssl_cert,
261269
)
262270

263271
else:
@@ -340,7 +348,11 @@ def capabilities(self):
340348

341349
for ree in gnmi_message_response.supported_models:
342350
response["supported_models"].append(
343-
{"name": ree.name, "organization": ree.organization, "version": ree.version}
351+
{
352+
"name": ree.name,
353+
"organization": ree.organization,
354+
"version": ree.version,
355+
}
344356
)
345357

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

393-
def get(self, prefix: str = "", path: list = None, target: str = None, datatype: str = "all", encoding: str = None):
405+
def get(
406+
self,
407+
prefix: str = "",
408+
path: list = None,
409+
target: str = None,
410+
datatype: str = "all",
411+
encoding: str = None,
412+
):
394413
"""
395414
Collecting the information about the resources from defined paths.
396415
@@ -453,7 +472,10 @@ def get(self, prefix: str = "", path: list = None, target: str = None, datatype:
453472

454473
try:
455474
gnmi_message_request = GetRequest(
456-
prefix=protobuf_prefix, path=protobuf_paths, type=pb_datatype, encoding=pb_encoding
475+
prefix=protobuf_prefix,
476+
path=protobuf_paths,
477+
type=pb_datatype,
478+
encoding=pb_encoding,
457479
)
458480
debug_gnmi_msg(self.__debug, gnmi_message_request, "gNMI request")
459481

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

646668
pre_change_dict = self.get(
647-
prefix=prefix, path=paths_to_collect_list, encoding=encoding, datatype="config"
669+
prefix=prefix,
670+
path=paths_to_collect_list,
671+
encoding=encoding,
672+
datatype="config",
648673
)
649674

650675
if gnmi_extension:
@@ -657,7 +682,10 @@ def set(
657682
)
658683
else:
659684
gnmi_message_request = SetRequest(
660-
prefix=protobuf_prefix, delete=del_protobuf_paths, update=update_msg, replace=replace_msg
685+
prefix=protobuf_prefix,
686+
delete=del_protobuf_paths,
687+
update=update_msg,
688+
replace=replace_msg,
661689
)
662690
debug_gnmi_msg(self.__debug, gnmi_message_request, "gNMI request")
663691

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

718746
diff_list = diff_openconfig(
719-
pre_dict=pre_change_dict, post_dict=post_change_dict, is_printable=is_printable
747+
pre_dict=pre_change_dict,
748+
post_dict=post_change_dict,
749+
is_printable=is_printable,
720750
)
721751

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

739769
def set_with_retry(
740-
self, delete: list = None, replace: list = None, update: list = None, encoding: str = None, retry_delay: int = 3
770+
self,
771+
delete: list = None,
772+
replace: list = None,
773+
update: list = None,
774+
encoding: str = None,
775+
retry_delay: int = 3,
741776
):
742777
"""
743778
Performs a set and retries (once) after a temporary failure with StatusCode.FAILED_PRECONDITION
@@ -890,7 +925,13 @@ def _build_subscriptionrequest(self, subscribe: dict, target: str = None, extens
890925
else:
891926
return SubscribeRequest(subscribe=request)
892927

893-
def subscribe(self, subscribe: dict = None, poll: bool = False, aliases: list = None, timeout: float = 0.0):
928+
def subscribe(
929+
self,
930+
subscribe: dict = None,
931+
poll: bool = False,
932+
aliases: list = None,
933+
timeout: float = 0.0,
934+
):
894935
"""
895936
Implementation of the subscribe gNMI RPC to pool
896937
"""
@@ -1113,7 +1154,8 @@ def next(self):
11131154
Blocks until one is available."""
11141155
return self._next_update(timeout=None)
11151156

1116-
def _next_update(self, timeout=None): ...
1157+
def _next_update(self, timeout=None):
1158+
...
11171159

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

13001342
elif update_msg.val.HasField("bytes_val"):
1301-
val_binary = ''.join(format(byte, '08b') for byte in update_msg.val.bytes_val)
1343+
val_binary = "".join(format(byte, "08b") for byte in update_msg.val.bytes_val)
13021344
val_decimal = struct.unpack("f", struct.pack("I", int(val_binary, 2)))[0]
1303-
update_container.update({'val': val_decimal})
1304-
1305-
elif update_msg.val.HasField('leaflist_val'):
1345+
update_container.update({"val": val_decimal})
1346+
1347+
elif update_msg.val.HasField("leaflist_val"):
13061348
val_leaflist = update_msg.val
13071349
element_str = ""
13081350
for element in val_leaflist.leaflist_val.element:
13091351
element_str += element
1310-
update_container.update({'val': element_str})
1352+
update_container.update({"val": element_str})
13111353

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

0 commit comments

Comments
 (0)