Skip to content
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

lldp-show: skip containers not in running state #1656

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions scripts/lldpshow
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ LLDP_INSTANCE_IN_HOST_NAMESPACE = ''
LLDP_DEFAULT_INTERFACE_LIST_IN_ASIC_NAMESPACE = ''
SPACE_TOKEN = ' '

# Global helper function to check if LLDP docker is running for a given namespace
def is_instance_running(instance_num):
lldp_container_cmd = 'sudo docker container inspect -f {{.State.Status}} lldp{} '.format(instance_num)
p = subprocess.Popen(lldp_container_cmd, stdout=subprocess.PIPE, shell=True, text=True)
(output, err) = p.communicate()

## Wait for end of command. Get return returncode ##
returncode = p.wait()

if returncode == 0:
if output == 'running':
return True
return False

class Lldpshow(object):
def __init__(self):
Expand Down Expand Up @@ -78,6 +91,11 @@ class Lldpshow(object):
"""
for lldp_instace_num in range(len(self.lldp_instance)):
lldp_interface_list = lldp_port if lldp_port is not None else self.lldp_interface[lldp_instace_num]

# Skip instances that are not in 'running' state
if is_instance_running(self.lldp_instance[lldp_instace_num]) == False:
continue

# In detail mode we will pass interface list (only front ports) and get O/P as plain text
# and in table format we will get xml output
lldp_cmd = 'sudo docker exec -i lldp{} lldpctl '.format(self.lldp_instance[lldp_instace_num]) + (
Expand Down