class Lldp
The Lldp
class provides a class implementation and methods for managing LLdp on the node. This class presents an abstraction
Public Class Methods
This API gets LLDP information from the switch
Request URL: IP-ADDR:REST-PORT/api/lldps/info/chassis: Get chassis (switch) detailed information
http://IP-ADDR:REST-PORT/api/lldps/info/stats: Get statistics summary information http://IP-ADDR:REST-PORT/api/lldps/info/stats/Ethernet0: Get statistics information for a specific port http://IP-ADDR:REST-PORT/api/lldps/info/config: Get LLDP configuration http://IP-ADDR:REST-PORT/api/lldps/neighbors: Get LLDP neighbor information for all ports http://IP-ADDR:REST-PORT/api/lldps/info/neighbors/Ethernet0: Get LLDP neighbor information for a specific port
@param conn [Class] Connect
object to the node @param filter [String] LLDP info filter which holds the value chassis/stats/config/neighbors @param port_name [String] Port name
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/lldp.rb, line 40 def self.get_lldp_info(conn, filter, port_name=nil) chassis_filter = "chassis" stats_filter = "stats" cfg_filter = "config" neighbor_filter = "neighbors" if filter == chassis_filter url = form_url(conn, @lldp_info + '/' + chassis_filter) elsif filter == stats_filter if port_name == nil url = form_url(conn, @lldp_info + '/' + stats_filter) else url = form_url(conn, @lldp_info + '/' + stats_filter + '/' + port_name) end elsif filter == cfg_filter url = form_url(conn, @lldp_info + '/' + cfg_filter) elsif filter == neighbor_filter if port_name == nil url = form_url(conn, @lldp_info + '/' + neighbor_filter) else url = form_url(conn, @lldp_info + '/' + neighbor_filter + '/' + port_name) end end hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API updates the global LLDP config on the switch.
Request URL: IP-ADDR:REST-PORT/api/lldps/cfgs
payload format of key-value pairs { "tx_interval": <tx_interval>, "tx_hold": <tx_hold>, "admin_status": <admin_status>, "capabilities_ad": <cap_status>, "mgmt_addr_ad": <mgmt_status>, }
@param conn [Class] Connect
object to the node @param tx_interval [Integer] LLDP transmit delay in seconds (optional) @param tx_hold [Integer] LLDP transmit hold in seconds (optional) @param admin_status [String] LLDP admin status(mandatory). Valid values: tx-only, rx-only, rx-and-tx, disabled @param capabilities_ad [Boolean] Enable/disable capabilities advertisement (optional). Valid values: true, false @param mgmt_addr_ad [Boolean] Enable/disable management address advertisement (optional). Valid values: true, false
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/lldp.rb, line 87 def self.update_lldp_global_config(conn, tx_interval=0, tx_hold=0, admin_status='rx-and-tx', capabilities_ad='true', mgmt_addr_ad='false') url = form_url(conn, @lldp_cfg) hdr = form_hdr(conn) params = {"tx_interval": tx_interval, "tx_hold": tx_hold, "admin_status": admin_status, "capabilities_ad": capabilities_ad, "mgmt_addr_ad": mgmt_addr_ad} params = params.to_json Rest.put(conn, url, hdr, params) end
This API updates the LLDP port configuration on the switch.
Request URL: IP-ADDR:REST-PORT/api/lldps/cfgs/Ethernet0
payload format of key-value pairs { "admin_status": <admin_status>, "mgmt_addr_ad": <mgmt_status>, }
@param conn [Class] Connect
object to the node @param port_name [String] Port Name @param admin_status [String] LLDP admin status (mandatory). Valid values: tx-only, rx-only, rx-and-tx, disabled @param mgmt_status [Boolean] Enable/disable management address advertisement (optional). Valid values: true, false
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/lldp.rb, line 110 def self.update_lldp_port_config(conn, port_name, admin_status='rx-and-tx', mgmt_status='false') url = form_url(conn, @lldp_cfg + '/' + port_name) hdr = form_hdr(conn) params = {"admin_status": admin_status, "mgmt_addr_ad": mgmt_status} params = params.to_json Rest.put(conn, url, hdr, params) end