Over SSH the name went into `name "<name>"` in config mode, one line of a
block sent line by line before `write memory`: a line break ended the
line and the switch ran the rest as commands, a double quote ended the
name. netOrk replays VLAN names other devices reported here
(NetOrk/netork#2455).
set_vlan() now raises ValueError for a name containing \r, \n or ",
before anything is sent, over every transport.
netOrk aligns every device's NTP servers and time zone with its site's
(NetOrk/netork#2360, #2366). A ProCurve keeps them as configuration
lines: sntp server priority <1-3> (or ntp server lines when 16.x runs
timesync ntp), time timezone <minutes> and time daylight-time-rule.
get_time_sync() reads those lines from show running-config, over REST
through the /cli endpoint, and the zone as None: the switch keeps
minutes and a rule, no name. configure_time_sync() writes the servers
in the protocol the switch runs (SNTP unless it runs NTP, switching
TimeP to sntp unicast), keeping those already in place from the first
on; the zone as minutes and the switch's own US/EU rule, or user-defined
dates for other Sunday rules, from the zone's POSIX rule. What the switch
cannot take is refused before anything is sent: more than 3 SNTP or 8
NTP servers, host names, half an hour of summer time, a change on a
weekday. A change is saved with write memory; values already in place
are not sent again, so the alignment on every poll does not churn.
Over REST the writes need the CLI, so the temporary SSH session
configure_snmp_agent opened is now the _config_cli() context manager
both use. get_ntp_servers() reads through get_time_sync() on every
transport; it and get_ntp_stats() move to time_sync.py with the rest of
the clock, so procurve.py shrinks (1383 -> 1339 lines). The unused
parse_ntp_servers() and ProcurveApiClient.get_ntp_servers() are gone.
A switch whose REST API has no configuration is read over a temporary
SSH session. That path read the running config only, whatever retrieve
asked for, and returned an empty startup config. It now reads through
the same code as the SSH transport: running and/or startup as asked,
"show config" where "show startup-config" is unknown, and a part that
could not be read raises.
Closes#25
ProcurveApiClient.get() answered {} for a timeout, a refused session or
any HTTP error, so every REST getter reported a failed read as a switch
with no hostname, ports, VLANs or neighbours. get() now raises
ConnectionException (no answer, 401/403) or RuntimeError (other
non-2xx, a body that is not JSON); the getters that expect a resource
to be missing on some firmware pass missing_ok for its 404.
get_config no longer returns an empty configuration when both the REST
read and the SSH fallback failed, and cli() over REST raises instead of
returning "Error: HTTP <status>" as the command's output.
Closes#22
The REST login now checks the certificate before it posts the password
(#17) and then tells a web page from a refused login (#13); the two
login-answer checks moved into _require_login so connect() stays within
the function-length limit. #13's REST tests stand in for the switch's
certificate, since connect() fetches it before the login.
The probe falls back to HTTP when HTTPS does not answer. For a switch
known by its certificate that is a downgrade anyone who blocks port 443
can force: the login would go out in clear text, unchecked. With a
pinned fingerprint the REST API is skipped then and the CLI transports
are tried; without one, plain HTTP is used as before.
Refs #17
The REST login never verified the switch in practice: with ssl_verify
off nothing was checked, and with it on a self-signed certificate (the
one every ProCurve ships) failed the CA check and the login was retried
with verification off. Either way the password went to whatever answered
on port 443.
The certificate is now checked by its SHA-256 fingerprint, trust on
first use (napalm-device-types tls_certificates): the caller passes the
fingerprint to expect in optional_args["tls_fingerprints"] and receives
every one seen through optional_args["tls_certificate_observer"]. A
different certificate ends open() with TlsCertificateMismatch before the
password is sent, without trying SSH or Telnet, which would reach the
same host with the same password. The session is pinned to the checked
certificate for every later connection. ssl_verify no longer has an
effect, and the unverified retry is gone.
Closes#17
Over the REST API, cli() returned the /cli endpoint's
result_base64_encoded field as it came: base64 instead of the command's
output. It now decodes it and drops the NUL byte the switch ends it with,
in the same parser the SNMP read over REST uses.
New finding, confirmed by the show snmp-server answer recorded from a
ProCurve switch; no issue filed.
The #10 tests read a hand-written show snmp-server. They now read the
output recorded from a ProCurve switch: as the CLI prints it, and as the
REST /cli endpoint answers it, base64 with a trailing NUL byte. The
trap receiver's address is replaced. The read-only preference and the
no-community case put a line into, or take one out of, the recording.
get_snmp_config sent "show snmp-server" through the CLI session, which
does not exist on the REST transport, and returned None, so every switch
managed over REST read as "SNMP not configured". Over REST the command
now runs through the API's /cli endpoint and the output goes through the
parser the SSH path uses. A failed REST read raises.
Closes#10
A switch whose Telnet sessions were all taken, and a REST API answering
the login with the web UI's HTML page, were both reported as an
authentication failure, which sent the operator after the password. The
Telnet login now keeps the switch's greeting in an in-memory session log
and reports a full switch as a connection error; an HTML answer to the
REST login says so. An SSH attempt records netmiko's underlying error
instead of "timed out" when it was not a timeout.
Session log objects need netmiko 4.3.0, which becomes the floor.
Closes#13
configure_snmp_agent over the REST API opened its temporary SSH session
on optional_args["port"], which names the REST API's port when REST is
the transport. It now uses port 22, as the running-config fallback
already did.
The second finding of the issue, the unverified REST certificate, needs
a decision and stays open.
Refs #17
- The six except Exception: pass (REST logout, the extra-ports lookup, the
per-port detail in get_interfaces, closing CLI and REST sessions) now log
at debug level (B110), so a swallowed failure leaves a trace.
- nosec for comparing a reported address with 0.0.0.0 (B104) and for the
empty password field of get_users (B105, now a named constant); both are
false positives.
- A long error message is split into adjacent f-strings; the unused ARP
entry type is named _entry_type.
- tests: the failed-open test expects ConnectionException instead of any
Exception; raise ... from exc.
Mechanical: ruff format, and ruff check --fix with the rule set every NAPALM
driver uses (E, F, I, UP, B at line length 100, Python 3.10). What ruff
cannot fix comes in the next commit.
The driver accepted any SSH host key. It now verifies through
napalm-device-types' HostKeyCheck (>= 4.19.0): with a known key in
optional_args["ssh_host_keys"] any other key is refused before login, and
every key seen is reported to optional_args["ssh_host_key_observer"].
Without either argument it connects as before (first use).
fix_snmp hard-coded community "public". The driver implements
napalm-device-types 4.13's configure_snmp_agent as a whole, because
over REST a temporary SSH session has to run the config-mode CLI:
community (read-only), contact and location from the caller, saved
and verified in show snmp-server. The agent is built in and the switch
filters nothing for its management plane; the steps say so instead of
pretending. A value that would break the CLI is refused.
The unused _detect_management_vlan goes with it.
BREAKING CHANGE: run_device_action is removed.
Part of #12 and #6 (the dead helper).
pyproject.toml did not list napalm-device-types although the code
imports it (CI installed it by hand); it now requires 4.13, whose fix
templates the next commit uses. Seven .pyc and six egg-info files were
tracked; they go, and a .gitignore keeps them out.
Closes#11
The driver no longer collects over SNMP. SNMP_HEALTH_PROFILE states
where the switch publishes its values; the application polls and
computes (napalm-device-types docs/STRUCTURE.md).
This also fixes the memory figure: NETSWITCH-MIB hpLocalMemEntry column
6 is free memory, not used. On swt-l0-3-40 total 58720256 = free
39105640 + allocated 19614616, so the switch showed 66.6 % used instead
of 33.4 %. The profile names column 6 as free.
Interface counters now come from the 64-bit ifXTable where the switch
has it, as the application reads them for every device.
Closes#9
Since f35b59e a CLI poll reports trunk members as `3` with
trunk_group `Trk3`, but `show interfaces brief` has no line for Trk3
itself, so the trunk was missing from the interface list. The REST path
built that row on its own.
Both paths now use napalm_device_types.add_lag_interfaces, and the REST
path's copy is gone. One visible change there: `lag_members` is now in
port order (7, 10) instead of API order; the description already was.
The CLI path does not know the mode yet, so its trunks carry no
lag_mode. That needs `show trunks`, whose output is not at hand.
Needs napalm-device-types f3fa75b.
Closes#5
A 2800-series switch on J.15.09 polled over CLI came back with no
interfaces and an empty OS version, while VLANs and ARP parsed fine.
`show interfaces brief` on that firmware has an Intrusion Alert column
between the `|` and Enabled, and puts Mode before MDI rather than after:
Port Type | Alert Enabled Status Mode Mode ...
3-Trk3 100/1000T | No Yes Down 1000FDx MDI ...
The regex read Alert as Enabled, then failed on Yes where it wanted
Up|Down, so no line matched. It now skips the Alert column where there is
one and takes the speed from either position. Trunk members are listed as
`<port>-Trk<n>`; the port is `<port>` and the suffix becomes its
trunk_group, so the per-port `show interfaces 3` is a command the switch
knows.
The empty OS version was the alternatives list in _send_command. It moved
to the next command on "% Invalid" or "Error", but ProCurve rejects an
unknown command with "Invalid input: system-information" -- so that line
was parsed as system information. "Invalid input" now counts as failure.
Getting there took longer than it should have, because the first symptom
was "Authentication failed: Login failed". That was Telnet's error, the
last transport tried; the REST probe and both SSH attempts had failed
before it and said nothing above debug level. In fact the switch had run
out of CLI sessions and closed SSH straight after the password. open()
now records why each transport failed, and both the auth error and the
final "Cannot connect" carry that list.
Fixtures are that switch's output, with hostname, serial and MAC
replaced.
Closes#2Closes#3Closes#4
set_interface() always POSTed to vlans-ports, treating every membership as
new. Moving a port that already carries the VLAN from untagged to tagged is
not a create, though, and the switch says so:
POST vlans-ports {"vlan_id":10,"port_id":"10","port_mode":"POM_TAGGED_STATIC"}
-> 400 {"message":"Association exists"}
Only 409 was handled as "already there"; v7 firmware answers 400. The
membership is its own resource named {vlan_id}-{port_id} and takes a PUT:
PUT vlans-ports/10-10 -> 200
So the exact case anyone hits first failed outright — a port holding VLAN 10
untagged alongside 30/40/50 tagged, with VLAN 10 to become tagged too.
The response body is now carried into both error messages. The ports PUT just
above already did this; here it was dropped, so "Association exists" — which
names the cause outright — never reached the caller. The message read
"vlans-ports POST HTTP 400" and nothing more.
Verified against a 2530-24G-PoEP on REST v7: set_interface("10", trunk
vlan 30), where that membership already exists, now completes and leaves the
port exactly as it was.