Skip to content

Conversation

vikumarks
Copy link
Contributor

What I did

Added json output supoort for

intfutil -c autoneg -j
intfutil -c fec -j
intfutil -c status -j
intfutil -c description -j
intfutil -c tpid -j
intfutil -c link_training -j

How I did it

How to verify it

admin@str-7060x6-64pe-stress-01:~$ intfutil -c status -i Ethernet0 -j
{
    "Ethernet0": {
        "Admin": "up",
        "Alias": "Ethernet1/1",
        "Asym PFC": "off",
        "FEC": "rs",
        "Lanes": "17",
        "MTU": "9100",
        "Oper": "up",
        "Speed": "100G",
        "Type": "OSFP 8X Pluggable Transceiver",
        "Vlan": "trunk"
    }
}
admin@str-7060x6-64pe-stress-01:~$ intfutil -c description -i Ethernet0 -j
{
    "Ethernet0": {
        "Admin": "up",
        "Alias": "Ethernet1/1",
        "Description": "Servers0:eth0",
        "Oper": "up"
    }
}
admin@str-7060x6-64pe-stress-01:~$ intfutil -c autoneg -i Ethernet0 -j
{
    "Ethernet0": {
        "Admin": "up",
        "Adv Speeds": "N/A",
        "Adv Types": "N/A",
        "Auto-Neg Mode": "N/A",
        "Oper": "up",
        "Rmt Adv Speeds": "N/A",
        "Speed": "100G",
        "Type": "N/A"
    }
}
admin@str-7060x6-64pe-stress-01:~$ intfutil -c tpid -i Ethernet0 -j
{
    "Ethernet0": {
        "Admin": "up",
        "Alias": "Ethernet1/1",
        "Oper": "up",
        "TPID": "0x8100"
    }
}
admin@str-7060x6-64pe-stress-01:~$ intfutil -c link_training -i Ethernet0 -j
{
    "Ethernet0": {
        "Admin": "up",
        "LT Admin": "N/A",
        "LT Oper": "N/A",
        "Oper": "up"
    }
}
admin@str-7060x6-64pe-stress-01:~$ intfutil -c fec -i Ethernet0 -j
{
    "Ethernet0": {
        "FEC Admin": "rs",
        "FEC Oper": "N/A"
    }
}

Previous command output (if the output of a command-line utility has changed)

New command output (if the output of a command-line utility has changed)

@zhangyanzhao
Copy link
Collaborator

@qiluo-msft can you please help to review? Thanks.

@qiluo-msft qiluo-msft requested a review from Copilot June 12, 2025 21:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds JSON output support to the intfutil script for multiple commands (status, description, autoneg, tpid, link_training, fec).

  • Introduces --json (-j) CLI flag and imports table_as_json
  • Updates each Intf* class constructor to accept use_json and conditionally print JSON
  • Propagates the new flag through main() when instantiating and displaying results
Comments suppressed due to low confidence (3)

doc/Command-Reference.md:1

  • Update the Command Line Reference Guide to document the new -j/--json flag for intfutil.
<Add section for `intfutil -j`>

scripts/intfutil:900

  • Add or update unit tests in the tests/ directory to cover the new JSON output path (--json flag) and validate the structure returned by table_as_json.
parser.add_argument('-j', '--json', action='store_true', help='Display in JSON format')

scripts/intfutil:455

  • [nitpick] The repeated if self.use_json: print(table_as_json(...)) else: print(tabulate(...)) pattern appears in multiple methods; consider extracting a helper function to reduce duplication and improve maintainability.
def display_intf_status(self):

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@qiluo-msft qiluo-msft merged commit 1418f21 into sonic-net:master Aug 6, 2025
7 checks passed
@vikumarks vikumarks deleted the pr-json-support-intfutil branch August 6, 2025 19:45
@mssonicbld
Copy link
Collaborator

Cherry-pick PR to msft-202412: Azure/sonic-utilities.msft#220

@mssonicbld
Copy link
Collaborator

Cherry-pick PR to 202505: #4023

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

Successfully merging this pull request may close these issues.

7 participants