Skip to content

Fix CSS326 support - #4

Closed
vvbelousov wants to merge 1 commit into
lanrat:mainfrom
vvbelousov:css326_fix
Closed

Fix CSS326 support#4
vvbelousov wants to merge 1 commit into
lanrat:mainfrom
vvbelousov:css326_fix

Conversation

@vvbelousov

Copy link
Copy Markdown

Fix CSS326 support: correct SwOS detection + clean VLAN export

  • fix platform detection (CSS326 runs SwOS, not SwOS Lite)
  • stop treating all CSS models as SwOS Lite
  • fix export logic: vlan_mode=Optional is baseline, not a change

Result: correct detection and no noisy port_vlans in export.
Tested on:

  • CSS326-24G-2S+ (SwOS 2.18)
  • CRS310-8G+2S+ (SwOS 2.18)

@Dennis-Q

Copy link
Copy Markdown

This is great work, I tested it on my CSS318 which also runs SWoS not Lite, and seems to work perfectly:

Connecting to switch at http://XXX.XXX.XXX.XXX...
Username: admin

Retrieving system information...

================================================================================
  SYSTEM INFORMATION
================================================================================

  Device Model:  CSS318-16G-2S+
  Device Name:   N/A
  Version:       2.18
  Serial Number: XXXXXXXXXX
  MAC Address:   xx:xx:xx:xx:xx:xx
  Uptime:        129532556 seconds

For others that don't like to wait for the request to be merged:

  1. Put this line into your requirements.txt
    git+https://github.com/lanrat/python-mikrotik-swos.git@refs/pull/4/head
  2. Then run this command:
    pip install --upgrade --force-reinstall -r requirements.txt

Ignore any Did not find branch or tag 'refs/pull/4/head', assuming revision or ref. errors, they are expected. Then you can try something like: swos-config 192.168.88.1 admin "". In my case, it gave me back switch info, but also port and VLAN information.

Thank you @vvbelousov !

lanrat pushed a commit that referenced this pull request Sep 6, 2026
CSS326-24G-2S+ runs full SwOS, but was detected as SwOS Lite.

The field-name test used `k.startswith('i') and len(k) == 3`, which
matches ico/img/imr/ip0/ivl in SwOS sys.b. That made has_hex_fields true
on every SwOS device, so detection always fell through to the model
prefix, which mapped CSS* to SwOS Lite. CRS devices only worked because
the same fallback mapped CRS* to SwOS - strip the model string and a
SwOS device came back as unknown.

Match i + digits exactly so field naming decides, as the code intended.
Model prefix is now a last resort, and a CSS model is resolved by which
field style it uses rather than assumed to be Lite.

Verified against the six devices in webui_reference/ (SwOS sys.b carries
no i+digits field; SwOS Lite carries no id/ver/brd) and on a CRS309-1G-8S+
(SwOS 2.18) and CSS610-8P-2S+ (SwOS Lite 2.21).

Also stop exporting untouched ports as port_vlans. An untouched port
reports vlan_mode 'Optional' on both platforms, but only 'Disabled' was
treated as baseline, so every port landed in the export. On the two test
switches this drops the noise from 9/9 to 4 and 10/10 to 1, with every
dropped port confirmed to be at ('Optional','Any',1,False).

Taken from PR #4, logic only - the docstring removal and quote
reformatting in that PR were left out.
@lanrat

lanrat commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Thanks — good catch, and the diagnosis holds up. I've merged the logic.

The root cause is nastier than it looks: k.startswith('i') and len(k) == 3 matches
ico, img, imr, ip0 and ivl in SwOS sys.b, so has_hex_fields was true on
every SwOS device. Detection always fell through to the model prefix, which mapped CSS*
to Lite. CRS boxes only worked because that same fallback mapped CRS* to SwOS — strip the
model string out and a SwOS device came back unknown. Matching i + digits exactly makes
the field-name test actually decide, which is what it always claimed to do.

Your export fix is right too, and broader than the PR describes. Optional is the
untouched state on SwOS Lite as well, so this wasn't CSS326-specific — on my two test
switches it cuts the exported port_vlans from 9/9 to 4 and from 10/10 to 1, and I
confirmed every dropped port is at ('Optional','Any',1,False).

I did leave out the reformatting. The docstring removal in platform.py takes the
Args/Returns/Raises blocks off PlatformAdapter's public methods, and the quote change
puts that one file out of step with the rest of the repo — neither relates to CSS326, and
together they were most of the diff. Kept the except:except Exception: change and
the unused Tuple/get_field imports, those are real improvements.

One ask: could you dump the CSS326-24G-2S+ web UI into webui_reference/? Same files as
the other devices there (index.html, plus engine.js if it's separate). I verified this
fix offline against all six devices already in that directory, but CSS326 is the one case I
can't check that way and don't have hardware for — so I'm taking your word on it. A dump
would make it verifiable like everything else, and would help the next person who hits a
CSS model running full SwOS.

@lanrat lanrat closed this Sep 6, 2026
@lanrat

lanrat commented Sep 6, 2026

Copy link
Copy Markdown
Owner

@Dennis-Q missed this earlier, thanks for testing — CSS318-16G-2S+ is a useful second data
point, that's two CSS models now confirmed running full SwOS rather than Lite. I've added
both to the README.

This is all released now, so the workaround isn't needed any more — and worth flagging that
refs/pull/4/head is frozen at the PR head, so it never picked up the merged version and
still carries the reformatting I left out. Just use the release:

pip install --upgrade mikrotik-swos    # v1.4.0

v1.4.0 also adds set_password() for changing the admin password, from #2.

And if you're willing — could you dump the CSS318 web UI into webui_reference/?
index.html, plus engine.js if it's a separate file. I asked @vvbelousov for a CSS326
dump above, but CSS318 verifies the same thing: a CSS-model device serving SwOS-style
fields. Every other device in that directory lets me check platform detection offline, and
this is the one class I have no hardware for. Either dump closes the gap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants