[lldpmgr] add mgmt ip to lldpd conf template, handle port description/alias changes (#2396)
* [lldpmgr] add mgmt ip to lldpd conf templte, handle port description/alias config Signed-off-by: Mykola Faryma <mykolaf@mellanox.com> * fix typo * [config-engine] update test sample output lldpd.conf Signed-off-by: Mykola Faryma <mykolaf@mellanox.com> * fix the log message * fix lldpd.conf.j2
This commit is contained in:
parent
3f6ad44230
commit
52c533fe01
@ -1,9 +1,11 @@
|
|||||||
{% if MGMT_INTERFACE %}
|
{% if MGMT_INTERFACE %}
|
||||||
{# If MGMT port alias is available, use it for port ID subtype, otherwise use port name #}
|
{# If MGMT port alias is available, use it for port ID subtype, otherwise use port name #}
|
||||||
{% set mgmt_port_name = MGMT_INTERFACE.keys()[0][0] %}
|
{% set mgmt_port_name = MGMT_INTERFACE.keys()[0][0] %}
|
||||||
|
{% set ipv4 = MGMT_INTERFACE.keys()[0][1].split('/')[0] %}
|
||||||
{% if MGMT_PORT and MGMT_PORT[mgmt_port_name] and MGMT_PORT[mgmt_port_name].alias %}
|
{% if MGMT_PORT and MGMT_PORT[mgmt_port_name] and MGMT_PORT[mgmt_port_name].alias %}
|
||||||
configure ports eth0 lldp portidsubtype local {{ MGMT_PORT[mgmt_port_name].alias }}
|
configure ports eth0 lldp portidsubtype local {{ MGMT_PORT[mgmt_port_name].alias }}
|
||||||
{% else %}
|
{% else %}
|
||||||
configure ports eth0 lldp portidsubtype local {{ mgmt_port_name }}
|
configure ports eth0 lldp portidsubtype local {{ mgmt_port_name }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
configure system ip management pattern {{ ipv4 }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -119,9 +119,8 @@ class LldpManager(object):
|
|||||||
|
|
||||||
def generate_pending_lldp_config_cmd_for_port(self, port_name):
|
def generate_pending_lldp_config_cmd_for_port(self, port_name):
|
||||||
"""
|
"""
|
||||||
For port `port_name`, look up the neighboring device's hostname and
|
For port `port_name`, look up the description and alias in the Config database,
|
||||||
corresponding port alias in the Config database, then form the
|
then form the appropriate lldpcli configuration command and run it.
|
||||||
appropriate lldpcli configuration command and run it.
|
|
||||||
"""
|
"""
|
||||||
# Retrieve all entires for this port from the Port table
|
# Retrieve all entires for this port from the Port table
|
||||||
port_table = swsscommon.Table(self.config_db, swsscommon.CFG_PORT_TABLE_NAME)
|
port_table = swsscommon.Table(self.config_db, swsscommon.CFG_PORT_TABLE_NAME)
|
||||||
@ -135,34 +134,21 @@ class LldpManager(object):
|
|||||||
if not port_alias:
|
if not port_alias:
|
||||||
log_info("Unable to retrieve port alias for port '{}'. Using port name instead.".format(port_name))
|
log_info("Unable to retrieve port alias for port '{}'. Using port name instead.".format(port_name))
|
||||||
port_alias = port_name
|
port_alias = port_name
|
||||||
|
|
||||||
|
# Get the port description. If None or empty string, we'll skip this configuration
|
||||||
|
port_desc = port_table_dict.get("description")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log_error("Port '{}' not found in {} table in Config DB. Using port name instead of port alias.".format(port_name, swsscommon.CFG_PORT_TABLE_NAME))
|
log_error("Port '{}' not found in {} table in Config DB. Using port name instead of port alias.".format(port_name, swsscommon.CFG_PORT_TABLE_NAME))
|
||||||
port_alias = port_name
|
port_alias = port_name
|
||||||
|
|
||||||
lldpcli_cmd = "lldpcli configure ports {0} lldp portidsubtype local {1}".format(port_name, port_alias)
|
lldpcli_cmd = "lldpcli configure ports {0} lldp portidsubtype local {1}".format(port_name, port_alias)
|
||||||
|
|
||||||
# Retrieve all entires for this port from the Device Neighbor table
|
# if there is a description available, also configure that
|
||||||
device_neighbor_table = swsscommon.Table(self.config_db, swsscommon.CFG_DEVICE_NEIGHBOR_TABLE_NAME)
|
if port_desc:
|
||||||
(status, fvp) = device_neighbor_table.get(port_name)
|
lldpcli_cmd += " description {}".format(port_desc)
|
||||||
if status:
|
|
||||||
# Convert list of tuples to a dictionary
|
|
||||||
device_neighbor_table_dict = dict(fvp)
|
|
||||||
|
|
||||||
# Get neighbor host name and port name
|
|
||||||
neighbor_hostname = device_neighbor_table_dict.get("name")
|
|
||||||
neighbor_portname = device_neighbor_table_dict.get("port")
|
|
||||||
|
|
||||||
# If we sucessfully obtained the neighbor's host name and port name, append a port description to the command
|
|
||||||
if neighbor_hostname and neighbor_portname:
|
|
||||||
lldpcli_cmd += " description {0}:{1}".format(neighbor_hostname, neighbor_portname)
|
|
||||||
else:
|
|
||||||
if not neighbor_hostname:
|
|
||||||
log_info("Failed to retrieve neighbor host name for port '{}'. Not adding port description.".format(port_name))
|
|
||||||
|
|
||||||
if not neighbor_portname:
|
|
||||||
log_info("Failed to retrieve neighbor port name for port '{}'. Not adding port description.".format(port_name))
|
|
||||||
else:
|
else:
|
||||||
log_info("Unable to retrieve neighbor information for port '{}'. Not adding port description.".format(port_name))
|
log_info("Unable to retrieve description for port '{}'. Not adding port description".format(port_name))
|
||||||
|
|
||||||
# Add the command to our dictionary of pending commands, overwriting any
|
# Add the command to our dictionary of pending commands, overwriting any
|
||||||
# previous pending command for this port
|
# previous pending command for this port
|
||||||
@ -200,9 +186,11 @@ class LldpManager(object):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""
|
"""
|
||||||
Infinite loop. Subscribes to notifications of changes in the PORT table
|
Subscribes to notifications of changes in the PORT table
|
||||||
of the Redis State database. When we are notified of the creation of an
|
of the Redis State database.
|
||||||
interface, update LLDP configuration accordingly.
|
Subscribe to STATE_DB - get notified of the creation of an interface
|
||||||
|
Subscribe to CONFIG_DB - get notified of port config changes
|
||||||
|
Update LLDP configuration accordingly.
|
||||||
"""
|
"""
|
||||||
# Set select timeout to 10 seconds
|
# Set select timeout to 10 seconds
|
||||||
SELECT_TIMEOUT_MS = 1000 * 10
|
SELECT_TIMEOUT_MS = 1000 * 10
|
||||||
@ -211,8 +199,10 @@ class LldpManager(object):
|
|||||||
sel = swsscommon.Select()
|
sel = swsscommon.Select()
|
||||||
sst = swsscommon.SubscriberStateTable(self.state_db, swsscommon.STATE_PORT_TABLE_NAME)
|
sst = swsscommon.SubscriberStateTable(self.state_db, swsscommon.STATE_PORT_TABLE_NAME)
|
||||||
sel.addSelectable(sst)
|
sel.addSelectable(sst)
|
||||||
|
sst = swsscommon.SubscriberStateTable(self.config_db, swsscommon.CFG_PORT_TABLE_NAME)
|
||||||
|
sel.addSelectable(sst)
|
||||||
|
|
||||||
# Listen indefinitely for changes to the PORT table in the State DB
|
# Listen for changes to the PORT table in the STATE_DB and CONFIG_DB
|
||||||
while True:
|
while True:
|
||||||
(state, c) = sel.select(SELECT_TIMEOUT_MS)
|
(state, c) = sel.select(SELECT_TIMEOUT_MS)
|
||||||
|
|
||||||
@ -221,9 +211,14 @@ class LldpManager(object):
|
|||||||
|
|
||||||
fvp_dict = dict(fvp)
|
fvp_dict = dict(fvp)
|
||||||
|
|
||||||
|
# handle creation
|
||||||
if op == "SET" and fvp_dict.get("state") == "ok":
|
if op == "SET" and fvp_dict.get("state") == "ok":
|
||||||
self.generate_pending_lldp_config_cmd_for_port(key)
|
self.generate_pending_lldp_config_cmd_for_port(key)
|
||||||
|
|
||||||
|
# handle config change
|
||||||
|
if op in ["SET", "DEL"] and (fvp_dict.get("alias") or fvp_dict.get("description")) :
|
||||||
|
self.generate_pending_lldp_config_cmd_for_port(key)
|
||||||
|
|
||||||
# Process all pending commands
|
# Process all pending commands
|
||||||
self.process_pending_cmds()
|
self.process_pending_cmds()
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
configure ports eth0 lldp portidsubtype local eth0
|
configure ports eth0 lldp portidsubtype local eth0
|
||||||
|
configure system ip management pattern 10.0.0.100
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user