napalm-bsd 0.5.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.
- napalm_bsd-0.5.0/LICENSE +165 -0
- napalm_bsd-0.5.0/PKG-INFO +131 -0
- napalm_bsd-0.5.0/README.md +98 -0
- napalm_bsd-0.5.0/napalm_bsd/__init__.py +6 -0
- napalm_bsd-0.5.0/napalm_bsd/base.py +553 -0
- napalm_bsd-0.5.0/napalm_bsd/freebsd.py +128 -0
- napalm_bsd-0.5.0/napalm_bsd/openbsd.py +91 -0
- napalm_bsd-0.5.0/napalm_bsd/parse.py +497 -0
- napalm_bsd-0.5.0/napalm_bsd/py.typed +0 -0
- napalm_bsd-0.5.0/napalm_bsd.egg-info/PKG-INFO +131 -0
- napalm_bsd-0.5.0/napalm_bsd.egg-info/SOURCES.txt +18 -0
- napalm_bsd-0.5.0/napalm_bsd.egg-info/dependency_links.txt +1 -0
- napalm_bsd-0.5.0/napalm_bsd.egg-info/entry_points.txt +3 -0
- napalm_bsd-0.5.0/napalm_bsd.egg-info/requires.txt +9 -0
- napalm_bsd-0.5.0/napalm_bsd.egg-info/top_level.txt +1 -0
- napalm_bsd-0.5.0/pyproject.toml +86 -0
- napalm_bsd-0.5.0/setup.cfg +4 -0
- napalm_bsd-0.5.0/tests/test_drivers.py +719 -0
- napalm_bsd-0.5.0/tests/test_parse.py +357 -0
- napalm_bsd-0.5.0/tests/test_ssh_host_key.py +109 -0
napalm_bsd-0.5.0/LICENSE
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship made available under
|
|
36
|
+
the License, as indicated by a copyright notice that is included in
|
|
37
|
+
or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
43
|
+
of this License, Derivative Works shall not include works that remain
|
|
44
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
45
|
+
the Work and Derivative Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean, as submitted to the Licensor for inclusion
|
|
48
|
+
in the Work by the copyright owner or by an individual or Legal Entity
|
|
49
|
+
authorized to submit on behalf of the copyright owner. For the purposes
|
|
50
|
+
of this definition, "submitted" means any form of electronic, verbal,
|
|
51
|
+
or written communication sent to the Licensor or its representatives,
|
|
52
|
+
including but not limited to communication on electronic mailing lists,
|
|
53
|
+
source code control systems, and issue tracking systems that are managed
|
|
54
|
+
by, or on behalf of, the Licensor for the purpose of tracking and
|
|
55
|
+
discussing the Work, but excluding communication that is conspicuously
|
|
56
|
+
marked or designated in writing by the copyright owner as "Not a
|
|
57
|
+
Contribution."
|
|
58
|
+
|
|
59
|
+
"Contributor" shall mean Licensor and any Legal Entity on behalf of
|
|
60
|
+
whom a Contribution has been received by the Licensor and included
|
|
61
|
+
within the Work.
|
|
62
|
+
|
|
63
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
64
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
65
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
66
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
67
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
68
|
+
Work and such Derivative Works in Source or Object form.
|
|
69
|
+
|
|
70
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
71
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
72
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
73
|
+
(except as stated in this section) patent license to make, have made,
|
|
74
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
75
|
+
where such license applies only to those patent claims licensable
|
|
76
|
+
by such Contributor that are necessarily infringed by their
|
|
77
|
+
Contribution(s) alone or by the combination of their Contributions
|
|
78
|
+
with the Work to which such Contributions were submitted. If You
|
|
79
|
+
institute patent litigation against any entity (including a cross-claim
|
|
80
|
+
or counterclaim in a lawsuit) alleging that the Work or any
|
|
81
|
+
Contribution embodied within the Work constitutes direct or contributory
|
|
82
|
+
patent infringement, then any patent licenses granted to You under
|
|
83
|
+
this License for that Work shall terminate as of the date such
|
|
84
|
+
litigation is filed.
|
|
85
|
+
|
|
86
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
87
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
88
|
+
modifications, and in Source or Object form, provided that You
|
|
89
|
+
meet the following conditions:
|
|
90
|
+
|
|
91
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
92
|
+
Works a copy of this License; and
|
|
93
|
+
|
|
94
|
+
(b) You must cause any modified files to carry prominent notices
|
|
95
|
+
stating that You changed the files; and
|
|
96
|
+
|
|
97
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
98
|
+
that You distribute, all copyright, patent, trademark, and
|
|
99
|
+
attribution notices from the Source form of the Work,
|
|
100
|
+
excluding those notices that do not pertain to any part of
|
|
101
|
+
the Derivative Works; and
|
|
102
|
+
|
|
103
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
104
|
+
distribution, You must include a readable copy of the
|
|
105
|
+
attribution notices contained within such NOTICE file, in
|
|
106
|
+
at least one of the following places: within a NOTICE text
|
|
107
|
+
file distributed as part of the Derivative Works; within
|
|
108
|
+
the Source form or documentation, if provided along with the
|
|
109
|
+
Derivative Works; or, within a display generated by the
|
|
110
|
+
Derivative Works, if and wherever such third-party notices
|
|
111
|
+
normally appear. The contents of the NOTICE file are for
|
|
112
|
+
informational purposes only and do not modify the License.
|
|
113
|
+
You may add Your own attribution notices within Derivative
|
|
114
|
+
Works that You distribute, alongside or in addition to the
|
|
115
|
+
NOTICE text from the Work, provided that such additional
|
|
116
|
+
attribution notices cannot be construed as modifying the License.
|
|
117
|
+
|
|
118
|
+
You may add Your own license statement for Your modifications and
|
|
119
|
+
may provide additional grant of rights to use, copy, modify, merge,
|
|
120
|
+
publish, sublicense, and/or sell copies of the Work, and to permit
|
|
121
|
+
persons to whom the Work is furnished to do so.
|
|
122
|
+
|
|
123
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
124
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
125
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
126
|
+
this License, without any additional terms or conditions.
|
|
127
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
128
|
+
the terms of any separate license agreement you may have executed
|
|
129
|
+
with Licensor regarding such Contributions.
|
|
130
|
+
|
|
131
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
132
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
133
|
+
except as required for reasonable and customary use in describing the
|
|
134
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
137
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
138
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
139
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
140
|
+
implied, including, without limitation, any conditions of TITLE,
|
|
141
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
142
|
+
PURPOSE. You are solely responsible for determining the
|
|
143
|
+
appropriateness of using or reproducing the Work and assume any
|
|
144
|
+
risks associated with Your exercise of permissions under this License.
|
|
145
|
+
|
|
146
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
147
|
+
whether in tort (including negligence), strict liability, or contract
|
|
148
|
+
shall any Contributor be liable to You for damages, including any
|
|
149
|
+
direct, indirect, special, incidental, or exemplary damages of any
|
|
150
|
+
character arising as a result of this License or out of the use or
|
|
151
|
+
inability to use the Work (even if such Contributor has been advised
|
|
152
|
+
of the possibility of such damages).
|
|
153
|
+
|
|
154
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
155
|
+
the Work or Derivative Works thereof, You may choose to offer, and
|
|
156
|
+
charge a fee for, acceptance of support, warranty, indemnity, or other
|
|
157
|
+
liability obligations and/or rights consistent with this License.
|
|
158
|
+
However, in accepting such obligations, You may offer only your own
|
|
159
|
+
liability and not on behalf of any other Contributor, and only if
|
|
160
|
+
You agree to indemnify, defend, and hold each Contributor harmless
|
|
161
|
+
for any liability incurred by, or claims asserted against, such
|
|
162
|
+
Contributor by reason of your accepting any such warranty or
|
|
163
|
+
additional liability.
|
|
164
|
+
|
|
165
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: napalm-bsd
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: NAPALM drivers for FreeBSD and OpenBSD hosts via SSH
|
|
5
|
+
Author-email: Christian Manivong <christian@manivong.de>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Repository, https://git.netork.io/NAPALM/napalm-bsd
|
|
8
|
+
Project-URL: Issues, https://git.netork.io/NAPALM/napalm-bsd/issues
|
|
9
|
+
Project-URL: Changelog, https://git.netork.io/NAPALM/napalm-bsd/src/branch/main/CHANGELOG.md
|
|
10
|
+
Keywords: napalm,network,automation,freebsd,openbsd,bsd,ssh,driver
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: System :: Systems Administration
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: napalm>=4.0
|
|
25
|
+
Requires-Dist: napalm-device-types>=4.21.1
|
|
26
|
+
Requires-Dist: paramiko>=5.0.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=8; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=5; extra == "dev"
|
|
30
|
+
Requires-Dist: mypy>=1.11; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff>=0.6; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# napalm-bsd
|
|
35
|
+
|
|
36
|
+
NAPALM drivers for **FreeBSD** (`freebsd`) and **OpenBSD** (`openbsd`) hosts,
|
|
37
|
+
over SSH, built on [napalm-device-types](https://git.netork.io/NAPALM/napalm-device-types)'
|
|
38
|
+
`OSDriver`. Written for netOrk, which provisions and manages BSD VMs
|
|
39
|
+
(NetOrk/netork#792).
|
|
40
|
+
|
|
41
|
+
## Design
|
|
42
|
+
|
|
43
|
+
- One shared `BsdDriver` (`napalm_bsd/base.py`) holds the SSH layer and every
|
|
44
|
+
reader whose tools agree between the BSDs. `FreeBSDDriver` and
|
|
45
|
+
`OpenBSDDriver` name only the commands that differ (hostname, release,
|
|
46
|
+
kernel, hardware, `netstat -rnW` vs `-rn`).
|
|
47
|
+
- Every command runs on its own SSH **exec channel** (`run_on_transport` from
|
|
48
|
+
napalm-device-types): no PTY to parse a prompt from, stdout and stderr apart,
|
|
49
|
+
a real exit status. `run_command()` / `open_stream()` are public
|
|
50
|
+
(`CommandChannelMixin`).
|
|
51
|
+
- Root comes from `sudo -S` with the sudo password on stdin (never on a command
|
|
52
|
+
line), or `sudo -n` without one, as in napalm-linux. netOrk provisions `sudo`
|
|
53
|
+
on BSD VMs for that reason; `doas` cannot read a password from stdin.
|
|
54
|
+
- Parsing is in `napalm_bsd/parse.py`, pure functions tested on output recorded
|
|
55
|
+
from real systems (`tests/fixtures/`, each directory's `COMMANDS.txt` lists
|
|
56
|
+
what produced it).
|
|
57
|
+
|
|
58
|
+
## Supported getters
|
|
59
|
+
|
|
60
|
+
| Getter | FreeBSD | OpenBSD | Source |
|
|
61
|
+
|---|---|---|---|
|
|
62
|
+
| `get_facts` | ✓ | ✓ | `kern.hostname`/`hostname`, `freebsd-version`/`uname`, `kenv smbios.*`/`hw.*`, `kern.boottime` |
|
|
63
|
+
| `get_interfaces`, `get_interfaces_ip` | ✓ | ✓ | `ifconfig -a` |
|
|
64
|
+
| `get_route_to` | ✓ | ✓ | `netstat -rnW` / `netstat -rn` |
|
|
65
|
+
| `get_arp_table` | ✓ | ✓ | `arp -an` |
|
|
66
|
+
| `get_lldp_neighbors` | `{}` | `{}` | no LLDP daemon in either base system |
|
|
67
|
+
| `get_os_users`, `get_processes`, `get_cron_jobs` | ✓ | ✓ | `/etc/passwd`+`/etc/group`, `ps … lstart`, system crontab + `crontab -l` |
|
|
68
|
+
| `get_listening_sockets` | ✓ | ✓ | `sockstat -46lq` / `fstat -n` as root, `netstat -an` without |
|
|
69
|
+
| `get_packages`, `install_package`, `uninstall_package` | ✓ | ✓ | `pkg query` / `pkg install`, `pkg delete`; `pkg_info` / `pkg_add -I`, `pkg_delete` |
|
|
70
|
+
| `get_available_updates` | ✓ | ✓ | `pkg upgrade -n` + `pkg audit` (VuXML); `pkg_add -u -n -v` + `syspatch -c` |
|
|
71
|
+
| `get_services`, `manage_service` | ✓ | ✓ | `service -e` + `service … status` / `service … <action>`; `rcctl ls on` + `rcctl check` / `rcctl <action>` |
|
|
72
|
+
| `run_device_action("fix_snmp")`, `get_snmp_config` | ✓ | ✓ | net-snmp from packages: `/usr/local/etc/snmp/snmpd.conf` + `service snmpd`; `/etc/snmp/snmpd.conf` + `rcctl … netsnmpd` |
|
|
73
|
+
| `get_host_status` | ✓ | unknown | napalm-device-types' host status: on FreeBSD `freebsd-version -k` vs `-r` (4.1+) |
|
|
74
|
+
| `first_boot_pending` | ✓ | always `False` | whether `/firstboot` still exists |
|
|
75
|
+
|
|
76
|
+
`get_listening_sockets` has the shape of napalm-device-types'
|
|
77
|
+
`ListeningSocketsMixin` (whose `ss`/cgroup reading is Linux's) and its rule:
|
|
78
|
+
read as root first, without root when that brings nothing back
|
|
79
|
+
(`attributed: False`). FreeBSD's `sockstat` sees every socket either way;
|
|
80
|
+
OpenBSD's `fstat` shows a user only their own processes, so without root the
|
|
81
|
+
sockets come from `netstat -an`, unnamed.
|
|
82
|
+
|
|
83
|
+
There is deliberately no `get_kernel_facts`: `KernelFactsMixin` reports a
|
|
84
|
+
Linux kernel's modules and `CONFIG_*` options, which a BSD kernel does not
|
|
85
|
+
have, and `hasattr(driver, "get_kernel_facts")` has to stay truthful.
|
|
86
|
+
|
|
87
|
+
**Updates.** `security` on FreeBSD comes from VuXML (`pkg audit`): True for a
|
|
88
|
+
package it lists as vulnerable, False for one it does not, None when the audit
|
|
89
|
+
could not run. OpenBSD's tools do not say, so it is None there. Base-system
|
|
90
|
+
patches are one entry, `base-system` (NetOrk/netork#799): OpenBSD's
|
|
91
|
+
`syspatch` applies its patches together and in order; a classic FreeBSD base
|
|
92
|
+
reports what `freebsd-update` has fetched (`updatesready`). On FreeBSD with
|
|
93
|
+
pkgbase the base system is packages from the `FreeBSD-base` repository and
|
|
94
|
+
needs no extra entry.
|
|
95
|
+
|
|
96
|
+
A reader that cannot read **raises** rather than return an empty list: netOrk
|
|
97
|
+
takes `[]` as "no updates" and would close every patch clock on the host. That
|
|
98
|
+
covers a refused sudo, a failing `pkg`, `syspatch` or `freebsd-update`, and a pkg
|
|
99
|
+
database pkg cannot read (only pkg's "not installed" means no packages).
|
|
100
|
+
|
|
101
|
+
**Reboot.** `get_host_status` reports a FreeBSD host whose installed kernel
|
|
102
|
+
(`freebsd-version -k`) differs from the running one (`-r`) as needing a reboot.
|
|
103
|
+
OpenBSD has no such reading yet, so it stays unknown there.
|
|
104
|
+
|
|
105
|
+
**First boot.** A FreeBSD cloud image upgrades its base system on its first boot,
|
|
106
|
+
starts sshd only after that and restarts right away. `/etc/rc` removes `/firstboot`
|
|
107
|
+
just before the restart, so `first_boot_pending()` is true until then; netOrk waits
|
|
108
|
+
for it before it sets up a new VM. OpenBSD has no such marker to ask yet.
|
|
109
|
+
|
|
110
|
+
**Services** are the enabled ones. FreeBSD reads their status as root, as
|
|
111
|
+
root-only pidfiles hide a daemon from anyone else, and without root when sudo
|
|
112
|
+
refuses; OpenBSD's `rcctl check` needs no root. Actions run as root.
|
|
113
|
+
|
|
114
|
+
**SNMP** is net-snmp from packages (NetOrk/netork#800), configured as netOrk does
|
|
115
|
+
on Linux (v2c, community `public`, every address), so the agent answers
|
|
116
|
+
UCD-SNMP-MIB for netOrk's health metrics. Memory, swap and load are right on
|
|
117
|
+
both systems. CPU: FreeBSD reports `ssCpuIdle` about a minute after the
|
|
118
|
+
agent starts; on OpenBSD net-snmp's CPU figures are wrong (0 % idle on an idle
|
|
119
|
+
machine, also in `hrProcessorLoad`).
|
|
120
|
+
|
|
121
|
+
## Connection arguments
|
|
122
|
+
|
|
123
|
+
`optional_args`: `port` (22), `key_file`, `sudo_password`, `allow_agent`,
|
|
124
|
+
`look_for_keys` (both off by default).
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
pip install -e ".[dev]"
|
|
130
|
+
pytest
|
|
131
|
+
```
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# napalm-bsd
|
|
2
|
+
|
|
3
|
+
NAPALM drivers for **FreeBSD** (`freebsd`) and **OpenBSD** (`openbsd`) hosts,
|
|
4
|
+
over SSH, built on [napalm-device-types](https://git.netork.io/NAPALM/napalm-device-types)'
|
|
5
|
+
`OSDriver`. Written for netOrk, which provisions and manages BSD VMs
|
|
6
|
+
(NetOrk/netork#792).
|
|
7
|
+
|
|
8
|
+
## Design
|
|
9
|
+
|
|
10
|
+
- One shared `BsdDriver` (`napalm_bsd/base.py`) holds the SSH layer and every
|
|
11
|
+
reader whose tools agree between the BSDs. `FreeBSDDriver` and
|
|
12
|
+
`OpenBSDDriver` name only the commands that differ (hostname, release,
|
|
13
|
+
kernel, hardware, `netstat -rnW` vs `-rn`).
|
|
14
|
+
- Every command runs on its own SSH **exec channel** (`run_on_transport` from
|
|
15
|
+
napalm-device-types): no PTY to parse a prompt from, stdout and stderr apart,
|
|
16
|
+
a real exit status. `run_command()` / `open_stream()` are public
|
|
17
|
+
(`CommandChannelMixin`).
|
|
18
|
+
- Root comes from `sudo -S` with the sudo password on stdin (never on a command
|
|
19
|
+
line), or `sudo -n` without one, as in napalm-linux. netOrk provisions `sudo`
|
|
20
|
+
on BSD VMs for that reason; `doas` cannot read a password from stdin.
|
|
21
|
+
- Parsing is in `napalm_bsd/parse.py`, pure functions tested on output recorded
|
|
22
|
+
from real systems (`tests/fixtures/`, each directory's `COMMANDS.txt` lists
|
|
23
|
+
what produced it).
|
|
24
|
+
|
|
25
|
+
## Supported getters
|
|
26
|
+
|
|
27
|
+
| Getter | FreeBSD | OpenBSD | Source |
|
|
28
|
+
|---|---|---|---|
|
|
29
|
+
| `get_facts` | ✓ | ✓ | `kern.hostname`/`hostname`, `freebsd-version`/`uname`, `kenv smbios.*`/`hw.*`, `kern.boottime` |
|
|
30
|
+
| `get_interfaces`, `get_interfaces_ip` | ✓ | ✓ | `ifconfig -a` |
|
|
31
|
+
| `get_route_to` | ✓ | ✓ | `netstat -rnW` / `netstat -rn` |
|
|
32
|
+
| `get_arp_table` | ✓ | ✓ | `arp -an` |
|
|
33
|
+
| `get_lldp_neighbors` | `{}` | `{}` | no LLDP daemon in either base system |
|
|
34
|
+
| `get_os_users`, `get_processes`, `get_cron_jobs` | ✓ | ✓ | `/etc/passwd`+`/etc/group`, `ps … lstart`, system crontab + `crontab -l` |
|
|
35
|
+
| `get_listening_sockets` | ✓ | ✓ | `sockstat -46lq` / `fstat -n` as root, `netstat -an` without |
|
|
36
|
+
| `get_packages`, `install_package`, `uninstall_package` | ✓ | ✓ | `pkg query` / `pkg install`, `pkg delete`; `pkg_info` / `pkg_add -I`, `pkg_delete` |
|
|
37
|
+
| `get_available_updates` | ✓ | ✓ | `pkg upgrade -n` + `pkg audit` (VuXML); `pkg_add -u -n -v` + `syspatch -c` |
|
|
38
|
+
| `get_services`, `manage_service` | ✓ | ✓ | `service -e` + `service … status` / `service … <action>`; `rcctl ls on` + `rcctl check` / `rcctl <action>` |
|
|
39
|
+
| `run_device_action("fix_snmp")`, `get_snmp_config` | ✓ | ✓ | net-snmp from packages: `/usr/local/etc/snmp/snmpd.conf` + `service snmpd`; `/etc/snmp/snmpd.conf` + `rcctl … netsnmpd` |
|
|
40
|
+
| `get_host_status` | ✓ | unknown | napalm-device-types' host status: on FreeBSD `freebsd-version -k` vs `-r` (4.1+) |
|
|
41
|
+
| `first_boot_pending` | ✓ | always `False` | whether `/firstboot` still exists |
|
|
42
|
+
|
|
43
|
+
`get_listening_sockets` has the shape of napalm-device-types'
|
|
44
|
+
`ListeningSocketsMixin` (whose `ss`/cgroup reading is Linux's) and its rule:
|
|
45
|
+
read as root first, without root when that brings nothing back
|
|
46
|
+
(`attributed: False`). FreeBSD's `sockstat` sees every socket either way;
|
|
47
|
+
OpenBSD's `fstat` shows a user only their own processes, so without root the
|
|
48
|
+
sockets come from `netstat -an`, unnamed.
|
|
49
|
+
|
|
50
|
+
There is deliberately no `get_kernel_facts`: `KernelFactsMixin` reports a
|
|
51
|
+
Linux kernel's modules and `CONFIG_*` options, which a BSD kernel does not
|
|
52
|
+
have, and `hasattr(driver, "get_kernel_facts")` has to stay truthful.
|
|
53
|
+
|
|
54
|
+
**Updates.** `security` on FreeBSD comes from VuXML (`pkg audit`): True for a
|
|
55
|
+
package it lists as vulnerable, False for one it does not, None when the audit
|
|
56
|
+
could not run. OpenBSD's tools do not say, so it is None there. Base-system
|
|
57
|
+
patches are one entry, `base-system` (NetOrk/netork#799): OpenBSD's
|
|
58
|
+
`syspatch` applies its patches together and in order; a classic FreeBSD base
|
|
59
|
+
reports what `freebsd-update` has fetched (`updatesready`). On FreeBSD with
|
|
60
|
+
pkgbase the base system is packages from the `FreeBSD-base` repository and
|
|
61
|
+
needs no extra entry.
|
|
62
|
+
|
|
63
|
+
A reader that cannot read **raises** rather than return an empty list: netOrk
|
|
64
|
+
takes `[]` as "no updates" and would close every patch clock on the host. That
|
|
65
|
+
covers a refused sudo, a failing `pkg`, `syspatch` or `freebsd-update`, and a pkg
|
|
66
|
+
database pkg cannot read (only pkg's "not installed" means no packages).
|
|
67
|
+
|
|
68
|
+
**Reboot.** `get_host_status` reports a FreeBSD host whose installed kernel
|
|
69
|
+
(`freebsd-version -k`) differs from the running one (`-r`) as needing a reboot.
|
|
70
|
+
OpenBSD has no such reading yet, so it stays unknown there.
|
|
71
|
+
|
|
72
|
+
**First boot.** A FreeBSD cloud image upgrades its base system on its first boot,
|
|
73
|
+
starts sshd only after that and restarts right away. `/etc/rc` removes `/firstboot`
|
|
74
|
+
just before the restart, so `first_boot_pending()` is true until then; netOrk waits
|
|
75
|
+
for it before it sets up a new VM. OpenBSD has no such marker to ask yet.
|
|
76
|
+
|
|
77
|
+
**Services** are the enabled ones. FreeBSD reads their status as root, as
|
|
78
|
+
root-only pidfiles hide a daemon from anyone else, and without root when sudo
|
|
79
|
+
refuses; OpenBSD's `rcctl check` needs no root. Actions run as root.
|
|
80
|
+
|
|
81
|
+
**SNMP** is net-snmp from packages (NetOrk/netork#800), configured as netOrk does
|
|
82
|
+
on Linux (v2c, community `public`, every address), so the agent answers
|
|
83
|
+
UCD-SNMP-MIB for netOrk's health metrics. Memory, swap and load are right on
|
|
84
|
+
both systems. CPU: FreeBSD reports `ssCpuIdle` about a minute after the
|
|
85
|
+
agent starts; on OpenBSD net-snmp's CPU figures are wrong (0 % idle on an idle
|
|
86
|
+
machine, also in `hrProcessorLoad`).
|
|
87
|
+
|
|
88
|
+
## Connection arguments
|
|
89
|
+
|
|
90
|
+
`optional_args`: `port` (22), `key_file`, `sudo_password`, `allow_agent`,
|
|
91
|
+
`look_for_keys` (both off by default).
|
|
92
|
+
|
|
93
|
+
## Development
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install -e ".[dev]"
|
|
97
|
+
pytest
|
|
98
|
+
```
|