From fffeffc2ebf173cd5d131cb4867f752db13961fc Mon Sep 17 00:00:00 2001 From: Tejaswi Goel Date: Fri, 20 Sep 2019 03:31:46 -0700 Subject: [PATCH 1/4] CLI skeleton for Port channel Signed-off-by: Tejaswi Goel --- src/CLI/actioner/port_channel_dummy_data.json | 48 ++ src/CLI/actioner/sonic-cli-if.py | 93 +++- src/CLI/clitree/cli-xml/interface.xml | 433 ++++++++++++++++-- .../renderer/templates/show_portchannel.j2 | 9 + .../renderer/templates/show_portchannel_id.j2 | 8 + 5 files changed, 553 insertions(+), 38 deletions(-) create mode 100644 src/CLI/actioner/port_channel_dummy_data.json create mode 100644 src/CLI/renderer/templates/show_portchannel.j2 create mode 100644 src/CLI/renderer/templates/show_portchannel_id.j2 diff --git a/src/CLI/actioner/port_channel_dummy_data.json b/src/CLI/actioner/port_channel_dummy_data.json new file mode 100644 index 0000000000..20149bb2d5 --- /dev/null +++ b/src/CLI/actioner/port_channel_dummy_data.json @@ -0,0 +1,48 @@ +{ + "openconfig-interfaces:interface": [ + { + "members": [ + "Ethernet56", + "Ethernet60" + ], + "min-links": 2, + "mtu": 9100, + "admin-status": "up", + "name": "Portchannel0" + }, + { + "members": [ + "Ethernet64", + "Ethernet68" + ], + "min-links": 1, + "mtu": 9100, + "admin-status": "up", + "name": "Portchannel1" + }, + { + "members": [ + "Ethernet24", + "Ethernet12" + ], + "min-links": 1, + "mtu": 9100, + "admin-status": "up", + "name": "Portchannel2" + }, + { + "members": [], + "min-links": 1, + "mtu": 9100, + "admin-status": "up", + "name": "Portchannel3" + }, + { + "members": [], + "min-links": 1, + "mtu": 9100, + "admin-status": "up", + "name": "Portchannel4" + } + ] +} diff --git a/src/CLI/actioner/sonic-cli-if.py b/src/CLI/actioner/sonic-cli-if.py index 9ed5f27006..2b20d9cfcd 100755 --- a/src/CLI/actioner/sonic-cli-if.py +++ b/src/CLI/actioner/sonic-cli-if.py @@ -21,6 +21,7 @@ import time import json import ast +import yaml import openconfig_interfaces_client from rpipe_utils import pipestr from openconfig_interfaces_client.rest import ApiException @@ -44,7 +45,6 @@ def call_method(name, args): def generate_body(func, args): body = None - # Get the rules of all ACL table entries. if func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_description': keypath = [ args[0] ] body = { "openconfig-interfaces:description": args[1] } @@ -94,6 +94,97 @@ def run(func, args): c.verify_ssl = False aa = openconfig_interfaces_client.OpenconfigInterfacesApi(api_client=openconfig_interfaces_client.ApiClient(configuration=c)) +# Code for Portchannel cli skeleton, reading and writing data to port_channel_dummy_data json file + #create a port-channel + if "Portchannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface': + with open('port_channel_dummy_data.json', 'r') as f: + data= yaml.safe_load(f) + for dict in data['openconfig-interfaces:interface']: + if dict["name"] == args[0]: + return + body = { + "name": args[0], + "min-links": 1, + "mtu": 9100, + "admin-status": "up", + "members": [] + } + data['openconfig-interfaces:interface'].append(body) + with open('port_channel_dummy_data.json', 'w') as f: + json.dump(data, f, sort_keys=True, indent=4) + print ("Success") + return + + #show given port-channel details + if "Portchannel" in args[0] and func.__name__ == 'get_openconfig_if_aggregate_interfaces_interface_aggregation_state': + with open('port_channel_dummy_data.json', 'r') as f: + data= yaml.safe_load(f) + for dict in data['openconfig-interfaces:interface']: + if dict["name"] == args[0]: + show_cli_output("show_portchannel_id.j2", dict) + return + print("%Error: Entry not found") + return + + #show port-channels summary + if "Portchannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces': + with open('port_channel_dummy_data.json', 'r') as f: + data= yaml.safe_load(f) + show_cli_output("show_portchannel.j2", data) + return + + #add members to port-channel + if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id': + port_c = 'Portchannel' + args[1] + with open('port_channel_dummy_data.json', 'r') as readf: + data= yaml.safe_load(readf) + for dict in data['openconfig-interfaces:interface']: + if dict["name"] == port_c: + dict["members"].append(args[0]) + with open('port_channel_dummy_data.json', 'w') as writef: + json.dump(data, writef, sort_keys=True, indent=4) + print ("Success") + return + print ("Failed-entry not found") + return + + #remove members from port-channel + if func.__name__ == 'delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id': + return("Success") + + #config mtu for port-channel + if "po" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu': + return("Success") + + #delete port-channel + if "Portchannel" in args[0] and func.__name__ == 'delete_openconfig_interfaces_interfaces_interface': + with open('port_channel_dummy_data.json', 'r') as f: + data= yaml.safe_load(f) + for dict in data['openconfig-interfaces:interface']: + if dict["name"] == args[0]: + data['openconfig-interfaces:interface'].remove(dict) + with open('port_channel_dummy_data.json', 'w') as writef: + json.dump(data, writef, sort_keys=True, indent=4) + print ("Success") + return + print ("Failed-entry not found") + return + + #config min-links in port-channel + if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links': + with open('port_channel_dummy_data.json', 'r') as f: + data= yaml.safe_load(f) + port_c = 'Portchannel'+args[0][2:] + for dict in data['openconfig-interfaces:interface']: + if dict["name"] == port_c: + dict["min-links"]=args[1] + with open('port_channel_dummy_data.json', 'w') as f: + json.dump(data, f, sort_keys=True, indent=4) + print ("Success") + return + print ("Failed-entry not found") + return + # create a body block keypath, body = generate_body(func, args) diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index 3341170d76..5c0a3aa344 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -53,7 +53,21 @@ limitations under the License. ptype="UINT" optional="true" > - + + + + + - - - - - + name="interface" + help="Select an interface" + /> + + + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface Vlan${vlan-id} + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface Portchannel${lag-id} + + + + + + + + + + + + + + if test "${if-subcommands}" = "vlan"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface Vlan${vlan-id} + fi + if test "${if-subcommands}" = "port-channel"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface Portchannel${lag-id} + fi + + - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} True - - - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_description ${iface} ${desc} + @@ -147,8 +233,8 @@ limitations under the License. - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} ${mtu} @@ -158,6 +244,279 @@ limitations under the License. help="Remove MTU"> python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${iface} 9100 + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} ${lag-id} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} True + + + + + + + + + + + + + + + + + + + + + + + if test "${switchport-subcommands}" = "access"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_config ${iface} ACCESS ${vlan-id} + else + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_config ${iface} TRUNK ${vlan-id} + fi + + + + + + + + + + + + + + + + + + + + + + if test "${switchport-subcommands}" = "access"; then + python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_config_access_vlan ${iface} ACCESS + else + python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_vlan_interfaces_interface_ethernet_switched_vlan_config_trunk_vlans ${iface} TRUNK ${vlan-id} + fi + + + + + + + + + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} ${min-links} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} 1 + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} ${mtu} + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_mtu ${po_id} 9100 + + + + + + + + + + + + + + + + + diff --git a/src/CLI/renderer/templates/show_portchannel.j2 b/src/CLI/renderer/templates/show_portchannel.j2 new file mode 100644 index 0000000000..be5f282ad5 --- /dev/null +++ b/src/CLI/renderer/templates/show_portchannel.j2 @@ -0,0 +1,9 @@ +{% set just_var = 2 %} + +Flags: A - Active, Dw - Oper status down +{{'----------------------------------------------------------------------------------------------------------------------------'}} +{{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}} +{{'----------------------------------------------------------------------------------------------------------------------------'}} +{% for dict in json_output['openconfig-interfaces:interface'] %} +{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)(Dw)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin-status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}} +{% endfor %} diff --git a/src/CLI/renderer/templates/show_portchannel_id.j2 b/src/CLI/renderer/templates/show_portchannel_id.j2 new file mode 100644 index 0000000000..b45173aaa9 --- /dev/null +++ b/src/CLI/renderer/templates/show_portchannel_id.j2 @@ -0,0 +1,8 @@ +{% set just_var = 2 %} + +Flags: A - Active, Dw - Oper status down +{{'----------------------------------------------------------------------------------------------------------------------------'}} +{{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}} +{{'----------------------------------------------------------------------------------------------------------------------------'}} +{% set dict = json_output %} +{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin-status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}} From 006737e7ed71ae11dd0416d7e7311b4c6993b2e6 Mon Sep 17 00:00:00 2001 From: Tejaswi Goel Date: Wed, 25 Sep 2019 12:04:36 -0700 Subject: [PATCH 2/4] Changes to remove dummy json file Signed-off-by: Tejaswi Goel --- src/CLI/actioner/port_channel_dummy_data.json | 48 -------- src/CLI/actioner/sonic-cli-if.py | 106 +++++++----------- src/CLI/clitree/cli-xml/interface.xml | 10 +- .../renderer/templates/show_portchannel.j2 | 2 +- .../renderer/templates/show_portchannel_id.j2 | 2 +- 5 files changed, 50 insertions(+), 118 deletions(-) delete mode 100644 src/CLI/actioner/port_channel_dummy_data.json diff --git a/src/CLI/actioner/port_channel_dummy_data.json b/src/CLI/actioner/port_channel_dummy_data.json deleted file mode 100644 index 20149bb2d5..0000000000 --- a/src/CLI/actioner/port_channel_dummy_data.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "openconfig-interfaces:interface": [ - { - "members": [ - "Ethernet56", - "Ethernet60" - ], - "min-links": 2, - "mtu": 9100, - "admin-status": "up", - "name": "Portchannel0" - }, - { - "members": [ - "Ethernet64", - "Ethernet68" - ], - "min-links": 1, - "mtu": 9100, - "admin-status": "up", - "name": "Portchannel1" - }, - { - "members": [ - "Ethernet24", - "Ethernet12" - ], - "min-links": 1, - "mtu": 9100, - "admin-status": "up", - "name": "Portchannel2" - }, - { - "members": [], - "min-links": 1, - "mtu": 9100, - "admin-status": "up", - "name": "Portchannel3" - }, - { - "members": [], - "min-links": 1, - "mtu": 9100, - "admin-status": "up", - "name": "Portchannel4" - } - ] -} diff --git a/src/CLI/actioner/sonic-cli-if.py b/src/CLI/actioner/sonic-cli-if.py index 2b20d9cfcd..770a644d28 100755 --- a/src/CLI/actioner/sonic-cli-if.py +++ b/src/CLI/actioner/sonic-cli-if.py @@ -21,7 +21,6 @@ import time import json import ast -import yaml import openconfig_interfaces_client from rpipe_utils import pipestr from openconfig_interfaces_client.rest import ApiException @@ -94,95 +93,76 @@ def run(func, args): c.verify_ssl = False aa = openconfig_interfaces_client.OpenconfigInterfacesApi(api_client=openconfig_interfaces_client.ApiClient(configuration=c)) -# Code for Portchannel cli skeleton, reading and writing data to port_channel_dummy_data json file +# Code for PortChannel cli skeleton + #create a port-channel - if "Portchannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface': - with open('port_channel_dummy_data.json', 'r') as f: - data= yaml.safe_load(f) - for dict in data['openconfig-interfaces:interface']: - if dict["name"] == args[0]: - return - body = { - "name": args[0], - "min-links": 1, - "mtu": 9100, - "admin-status": "up", - "members": [] - } - data['openconfig-interfaces:interface'].append(body) - with open('port_channel_dummy_data.json', 'w') as f: - json.dump(data, f, sort_keys=True, indent=4) - print ("Success") + if "PortChannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface': return + dummy_data= { + "openconfig-interfaces:interface": [ + { + "members": [ + "Ethernet56", + "Ethernet60" + ], + "min-links": 2, + "mtu": 9100, + "admin_status": "up", + "oper_status": "down", + "name": "PortChannel1" + }, + { + "members": [], + "min-links": 1, + "mtu": 9100, + "admin_status": "up", + "oper_status": "down", + "name": "PortChannel2" + }, + { + "members": [], + "min-links": 1, + "mtu": 9100, + "admin_status": "up", + "oper_status": "down", + "name": "PortChannel3" + } + ] +} + #show given port-channel details - if "Portchannel" in args[0] and func.__name__ == 'get_openconfig_if_aggregate_interfaces_interface_aggregation_state': - with open('port_channel_dummy_data.json', 'r') as f: - data= yaml.safe_load(f) - for dict in data['openconfig-interfaces:interface']: - if dict["name"] == args[0]: + if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_if_aggregate_interfaces_interface_aggregation_state': + for dict in dummy_data['openconfig-interfaces:interface']: + if dict["name"] == "PortChannel3": show_cli_output("show_portchannel_id.j2", dict) return print("%Error: Entry not found") return #show port-channels summary - if "Portchannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces': - with open('port_channel_dummy_data.json', 'r') as f: - data= yaml.safe_load(f) - show_cli_output("show_portchannel.j2", data) + if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces': + show_cli_output("show_portchannel.j2", dummy_data) return #add members to port-channel if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id': - port_c = 'Portchannel' + args[1] - with open('port_channel_dummy_data.json', 'r') as readf: - data= yaml.safe_load(readf) - for dict in data['openconfig-interfaces:interface']: - if dict["name"] == port_c: - dict["members"].append(args[0]) - with open('port_channel_dummy_data.json', 'w') as writef: - json.dump(data, writef, sort_keys=True, indent=4) - print ("Success") - return - print ("Failed-entry not found") return #remove members from port-channel if func.__name__ == 'delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id': - return("Success") + return #config mtu for port-channel if "po" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface_config_mtu': - return("Success") + return #delete port-channel - if "Portchannel" in args[0] and func.__name__ == 'delete_openconfig_interfaces_interfaces_interface': - with open('port_channel_dummy_data.json', 'r') as f: - data= yaml.safe_load(f) - for dict in data['openconfig-interfaces:interface']: - if dict["name"] == args[0]: - data['openconfig-interfaces:interface'].remove(dict) - with open('port_channel_dummy_data.json', 'w') as writef: - json.dump(data, writef, sort_keys=True, indent=4) - print ("Success") - return - print ("Failed-entry not found") + if "PortChannel" in args[0] and func.__name__ == 'delete_openconfig_interfaces_interfaces_interface': return #config min-links in port-channel if func.__name__ == 'patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links': - with open('port_channel_dummy_data.json', 'r') as f: - data= yaml.safe_load(f) - port_c = 'Portchannel'+args[0][2:] - for dict in data['openconfig-interfaces:interface']: - if dict["name"] == port_c: - dict["min-links"]=args[1] - with open('port_channel_dummy_data.json', 'w') as f: - json.dump(data, f, sort_keys=True, indent=4) - print ("Success") - return - print ("Failed-entry not found") return # create a body block diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index 5c0a3aa344..f46c082ddc 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -63,7 +63,7 @@ limitations under the License. > @@ -84,9 +84,9 @@ limitations under the License. python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces show_interface_counters.j2 elif test "${if-subcommands}" = "port-channel"; then if test "${lag-id}" = ""; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces Portchannel show_portchannel.j2 + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces PortChannel show_portchannel.j2 else - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_if_aggregate_interfaces_interface_aggregation_state Portchannel${lag-id} show_portchannel_id.j2#xA; + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_if_aggregate_interfaces_interface_aggregation_state PortChannel${lag-id} show_portchannel_id.j2#xA; fi else if test "${phy-if-id}" = ""; then @@ -151,7 +151,7 @@ limitations under the License. ptype="UINT" > - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface Portchannel${lag-id} + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface PortChannel${lag-id} @@ -195,7 +195,7 @@ limitations under the License. python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface Vlan${vlan-id} fi if test "${if-subcommands}" = "port-channel"; then - python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface Portchannel${lag-id} + python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_interfaces_interfaces_interface PortChannel${lag-id} fi diff --git a/src/CLI/renderer/templates/show_portchannel.j2 b/src/CLI/renderer/templates/show_portchannel.j2 index be5f282ad5..a0f45a4e56 100644 --- a/src/CLI/renderer/templates/show_portchannel.j2 +++ b/src/CLI/renderer/templates/show_portchannel.j2 @@ -5,5 +5,5 @@ Flags: A - Active, Dw - Oper status down {{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}} {{'----------------------------------------------------------------------------------------------------------------------------'}} {% for dict in json_output['openconfig-interfaces:interface'] %} -{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)(Dw)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin-status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}} +{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)(Dw)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin_status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}} {% endfor %} diff --git a/src/CLI/renderer/templates/show_portchannel_id.j2 b/src/CLI/renderer/templates/show_portchannel_id.j2 index b45173aaa9..20ccd97758 100644 --- a/src/CLI/renderer/templates/show_portchannel_id.j2 +++ b/src/CLI/renderer/templates/show_portchannel_id.j2 @@ -5,4 +5,4 @@ Flags: A - Active, Dw - Oper status down {{'%-20s'|format("Port-Channel")}}{{'%-20s'|format("min-links")}}{{'%-20s'|format("Protocol")}}{{'%-15s'|format("MTU")}}{{'%-15s'|format("Admin")}}{{'%-15s'|format("port-members")}} {{'----------------------------------------------------------------------------------------------------------------------------'}} {% set dict = json_output %} -{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin-status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}} +{{'%-20s'|format(dict['name']|string)}}{{'%-20s'|format(dict['min-links'])}}{{'%-20s'|format("LACP(A)")}}{{'%-15s'|format(dict['mtu'])}}{{'%-15s'|format(dict['admin_status'])}}{{'%-15s'|format(dict['members']|string|replace("[", "")|replace("]", ""))}} From 7a257f7b4731ec4df26498b83673c2d712b75728 Mon Sep 17 00:00:00 2001 From: Tejaswi Goel Date: Wed, 25 Sep 2019 17:17:32 -0700 Subject: [PATCH 3/4] Changes in show port-channel command Signed-off-by: Tejaswi Goel --- src/CLI/actioner/sonic-cli-if.py | 78 +++++++++--------- src/CLI/clitree/cli-xml/interface.xml | 81 ++++++++++++------- src/CLI/clitree/cli-xml/sonic_types.xml | 14 ++++ .../renderer/templates/show_portchannel.j2 | 9 ++- .../renderer/templates/show_portchannel_id.j2 | 8 -- 5 files changed, 106 insertions(+), 84 deletions(-) delete mode 100644 src/CLI/renderer/templates/show_portchannel_id.j2 diff --git a/src/CLI/actioner/sonic-cli-if.py b/src/CLI/actioner/sonic-cli-if.py index af02afcec8..5fe245442d 100755 --- a/src/CLI/actioner/sonic-cli-if.py +++ b/src/CLI/actioner/sonic-cli-if.py @@ -101,50 +101,44 @@ def run(func, args): if "PortChannel" in args[0] and func.__name__ == 'patch_openconfig_interfaces_interfaces_interface': return - dummy_data= { - "openconfig-interfaces:interface": [ - { - "members": [ - "Ethernet56", - "Ethernet60" - ], - "min-links": 2, - "mtu": 9100, - "admin_status": "up", - "oper_status": "down", - "name": "PortChannel1" - }, - { - "members": [], - "min-links": 1, - "mtu": 9100, - "admin_status": "up", - "oper_status": "down", - "name": "PortChannel2" - }, - { - "members": [], - "min-links": 1, - "mtu": 9100, - "admin_status": "up", - "oper_status": "down", - "name": "PortChannel3" - } - ] -} - - #show given port-channel details - if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_if_aggregate_interfaces_interface_aggregation_state': - for dict in dummy_data['openconfig-interfaces:interface']: - if dict["name"] == "PortChannel3": - show_cli_output("show_portchannel_id.j2", dict) - return - print("%Error: Entry not found") - return - #show port-channels summary if "PortChannel" in args[0] and func.__name__ == 'get_openconfig_interfaces_interfaces': - show_cli_output("show_portchannel.j2", dummy_data) + + dummy_resp= { + "PORTCHANNEL": [ + { + "members": [ + "Ethernet56", + "Ethernet60" + ], + "min-links": 2, + "mtu": 9100, + "admin_status": "up", + "oper_status": "down", + "name": "PortChannel1", + "id": "1" + }, + { + "members": [], + "min-links": 1, + "mtu": 9100, + "admin_status": "up", + "oper_status": "down", + "name": "PortChannel12", + "id": "12" + }, + { + "members": [], + "min-links": 1, + "mtu": 9100, + "admin_status": "up", + "oper_status": "down", + "name": "PortChannel3", + "id": "3" + } + ] + } + show_cli_output(args[1], dummy_resp) return #add members to port-channel diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index a72827413e..5ef58c8650 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -98,23 +98,15 @@ limitations under the License. - - - - if test "${lag-id}" = ""; then - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces PortChannel show_portchannel.j2 - else - python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_if_aggregate_interfaces_interface_aggregation_state PortChannel${lag-id} show_portchannel_id.j2#xA; - fi + mode="subcommand" /> + + + python $SONIC_CLI_ROOT/sonic-cli-if.py get_openconfig_interfaces_interfaces PortChannel show_portchannel.j2 @@ -163,7 +155,7 @@ limitations under the License. python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface PortChannel${lag-id} @@ -209,8 +201,8 @@ limitations under the License. > @@ -263,19 +255,45 @@ limitations under the License. - + + - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} ${lag-id} + ptype="LAG_ID" + > + + + + + + + + python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} ${lag-id} + - python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} + python $SONIC_CLI_ROOT/sonic-cli-if.py delete_openconfig_if_aggregate_interfaces_interface_ethernet_config_aggregate_id ${iface} - python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_interfaces_interfaces_interface_config_enabled ${iface} False @@ -438,7 +456,7 @@ limitations under the License. + ptype="MIN_LINK" /> python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} ${min-links} + + - @@ -485,6 +504,7 @@ limitations under the License. name="addr" help="IP address with mask" ptype="IP_ADDR_MASK" /> + + diff --git a/src/CLI/clitree/cli-xml/sonic_types.xml b/src/CLI/clitree/cli-xml/sonic_types.xml index 6b33089605..09a23fe5ef 100644 --- a/src/CLI/clitree/cli-xml/sonic_types.xml +++ b/src/CLI/clitree/cli-xml/sonic_types.xml @@ -41,6 +41,20 @@ limitations under the License. help="" /> + + + + Date: Wed, 2 Oct 2019 07:22:19 -0700 Subject: [PATCH 4/4] Correct naming convention for Interface commands Signed-off-by: Tejaswi Goel --- src/CLI/clitree/cli-xml/interface.xml | 16 ++++++++-------- src/CLI/renderer/templates/show_portchannel.j2 | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/CLI/clitree/cli-xml/interface.xml b/src/CLI/clitree/cli-xml/interface.xml index 5ef58c8650..b555b5a58b 100644 --- a/src/CLI/clitree/cli-xml/interface.xml +++ b/src/CLI/clitree/cli-xml/interface.xml @@ -97,12 +97,12 @@ limitations under the License. @@ -154,7 +154,7 @@ limitations under the License. @@ -452,10 +452,10 @@ limitations under the License. /> + help="Configure the minimum number of links in a PortChannel"> python $SONIC_CLI_ROOT/sonic-cli-if.py patch_openconfig_if_aggregate_interfaces_interface_aggregation_config_min_links ${po_id} ${min-links} diff --git a/src/CLI/renderer/templates/show_portchannel.j2 b/src/CLI/renderer/templates/show_portchannel.j2 index d1dba6e31e..da5986b640 100644 --- a/src/CLI/renderer/templates/show_portchannel.j2 +++ b/src/CLI/renderer/templates/show_portchannel.j2 @@ -1,6 +1,6 @@ {% set just_var = 2 %} Flags: D - Down - U - Up (port-channel) + U - Up (PortChannel) {{'----------------------------------------------------------------------------------------------------------------------------'}} {{'%-20s'|format("Group")}}{{'%-30s'|format("Port-Channel")}}{{'%-20s'|format("Type")}}{{'%-15s'|format("Protocol")}}{{'%-15s'|format("Member Ports")}}