sc-napalm 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ .env
2
+ .venv
3
+ __pycache__
4
+ *.egg-info
5
+ *.swp
6
+ *.python-version
@@ -0,0 +1,108 @@
1
+ Metadata-Version: 2.4
2
+ Name: sc-napalm
3
+ Version: 0.1.0
4
+ Summary: Add your description here
5
+ Requires-Python: >=3.8
6
+ Requires-Dist: gitpython>=3.1.45
7
+ Requires-Dist: lxml>=6.0.2
8
+ Requires-Dist: napalm-srl>=1.0.5
9
+ Requires-Dist: napalm-sros>=1.0.2
10
+ Requires-Dist: napalm>=5.1.0
11
+ Requires-Dist: pynautobot>=2.1.1
12
+ Requires-Dist: python-decouple>=3.8
13
+ Description-Content-Type: text/markdown
14
+
15
+ # sc-napalm
16
+
17
+ This repo is for building custom [NAPALM](https://napalm.readthedocs.io/en/latest/) "getters" to pull operational data from network devices.
18
+ At the moment only one custom getter is implemented: `get_inventory`, and it is only implemented for junos, iosxr, and nxos.
19
+
20
+ What's cool about NAPALM is that if you nest your custom drivers under `custom_napalm` as is done in this project, when you call `get_network_driver`
21
+ in a runtime environment that has your modules, these drivers will override the core NAPALM drivers. This allows us to leverage NAPALM in a pretty seamless way,
22
+ in particular it allows us to use the [nornir-napalm](https://github.com/nornir-automation/nornir_napalm) connection plugins and tasks to point at our custom drivers.
23
+
24
+
25
+ ## Using sc-napalm
26
+ For now the repo comes with two scripts:
27
+ * `sc-napalm-get` will run a particular getter against a particular device and output the results to your terminal.
28
+ * `sc-napalm-run` uses Nornir to run a set of getters against a set of devices in Nautobot and print out the results.
29
+
30
+ Right now to use this code you must do the following things:
31
+ 1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/)
32
+ 2. Clone the repo onto your local machine, then do a local development install of the repo into a uv virtual environment.
33
+ ```
34
+ git clone https://scinet.supercomputing.org:8443/automation/sc25/sc-napalm.git
35
+ cd sc-napalm
36
+ uv run pip install -e .
37
+ ```
38
+ 3. Copy `sample_env` file into `.env` and fill out `.env` with the credentials you need. Some notes about this.
39
+ - You only need the nautobot stuff for `sc-napalm-run`.
40
+ - You could also specify these values in your local environment as well, the scripts will check there if they're not set in `.env`
41
+
42
+ 4. Run the two scripts with `uv run [the script]`.
43
+ ```
44
+ amylieb@m-n76107kqmh sc-napalm % uv run sc-napalm-get -h
45
+ usage: sc-napalm-get [-h] [-l {DEBUG,INFO,WARNING,ERROR,CRITICAL} | -L {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--logfile LOGFILE] [--username USERNAME]
46
+ [--password PASSWORD]
47
+ device {iosxr,nxos,junos,sros,srl,eos} {get_config,get_facts,get_lldp_neighbors,get_inventory}
48
+
49
+ Run a specific sc_napalm "getter" against a device.
50
+
51
+ positional arguments:
52
+ device device hostname or IP address
53
+ {iosxr,nxos,junos,sros,srl,eos}
54
+ The platform of this device
55
+ {get_config,get_facts,get_lldp_neighbors,get_inventory}
56
+ The getter command to run against this device
57
+
58
+ options:
59
+ -h, --help show this help message and exit
60
+ -l, --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
61
+ Set log level for sc_napalm only
62
+ -L, --LOG-LEVEL {DEBUG,INFO,WARNING,ERROR,CRITICAL}
63
+ set global log level
64
+ --logfile LOGFILE Save logging to a file (specified by name) instead of to stdout
65
+ --username USERNAME Specify credentials
66
+ --password PASSWORD Specify credentials
67
+ amylieb@m-n76107kqmh sc-napalm % uv run sc-napalm-get dl-shallow-1 nxos get_inventory
68
+ [{'name': 'Slot 1',
69
+ 'part_number': 'N9K-C93180YC-FX',
70
+ 'serial_number': 'FLM252403M9',
71
+ 'type': 'linecard'},
72
+ {'name': 'Fan 1',
73
+ 'part_number': 'NXA-FAN-30CFM-B',
74
+ 'serial_number': 'N/A',
75
+ 'type': 'fan'},
76
+ .....
77
+
78
+ amylieb@m-n76107kqmh sc-napalm % uv run sc-napalm-run --device amytest --cmds get_facts
79
+ Uninstalled 1 package in 8ms
80
+ Installed 1 package in 3ms
81
+ napalm_get**********************************************************************
82
+ * amytest ** changed : False ***************************************************
83
+ vvvv napalm_get ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
84
+ { 'get_facts': { 'fqdn': '',
85
+ 'hostname': 'dl-shallow-1',
86
+ 'interface_list': [ 'Management0',
87
+ 'Ethernet1/1',
88
+ 'Ethernet1/2',
89
+ 'Ethernet1/3',
90
+ 'Ethernet1/4',
91
+ 'Ethernet1/5',
92
+ ```
93
+
94
+ ## Developing sc-napalm
95
+ Currently, the getters that are exposed as options in the `get` and `run` scripts are defined in the [base class](https://scinet.supercomputing.org:8443/automation/sc25/sc-napalm/-/blob/main/src/custom_napalm/base.py?ref_type=heads) of the custom drivers.
96
+ Note that because all the custom classes inherit the NAPALM getters, we could easily define all the other NAPALM getters there, but I've only included ones I think are obviously useful to us.
97
+
98
+ My hope is that instead of just printing out results we can write code that saves data in Nautobot, or some other place. This could be done with custom Nornir tasks or with Processors.
99
+
100
+ I have also noticed that Nautobot has a Nornir plugin - we could potentially leverage that as well.
101
+
102
+ ## To-dos
103
+ * Decide where this code is run and how (periodically? Manually? From Nautobot? if so, how?)
104
+ * Decide what output we want to capture (eg "show version"? "show lldp neighbor"?) and where it should go
105
+ * Fuctions/tasks that transform output and save it appropriately
106
+ * `get_inventory` methods for eos, srlinux, sros
107
+ * Test/mock classes for custom getters
108
+
@@ -0,0 +1,94 @@
1
+ # sc-napalm
2
+
3
+ This repo is for building custom [NAPALM](https://napalm.readthedocs.io/en/latest/) "getters" to pull operational data from network devices.
4
+ At the moment only one custom getter is implemented: `get_inventory`, and it is only implemented for junos, iosxr, and nxos.
5
+
6
+ What's cool about NAPALM is that if you nest your custom drivers under `custom_napalm` as is done in this project, when you call `get_network_driver`
7
+ in a runtime environment that has your modules, these drivers will override the core NAPALM drivers. This allows us to leverage NAPALM in a pretty seamless way,
8
+ in particular it allows us to use the [nornir-napalm](https://github.com/nornir-automation/nornir_napalm) connection plugins and tasks to point at our custom drivers.
9
+
10
+
11
+ ## Using sc-napalm
12
+ For now the repo comes with two scripts:
13
+ * `sc-napalm-get` will run a particular getter against a particular device and output the results to your terminal.
14
+ * `sc-napalm-run` uses Nornir to run a set of getters against a set of devices in Nautobot and print out the results.
15
+
16
+ Right now to use this code you must do the following things:
17
+ 1. [Install uv](https://docs.astral.sh/uv/getting-started/installation/)
18
+ 2. Clone the repo onto your local machine, then do a local development install of the repo into a uv virtual environment.
19
+ ```
20
+ git clone https://scinet.supercomputing.org:8443/automation/sc25/sc-napalm.git
21
+ cd sc-napalm
22
+ uv run pip install -e .
23
+ ```
24
+ 3. Copy `sample_env` file into `.env` and fill out `.env` with the credentials you need. Some notes about this.
25
+ - You only need the nautobot stuff for `sc-napalm-run`.
26
+ - You could also specify these values in your local environment as well, the scripts will check there if they're not set in `.env`
27
+
28
+ 4. Run the two scripts with `uv run [the script]`.
29
+ ```
30
+ amylieb@m-n76107kqmh sc-napalm % uv run sc-napalm-get -h
31
+ usage: sc-napalm-get [-h] [-l {DEBUG,INFO,WARNING,ERROR,CRITICAL} | -L {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--logfile LOGFILE] [--username USERNAME]
32
+ [--password PASSWORD]
33
+ device {iosxr,nxos,junos,sros,srl,eos} {get_config,get_facts,get_lldp_neighbors,get_inventory}
34
+
35
+ Run a specific sc_napalm "getter" against a device.
36
+
37
+ positional arguments:
38
+ device device hostname or IP address
39
+ {iosxr,nxos,junos,sros,srl,eos}
40
+ The platform of this device
41
+ {get_config,get_facts,get_lldp_neighbors,get_inventory}
42
+ The getter command to run against this device
43
+
44
+ options:
45
+ -h, --help show this help message and exit
46
+ -l, --log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
47
+ Set log level for sc_napalm only
48
+ -L, --LOG-LEVEL {DEBUG,INFO,WARNING,ERROR,CRITICAL}
49
+ set global log level
50
+ --logfile LOGFILE Save logging to a file (specified by name) instead of to stdout
51
+ --username USERNAME Specify credentials
52
+ --password PASSWORD Specify credentials
53
+ amylieb@m-n76107kqmh sc-napalm % uv run sc-napalm-get dl-shallow-1 nxos get_inventory
54
+ [{'name': 'Slot 1',
55
+ 'part_number': 'N9K-C93180YC-FX',
56
+ 'serial_number': 'FLM252403M9',
57
+ 'type': 'linecard'},
58
+ {'name': 'Fan 1',
59
+ 'part_number': 'NXA-FAN-30CFM-B',
60
+ 'serial_number': 'N/A',
61
+ 'type': 'fan'},
62
+ .....
63
+
64
+ amylieb@m-n76107kqmh sc-napalm % uv run sc-napalm-run --device amytest --cmds get_facts
65
+ Uninstalled 1 package in 8ms
66
+ Installed 1 package in 3ms
67
+ napalm_get**********************************************************************
68
+ * amytest ** changed : False ***************************************************
69
+ vvvv napalm_get ** changed : False vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv INFO
70
+ { 'get_facts': { 'fqdn': '',
71
+ 'hostname': 'dl-shallow-1',
72
+ 'interface_list': [ 'Management0',
73
+ 'Ethernet1/1',
74
+ 'Ethernet1/2',
75
+ 'Ethernet1/3',
76
+ 'Ethernet1/4',
77
+ 'Ethernet1/5',
78
+ ```
79
+
80
+ ## Developing sc-napalm
81
+ Currently, the getters that are exposed as options in the `get` and `run` scripts are defined in the [base class](https://scinet.supercomputing.org:8443/automation/sc25/sc-napalm/-/blob/main/src/custom_napalm/base.py?ref_type=heads) of the custom drivers.
82
+ Note that because all the custom classes inherit the NAPALM getters, we could easily define all the other NAPALM getters there, but I've only included ones I think are obviously useful to us.
83
+
84
+ My hope is that instead of just printing out results we can write code that saves data in Nautobot, or some other place. This could be done with custom Nornir tasks or with Processors.
85
+
86
+ I have also noticed that Nautobot has a Nornir plugin - we could potentially leverage that as well.
87
+
88
+ ## To-dos
89
+ * Decide where this code is run and how (periodically? Manually? From Nautobot? if so, how?)
90
+ * Decide what output we want to capture (eg "show version"? "show lldp neighbor"?) and where it should go
91
+ * Fuctions/tasks that transform output and save it appropriately
92
+ * `get_inventory` methods for eos, srlinux, sros
93
+ * Test/mock classes for custom getters
94
+
@@ -0,0 +1,45 @@
1
+ [project]
2
+ name = "sc-napalm"
3
+ version = "0.1.0"
4
+ description = "Add your description here"
5
+ readme = "README.md"
6
+ requires-python = ">=3.8"
7
+ dependencies = [
8
+ "gitpython>=3.1.45",
9
+ "lxml>=6.0.2",
10
+ "napalm>=5.1.0",
11
+ "napalm-srl>=1.0.5",
12
+ "napalm-sros>=1.0.2",
13
+ "pynautobot>=2.1.1",
14
+ "python-decouple>=3.8",
15
+ ]
16
+
17
+
18
+ [build-system]
19
+ requires = ["hatchling"]
20
+ build-backend = "hatchling.build"
21
+
22
+ [project.scripts]
23
+ sc-napalm-get = "custom_napalm.get:main"
24
+
25
+ [tool.hatch.build.targets.wheel]
26
+ packages = ["src/custom_napalm"]
27
+
28
+ [tool.hatch.build]
29
+ include = [
30
+ "src/custom_napalm/junos/*.yml",
31
+ "src/custom_napalm/nxos/*.tpl",
32
+ ]
33
+
34
+ [dependency-groups]
35
+ dev = [
36
+ "pytest>=8.3.5",
37
+ "ruff>=0.14.3",
38
+ ]
39
+
40
+ [tool.pytest.ini_options]
41
+ filterwarnings = [
42
+ "ignore::DeprecationWarning",
43
+ ]
44
+
45
+
@@ -0,0 +1,228 @@
1
+ ### ip interfaces ###
2
+ junos_ip_interfaces:
3
+ rpc: get-interface-information
4
+ item: physical-interface/logical-interface/address-family/interface-address
5
+ key: ifa-local
6
+ view: junos_ip_interfaces_view
7
+
8
+ junos_ip_interfaces_view:
9
+ fields:
10
+ ip: ifa-local
11
+ subnet: ifa-destination
12
+ family: ../address-family-name
13
+ interface: ../../name
14
+ mtu: ../mtu
15
+ description: ../../description
16
+ primary: ifa-flags/ifaf-current-primary
17
+ preferred: ifa-flags/ifaf-current-preferred
18
+ admin_up: ../../if-config-flags/iff-up
19
+ device_down: ../../if-config-flags/iff-device-down
20
+ hardware_down: ../../if-config-flags/iff-hardware-down
21
+
22
+
23
+ junos_vrf_interfaces:
24
+ rpc: get-instance-information
25
+ args:
26
+ detail: True
27
+ item: instance-core/instance-interface
28
+ key: interface-name
29
+ view: junos_vrf_interfaces_view
30
+
31
+ junos_vrf_interfaces_view:
32
+ fields:
33
+ vrf: ../instance-name
34
+
35
+ ## show route active-path ####
36
+ junos_route_table:
37
+ rpc: get-route-information
38
+ item: route-table/rt
39
+ args:
40
+ active-path: True
41
+ key:
42
+ - rt-destination
43
+ - ../table-name
44
+ view: junos_route_table_view
45
+
46
+ junos_route_table_view:
47
+ fields:
48
+ vrf: ../table-name
49
+ prefix: rt-destination
50
+ rt_entry: _entry_table
51
+
52
+ _entry_table:
53
+ item: rt-entry
54
+ key:
55
+ - protocol-name
56
+ - learned-from
57
+ view: _entry_view
58
+
59
+ _entry_view:
60
+ fields:
61
+ age: age
62
+ protocol: protocol-name
63
+ learned_from: gateway
64
+ next_hop: _nh_table
65
+
66
+ _nh_table:
67
+ item: nh
68
+ key:
69
+ - to
70
+ - via
71
+ view: _nh_view
72
+
73
+ _nh_view:
74
+ fields:
75
+ nh_ip: to
76
+ nh_interface: via
77
+ mpls_label: mpls-label
78
+ selected_next_hop: selected-next-hop
79
+ # nh_table_receive: nh-table-receive
80
+ # nh_table: nh-table
81
+
82
+ ### show route table mpls ###
83
+ junos_mpls_table:
84
+ rpc: get-route-information
85
+ item: route-table/rt
86
+ args:
87
+ table: mpls.0
88
+ active-path: True
89
+ key:
90
+ - rt-destination
91
+ view: junos_mpls_table_view
92
+
93
+ junos_mpls_table_view:
94
+ fields:
95
+ prefix: rt-destination
96
+ rt_entry: _mpls_entry_table
97
+
98
+ _mpls_entry_table:
99
+ item: rt-entry
100
+ key:
101
+ - protocol-name
102
+ - learned-from
103
+ view: _mpls_entry_view
104
+
105
+ _mpls_entry_view:
106
+ fields:
107
+ next_hop: _mpls_nh_table
108
+
109
+ _mpls_nh_table:
110
+ item: nh
111
+ key:
112
+ - to
113
+ - via
114
+ view: _mpls_nh_view
115
+
116
+ _mpls_nh_view:
117
+ fields:
118
+ nh_ip: to
119
+ nh_interface: via
120
+ mpls_label: mpls-label
121
+ # selected_next_hop: selected-next-hop
122
+ nh_table_receive: nh-table-receive
123
+ nh_table: nh-table
124
+
125
+
126
+ ### show chassis inventory ###
127
+ junos_inventory:
128
+ rpc: get-chassis-inventory
129
+ item: chassis
130
+ view: junos_inventory_view
131
+
132
+ junos_inventory_view:
133
+ fields:
134
+ system_serial: serial-number
135
+ system_description: description
136
+ modules: _module_table
137
+
138
+ _module_table:
139
+ item: chassis-module
140
+ key: name
141
+ view: _module_view
142
+
143
+ _module_view:
144
+ fields:
145
+ name: name
146
+ part_number: part-number
147
+ serial_number: serial-number
148
+ description: description
149
+ model_number: model-number
150
+ sub_modules: _sub_module_table
151
+
152
+ _sub_module_table:
153
+ item: chassis-sub-module
154
+ key: name
155
+ view: _sub_module_view
156
+
157
+ _sub_module_view:
158
+ fields:
159
+ name: name
160
+ part_number: part-number
161
+ serial_number: serial-number
162
+ description: description
163
+ model_number: model-number
164
+ sub_sub_modules: _sub_sub_module_table
165
+
166
+ _sub_sub_module_table:
167
+ item: chassis-sub-sub-module
168
+ key: name
169
+ view: _sub_sub_module_view
170
+
171
+ _sub_sub_module_view:
172
+ fields:
173
+ name: name
174
+ part_number: part-number
175
+ serial_number: serial-number
176
+ description: description
177
+ model_number: model-number
178
+
179
+
180
+ ### show route summary (for determining VPNs for ARP table) ###
181
+ junos_route_summary:
182
+ rpc: get-route-summary-information
183
+ item: route-table
184
+ key: table-name
185
+ view: junos_route_summary_view
186
+
187
+ junos_route_summary_view:
188
+ fields:
189
+ table: table-name
190
+
191
+
192
+ junos_show_int_lag:
193
+ rpc: get-interface-information
194
+ args:
195
+ terse: True
196
+ item: physical-interface/logical-interface
197
+ key: name
198
+ view: junos_show_int_lag_view
199
+
200
+ junos_show_int_lag_view:
201
+ fields:
202
+ phy_admin_status: ../admin-status
203
+ admin_status: admin-status
204
+ oper_status: oper-status
205
+ lag_name: address-family/ae-bundle-name
206
+
207
+
208
+ junos_show_lacp:
209
+ rpc: get-lacp-interface-information
210
+ item: lacp-interface-information
211
+ key: lag-lacp-header/aggregate-name
212
+ view: show_lacp_view
213
+
214
+ show_lacp_view:
215
+ fields:
216
+ name: lag-lacp-header/aggregate-name
217
+ members: _lacp_member_table
218
+
219
+ _lacp_member_table:
220
+ item: lag-lacp-state
221
+ key: name
222
+ view: _show_lacp_member_view
223
+
224
+ _show_lacp_member_view:
225
+ fields:
226
+ lacp_timeout: lacp-timeout
227
+ lacp_activity: lacp-activity
228
+