Skip to content

Commit bb93dc5

Browse files
author
SRBuilds
committed
pysros 22.2R1 is ready for customers
1 parent 5bc2e58 commit bb93dc5

30 files changed

+1954
-527
lines changed

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
author = 'Nokia'
2323

2424
# The full version, including alpha/beta/rc tags
25-
version = '21.10.1'
26-
release = '21.10.1'
25+
version = '22.2.1'
26+
release = '22.2.1'
2727

2828

2929
# -- General configuration ---------------------------------------------------

docs/source/ehs.rst

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
2+
The :mod:`pysros.ehs` module provides functionality obtain data from the
3+
specific event that triggered the execution of a Python application from
4+
the event handling system (EHS).
5+
6+
.. Reviewed by PLM 20220118
7+
.. Reviewed by TechComms 20220124
8+
9+
.. note:: This module is available when executing on SR OS only. On a remote
10+
machine, the event handling system (EHS) and its functionality
11+
are not supported.
12+
13+
.. Reviewed by PLM 20220117
14+
.. Reviewed by TechComms 20220124
15+
16+
.. py:function:: get_event
17+
18+
The EHS event that triggered the execution of the Python application.
19+
20+
:return: The Event object or None.
21+
:rtype: :py:class:`pysros.ehs.Event` or ``None``
22+
23+
.. Reviewed by PLM 20220118
24+
.. Reviewed by TechComms 20220124
25+
26+
.. class:: Event
27+
28+
The EHS event Class for the event that triggered the execution of the
29+
Python application.
30+
31+
.. py:attribute:: appid
32+
33+
The name of the application that generated the event.
34+
35+
:type: str
36+
37+
.. Reviewed by PLM 20220118
38+
.. Reviewed by TechComms 20220124
39+
40+
.. py:attribute:: eventid
41+
42+
The event ID number of the application.
43+
44+
:type: int
45+
46+
.. Reviewed by PLM 20220118
47+
.. Reviewed by TechComms 20220124
48+
49+
.. py:attribute:: severity
50+
51+
The severity level of the event.
52+
53+
:type: str
54+
55+
.. Reviewed by PLM 20220118
56+
.. Reviewed by TechComms 20220124
57+
58+
.. py:attribute:: subject
59+
60+
The subject or affected object of the event.
61+
62+
:type: str
63+
64+
.. Reviewed by PLM 20220118
65+
.. Reviewed by TechComms 20220124
66+
67+
.. py:attribute:: gentime
68+
69+
The formatted time, in ISO 8601 format, that the event was generated.
70+
71+
:type: str
72+
73+
.. Reviewed by PLM 20220118
74+
.. Reviewed by TechComms 20220124
75+
76+
.. py:attribute:: timestamp
77+
78+
The timestamp, in seconds, that the event was generated.
79+
80+
:type: float
81+
82+
.. Reviewed by PLM 20220118
83+
.. Reviewed by TechComms 20220124
84+
85+
.. function:: eventparameters
86+
87+
The additional parameters specific to the event that caused the
88+
Python application to execute.
89+
90+
:type: :py:class:`pysros.ehs.EventParams`
91+
92+
.. Reviewed by PLM 20220118
93+
.. Reviewed by TechComms 20220124
94+
95+
.. py:method:: format_msg
96+
97+
Return a string representation of the SR OS formatted log message.
98+
99+
:return: SR OS formatted log message.
100+
:rtype: str
101+
102+
.. Reviewed by PLM 20220118
103+
.. Reviewed by TechComms 20220124
104+
105+
.. class:: EventParams
106+
107+
The additional parameters of the specific :py:class:`pysros.ehs.Event`.
108+
This class is *read-only*. Specific additional parameters may be
109+
accessed using standard Python subscript syntax.
110+
111+
.. Reviewed by PLM 20220118
112+
.. Reviewed by TechComms 20220124
113+
114+
.. py:method:: keys
115+
116+
Obtain the additional parameters names.
117+
118+
:return: Additional parameters names for the Event.
119+
:rtype: tuple(str)
120+
121+
.. Reviewed by PLM 20220118
122+
.. Reviewed by TechComms 20220124
123+
124+
.. describe:: params[key]
125+
126+
Return the value of the parameter *key*. If the parameter does not exist,
127+
a :exc:`KeyError` is raised.
128+
129+
.. Reviewed by PLM 20220118
130+
.. Reviewed by TechComms 20220124
131+

docs/source/examples.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,44 @@ The example output for this application is shown here:
388388
.. Reviewed by TechComms 20210902
389389
390390
391+
Efficient YANG list key handling
392+
********************************
393+
394+
There are occasions where a set of specific entries in a YANG list are required.
395+
In these situations, use one of the following to obtain the key values for the list.
396+
397+
- Obtain the list from the node which is stored as a Python *dict* and then use ``.keys()`` on the
398+
dict to obtain the key values.
399+
- Use the :py:func:`pysros.management.Datastore.get_list_keys` function to obtain the list of the key values without
400+
obtaining the full data structure of the YANG list.
401+
402+
Using the :py:func:`pysros.management. Datastore.get_list_keys` function is significantly
403+
faster and uses less memory.
404+
405+
The following example compares and contrasts the different methods.
406+
407+
.. literalinclude:: ../../examples/get_list_keys_usage.py
408+
:caption: get_list_keys_usage.py
409+
:name: get-list-keys-usage-example
410+
:language: python
411+
412+
The example output for this application is shown here:
413+
414+
.. code-block:: none
415+
416+
get without defaults
417+
Output: dict_keys(['Base']) Time: 0.1393
418+
get with defaults
419+
Output: dict_keys(['Base', 'management', 'vpls-management']) Time: 0.7754
420+
get_list_keys without defaults
421+
Output: ['Base'] Time: 0.0859
422+
get_list_keys with defaults
423+
Output: ['Base', 'management', 'vpls-management'] Time: 0.1171
424+
425+
.. Reviewed by PLM 20220114
426+
.. Reviewed by TechComms 20220124
427+
428+
391429
Multi-device hardware inventory
392430
*******************************
393431

docs/source/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ documentation will be updated accordingly.
1616
.. list-table::
1717
:header-rows: 0
1818

19-
* - pySROS release: 21.10.1
20-
* - Document Number: 3HE 17936 AAAC TQZZA
19+
* - pySROS release: 22.2.1
20+
* - Document Number: 3HE 18378 AAAA TQZZA
2121

22-
.. Reviewed by PLM 20210902
23-
.. Reviewed by TechComms 20210902
22+
.. Reviewed by PLM 20220125
23+
.. Reviewed by TechComms 20220125
2424
2525
2626
.. toctree::

docs/source/modules.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@ pySROS modules
66

77
pysros
88

9-
Libraries adapted for SR OS
9+
10+
Libraries specific to SR OS
1011
===========================
1112

1213
The adapted versions of the modules documented here, are provided when
1314
executing on SR OS only. When executing on a remote device, the native
1415
Python versions of the library are used.
1516

1617
.. toctree::
17-
:maxdepth: 1
18+
:maxdepth: 6
1819

1920
utime
2021

2122

23+

docs/source/pysros.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
:undoc-members:
4545
:show-inheritance:
4646

47+
:mod:`pysros.ehs` - Functions for the event handling system (EHS)
48+
-------------------------------------------------------------------------
49+
50+
.. module:: pysros.ehs
51+
:synopsis: Functions for the SR OS event handling system (EHS)
52+
53+
.. include:: ehs.rst
54+
4755

4856

4957

examples/get_all_vprn_routes_with_nexthop_ipv4_address.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,19 @@ def get_input_args():
6666
def print_table(route_list, searched_ip_address):
6767
"""Setup and print the SR OS style table"""
6868
# compute total width of table
69-
cols = [(30, "Route"), (20, "Vprn"), (20, "Traffic Type"), (20, "Ipv Type")]
69+
cols = [
70+
(30, "Route"),
71+
(20, "Vprn"),
72+
(20, "Traffic Type"),
73+
(20, "Ipv Type"),
74+
]
7075
width = sum([col[0] for col in cols])
7176

7277
# init and print table
7378
table = Table(
74-
"Route List (nexthop: {})".format(searched_ip_address), cols, width=width
79+
"Route List (nexthop: {})".format(searched_ip_address),
80+
cols,
81+
width=width,
7582
)
7683
table.print(route_list)
7784

@@ -106,12 +113,16 @@ def main():
106113
for if_name in vrtr_state["interface"]:
107114
if_state = vrtr_state["interface"][if_name]
108115
if keys_exists(if_state, "ipv4", "primary", "oper-address"):
109-
oper_address = if_state["ipv4"]["primary"]["oper-address"].data
116+
oper_address = if_state["ipv4"]["primary"][
117+
"oper-address"
118+
].data
110119
ip_address = ipaddress.IPv4Address(oper_address)
111120
if_list.append((if_state["if-index"], if_name, ip_address))
112121

113122
# filter interface index list where ipv4 address is searched address
114-
if_index_list = [ifs[0].data for ifs in if_list if searched_ip_address == ifs[2]]
123+
if_index_list = [
124+
ifs[0].data for ifs in if_list if searched_ip_address == ifs[2]
125+
]
115126

116127
route_list = []
117128
# iterate all vprns
@@ -125,21 +136,25 @@ def main():
125136
if keys_exists(
126137
vrtr_state, "route-table", traffic_type, ipv_type, "route"
127138
):
128-
routes_state = vrtr_state["route-table"][traffic_type][ipv_type][
129-
"route"
130-
]
139+
routes_state = vrtr_state["route-table"][traffic_type][
140+
ipv_type
141+
]["route"]
131142
# iterate all routes
132143
for route_name in routes_state:
133144
if "nexthop" in routes_state[route_name]:
134145
# iterate all nexthop
135-
for nexthop_id in routes_state[route_name]["nexthop"]:
146+
for nexthop_id in routes_state[route_name][
147+
"nexthop"
148+
]:
136149
if keys_exists(
137-
routes_state[route_name]["nexthop"][nexthop_id],
150+
routes_state[route_name]["nexthop"][
151+
nexthop_id
152+
],
138153
"if-index",
139154
):
140-
nexthop_if_index = routes_state[route_name][
141-
"nexthop"
142-
][nexthop_id]["if-index"].data
155+
nexthop_if_index = routes_state[
156+
route_name
157+
]["nexthop"][nexthop_id]["if-index"].data
143158
nexthop_if_index = int(nexthop_if_index)
144159
# add route if nexthop interface in interface index list
145160
if nexthop_if_index in if_index_list:
@@ -156,13 +171,21 @@ def main():
156171
if keys_exists(vrtr_state, "static-routes"):
157172
for route in vrtr_state["static-routes"]["route"]:
158173
# if a route with a next-hop exists
159-
if keys_exists(vrtr_state["static-routes"]["route"][route], "next-hop"):
174+
if keys_exists(
175+
vrtr_state["static-routes"]["route"][route], "next-hop"
176+
):
160177
# identify whether the address portion of the CIDR address is IPv4 or IPv6
161-
version = ipaddress.ip_address(route[0].split("/")[0]).version
178+
version = ipaddress.ip_address(
179+
route[0].split("/")[0]
180+
).version
162181
if version == 4:
163-
route_list.append((route[0], vrtr_name, route[1], "ipv4"))
182+
route_list.append(
183+
(route[0], vrtr_name, route[1], "ipv4")
184+
)
164185
elif version == 6:
165-
route_list.append((route[0], vrtr_name, route[1], "ipv6"))
186+
route_list.append(
187+
(route[0], vrtr_name, route[1], "ipv6")
188+
)
166189
else:
167190
print("Unknown whether ipv4 or ipv6")
168191
sys.exit(-1)
@@ -173,8 +196,6 @@ def main():
173196
# disconnect from router
174197
connection_object.disconnect()
175198

176-
return 0
177-
178199

179200
if __name__ == "__main__":
180201
main()

0 commit comments

Comments
 (0)