Skip to content

CLI skeleton for Port channel #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/CLI/actioner/port_channel_dummy_data.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
93 changes: 92 additions & 1 deletion src/CLI/actioner/sonic-cli-if.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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] }
Expand Down Expand Up @@ -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)

Expand Down
Loading