Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
42 changes: 31 additions & 11 deletions CLI/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,51 @@ SHELL = /bin/bash
.ONESHELL:
.SHELLFLAGS += -e

CLIDEPS ?= packages
TOPDIR ?= $(abspath ..)
SUBDIRS := clitree renderer klish
export SONIC_CLI_ROOT=$(TOPDIR)/build
TGT_DIR := $(SONIC_CLI_ROOT)/target

CLI_DIR := $(TOPDIR)/CLI
PY_FILES := $(shell find $(CLI_DIR)/actioner -name '*.py')
PY_FILES += $(shell find $(CLI_DIR)/renderer/scripts -name '*.py')
PY_FILES += $(shell find $(CLI_DIR)/clitree/scripts -name '*.py')
PYLINT_DONE := $(SONIC_CLI_ROOT)/pylint/.pylint_done
TOOLS_DIR := $(TOPDIR)/tools
LINTER := $(TOOLS_DIR)/test/pylint.sh

.PHONY: clean

all: $(CLIDEPS)
all: $(PYLINT_DONE)
for dir in $(SUBDIRS); do \
$(MAKE) -C $$dir -f Makefile $@; \
done

rm -rf $(TOPDIR)/build/cli/*
rm -rf $(TOPDIR)/build/cli
mv -f $(TGT_DIR) $(TOPDIR)/build/cli

clean:
.SECONDEXPANSION:

#======================================================================
# Common rule for directories. Use "." suffix, like "xyz/."
#======================================================================
.PRECIOUS: %/.
%/.:
mkdir -p $@

pylint: $(PYLINT_DONE)

$(PYLINT_DONE): $(PY_FILES) | $$(@D)/.
$(LINTER) $?
touch $@

pylint-clean:
$(RM) -r $(PYLINT_DONE)
$(RM) -r $(SONIC_CLI_ROOT)/cli/pylint.log*

clean: pylint-clean
make --directory=klish clean
rm -rf $(TOPDIR)/build/cli
rm -rf $(TGT_DIR)

packages:
if ! dpkg -l | grep autoconf -c >>/dev/null; then sudo apt-get install autoconf; fi
if ! dpkg -l | grep m4 -c >>/dev/null; then sudo apt-get install m4; fi
if ! dpkg -l | grep libxml2-utils -c >>/dev/null; then sudo apt-get install libxml2-utils; fi
if ! dpkg -l | grep xsltproc -c >>/dev/null; then sudo apt-get install xsltproc; fi
if ! dpkg -l | grep python-lxml -c >>/dev/null; then sudo apt-get install python-lxml; fi
if ! dpkg -l | grep libexpat1-dev -c >>/dev/null; then sudo apt-get install libexpat1-dev; fi

3 changes: 2 additions & 1 deletion CLI/actioner/cli_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python3
################################################################################
# #
# Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or #
Expand Down Expand Up @@ -122,7 +123,7 @@ def __init__(self, template, **kwargs):
self.template = template
self.params = kwargs
self.path = template
for k, v in kwargs.items():
for k, v in list(kwargs.items()):
self.path = self.path.replace('{%s}' % k, quote(v, safe=''))

def __str__(self):
Expand Down
7 changes: 4 additions & 3 deletions CLI/actioner/cli_log.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/python3
################################################################################
# #
# Copyright 2019 Broadcom. The term Broadcom refers to Broadcom Inc. and/or #
Expand Down Expand Up @@ -42,7 +43,7 @@ def log_error(msg):


def __write_log(severity, msg):
if not isinstance(msg, basestring):
if not isinstance(msg, str):
msg = str(msg)

syslog.syslog(severity, msg)
Expand All @@ -51,9 +52,9 @@ def __write_log(severity, msg):
caller_frame = inspect.stack()[2][0]
frame_info = inspect.getframeinfo(caller_frame)
for line in msg.split('\n'):
print('[{}:{}/{}] {}:: {}'.format(
print(('[{}:{}/{}] {}:: {}'.format(
os.path.basename(frame_info.filename),
frame_info.lineno,
frame_info.function,
__severity_str[severity],
line))
line)))
24 changes: 12 additions & 12 deletions CLI/actioner/sonic-cli-acl.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
###########################################################################
#
# Copyright 2019 Dell, Inc.
Expand Down Expand Up @@ -73,11 +73,11 @@ def generate_body(func, args):

# Configure ACL rule specific to an ACL table
elif func.__name__ == 'patch_list_openconfig_acl_acl_acl_sets_acl_set_acl_entries_acl_entry' :
keypath = [ args[0], args[1] ]
keypath = [ args[0], args[1] ]
forwarding_action = "ACCEPT" if args[3] == 'permit' else 'DROP'
proto_number = {"icmp":"IP_ICMP","tcp":"IP_TCP","udp":"IP_UDP","6":"IP_TCP","17":"IP_UDP","1":"IP_ICMP",
"2":"IP_IGMP","103":"IP_PIM","46":"IP_RSVP","47":"IP_GRE","51":"IP_AUTH","115":"IP_L2TP"}
if args[4] not in proto_number.keys():
if args[4] not in list(proto_number.keys()):
print("%Error: Invalid protocol number")
exit(1)
else:
Expand Down Expand Up @@ -222,29 +222,29 @@ def run(func, args):
print ("Success")
else:
response = api_response.to_dict()
if 'openconfig_aclacl_entry' in response.keys():
if 'openconfig_aclacl_entry' in list(response.keys()):
value = response['openconfig_aclacl_entry']
if value is None:
print("Success")
else:
print ("Failed")
elif 'openconfig_aclacl_set' in response.keys():
elif 'openconfig_aclacl_set' in list(response.keys()):
value = response['openconfig_aclacl_set']
if value is None:
print("Success")
else:
print("Failed")
elif 'openconfig_aclacl_entries' in response.keys():
elif 'openconfig_aclacl_entries' in list(response.keys()):
value = response['openconfig_aclacl_entries']
if value is None:
return
show_cli_output(args[2], value)
elif 'openconfig_aclacl_sets' in response.keys():
elif 'openconfig_aclacl_sets' in list(response.keys()):
value = response['openconfig_aclacl_sets']
if value is None:
return
show_cli_output(args[0], value)
elif 'openconfig_aclinterfaces' in response.keys():
elif 'openconfig_aclinterfaces' in list(response.keys()):
value = response['openconfig_aclinterfaces']
if value is None:
return
Expand All @@ -263,15 +263,15 @@ def run(func, args):

errDict = {}
for dict in errList:
for k, v in dict.iteritems():
for k, v in dict.items():
errDict[k] = v

if "error-message" in errDict:
print "%Error: " + errDict["error-message"]
print("%Error: " + errDict["error-message"])
return
print "%Error: Transaction Failure"
print("%Error: Transaction Failure")
return
print "%Error: Transaction Failure"
print("%Error: Transaction Failure")


if __name__ == '__main__':
Expand Down
16 changes: 8 additions & 8 deletions CLI/actioner/sonic-cli-if.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
###########################################################################
#
# Copyright 2019 Dell, Inc.
Expand Down Expand Up @@ -70,7 +70,7 @@ def generate_body(func, args):
elif func.__name__ == 'delete_openconfig_if_ip_interfaces_interface_subinterfaces_subinterface_ipv6_addresses_address_config_prefix_length':
keypath = [args[0], 0, args[1]]
elif func.__name__ == 'get_openconfig_interfaces_interfaces_interface':
keypath = [args[0]]
keypath = [args[0]]
elif func.__name__ == 'get_openconfig_interfaces_interfaces':
keypath = []
else:
Expand All @@ -84,7 +84,7 @@ def getId(item):
ifName = state_dict['name']

if ifName.startswith(prfx):
ifId = int(ifName[len(prfx):])
ifId = ifName[len(prfx):]
return ifId
return ifName

Expand Down Expand Up @@ -134,17 +134,17 @@ def run(func, args):

errDict = {}
for dict in errList:
for k, v in dict.iteritems():
for k, v in dict.items():
errDict[k] = v

if "error-message" in errDict:
print "%Error: " + errDict["error-message"]
print("%Error: " + errDict["error-message"])
return
print "%Error: Transaction Failure"
print("%Error: Transaction Failure")
return
print "%Error: Transaction Failure"
print("%Error: Transaction Failure")
else:
print "Failed"
print("Failed")

if __name__ == '__main__':

Expand Down
28 changes: 14 additions & 14 deletions CLI/actioner/sonic-cli-lldp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
###########################################################################
#
# Copyright 2019 Dell, Inc.
Expand Down Expand Up @@ -70,28 +70,28 @@ def run(func, args):
print ("Success")
else:
response = api_response.to_dict()
if 'openconfig_lldpinterfaces' in response.keys():
if 'openconfig_lldpinterfaces' in list(response.keys()):
if not response['openconfig_lldpinterfaces']:
return
neigh_list = response['openconfig_lldpinterfaces']['interface']
neigh_list = response['openconfig_lldpinterfaces']['interface']
if neigh_list is None:
return
show_cli_output(sys.argv[2],neigh_list)
elif 'openconfig_lldpinterface' in response.keys():
neigh = response['openconfig_lldpinterface']#[0]['neighbors']['neighbor']
show_cli_output(sys.argv[2],neigh_list)
elif 'openconfig_lldpinterface' in list(response.keys()):
neigh = response['openconfig_lldpinterface']#[0]['neighbors']['neighbor']
if neigh is None:
return
if sys.argv[3] is not None:
if neigh[0]['neighbors']['neighbor'][0]['state'] is None:
print('No LLDP neighbor interface')
else:
show_cli_output(sys.argv[2],neigh)
else:
show_cli_output(sys.argv[2],neigh)
if sys.argv[3] is not None:
if neigh[0]['neighbors']['neighbor'][0]['state'] is None:
print('No LLDP neighbor interface')
else:
show_cli_output(sys.argv[2],neigh)
else:
show_cli_output(sys.argv[2],neigh)
else:
print("Failed")
except ApiException as e:
print("Exception when calling OpenconfigLldpApi->%s : %s\n" %(func.__name__, e))
print(("Exception when calling OpenconfigLldpApi->%s : %s\n" %(func.__name__, e)))

if __name__ == '__main__':
pipestr().write(sys.argv)
Expand Down
26 changes: 13 additions & 13 deletions CLI/actioner/sonic-cli-pfm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
###########################################################################
#
# Copyright 2019 Dell, Inc.
Expand Down Expand Up @@ -26,15 +26,15 @@
blocked_fields = {'parent':0, 'used_power':0, 'allocated_power':0, 'temperature':0}

def filter_json_value(value):
for key,val in value.items():
for key,val in list(value.items()):
if key in blocked_fields:
del value[key]
else:
temp = key.split('_')
alt_key = ''
for i in temp:
alt_key = alt_key + i.capitalize() + ' '
value[alt_key]=value.pop(key)
temp = key.split('_')
alt_key = ''
for i in temp:
alt_key = alt_key + i.capitalize() + ' '
value[alt_key]=value.pop(key)

return value

Expand All @@ -52,16 +52,16 @@ def run(func, args):
return
else:
value = api_response['openconfig-platform:components']['component'][0]['state']
if value is None:
if value is None:
return
if 'oper-status' in value:
temp = value['oper-status'].split(':')
if temp[len(temp) - 1] is not None:
value['oper-status'] = temp[len(temp) - 1]
if 'oper-status' in value:
temp = value['oper-status'].split(':')
if temp[len(temp) - 1] is not None:
value['oper-status'] = temp[len(temp) - 1]
show_cli_output(sys.argv[2],filter_json_value(value))

else:
print(response.error_message())
print((response.error_message()))
return 1

if __name__ == '__main__':
Expand Down
Loading