Skip to content

swadm quality of life improvements#228

Open
Nieuwejaar wants to merge 5 commits intomainfrom
qol
Open

swadm quality of life improvements#228
Nieuwejaar wants to merge 5 commits intomainfrom
qol

Conversation

@Nieuwejaar
Copy link
Collaborator

fixes #79 Add ls -> list alias for arp subcommand
fixes #121 swadm link history could report better timestamps for link events
fixes #221 swadm link ls filter matching

root@oxz_switch0:~# swadm arp ls | head
host                       mac                age
fe80::aa40:25ff:fe04:212   a8:40:25:04:02:12  21m10s
fe80::aa40:25ff:fe04:257   a8:40:25:04:02:57  21m10s
fe80::aa40:25ff:fe04:1113  a8:40:25:04:11:13  13m17s
fe80::aa40:25ff:fe04:1291  a8:40:25:04:12:91  7m9s
fe80::aa40:25ff:fe05:202   a8:40:25:05:02:02  21m22s
fe80::aa40:25ff:fe05:203   a8:40:25:05:02:03  21m22s
fe80::aa40:25ff:fe05:204   a8:40:25:05:02:04  21m21s
fe80::aa40:25ff:fe05:205   a8:40:25:05:02:05  21m20s
fe80::aa40:25ff:fe05:206   a8:40:25:05:02:06  21m20s
root@oxz_switch0:~# swadm link ls rear3 int
Port/Link  Media   Speed  FEC   Autoneg  Enabled  State    MAC
int0/0     CPU     10G    None  true     true     Up       a8:40:25:05:02:02
rear3/0    Copper  100G   RS    true     true     Unknown  a8:40:25:05:02:06
rear30/0   Copper  100G   RS    true     true     Unknown  a8:40:25:05:02:21
rear31/0   Copper  100G   RS    true     true     Unknown  a8:40:25:05:02:22
root@oxz_switch0:~# swadm link history rear14/0
Time         Class      Subclass                     Channel  Details
21m27s725ms  PortFSM    LinkUp                       -
21m27s836ms  PortFSM    LinkDown                     -
21m28s94ms   PortFSM    WaitAutoNegLinkTrainingDone  -
21m28s267ms  MediaFSM   LinkDown                     -
21m28s343ms  PortFSM    WaitAutoNegDone              -
21m28s361ms  LinkAdmin  Enable                       -
21m28s361ms  MediaFSM   WaitLinkSt                   -
21m29s250ms  MediaFSM   MediaDetected                -
21m29s582ms  QsfpFSM    Detected                     -
21m35s150ms  QsfpFSM    Inserted                     -
21m40s533ms  LinkAdmin  Create                       -        speed: 100G  fec: RS

Ok(())
}

fn fmt_time(mut ms: i64) -> String {
Copy link
Contributor

@rcgoodfellow rcgoodfellow Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol, a recurring theme this. Maybe we should have this in some common crate. Definitely do not want a dependency to mg-common from dendrite for this. It's unfortunate that the humantime crate does not seem to support not printing durations down to the nanosecond.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend we use humantime or something similar wherever we need this sort of thing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done:

root@oxz_switch0:~# ./swadm link history rear14/0
Time           Class      Subclass                     Channel  Details
51m 5s 422ms   PortFSM    LinkUp                       -
51m 5s 533ms   PortFSM    LinkDown                     -
51m 5s 791ms   PortFSM    WaitAutoNegLinkTrainingDone  -
51m 5s 964ms   MediaFSM   LinkDown                     -
51m 6s 40ms    PortFSM    WaitAutoNegDone              -
51m 6s 58ms    LinkAdmin  Enable                       -
51m 6s 58ms    MediaFSM   WaitLinkSt                   -
51m 6s 947ms   MediaFSM   MediaDetected                -
51m 7s 279ms   QsfpFSM    Detected                     -
51m 12s 847ms  QsfpFSM    Inserted                     -
51m 18s 230ms  LinkAdmin  Create                       -        speed: 100G  fec: RS

.await
.context("failed to list all links")?
.into_inner();
if !filter.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels like we need to update this block to operate on known matching links? swadm link ls rear3 blah would still succeed, right? We should consider tracking which filters actually matched at least one link and warn/err on unused ones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could argue that it's an error unless each of the filters matches something, or a success if any of the filters match anything. My preference is really to have no errors, and a failure to match just gives you an empty result.

@rmustacc filed the issue, and I think he might be asking for the same thing you are, so I'll let him make the final call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was going off the text in the issue too.

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.

swadm link ls filter matching swadm link history could report better timestamps for link events Add ls -> list alias for arp subcommand

4 participants