class Interfaces
The Interface class provides a class implementation and methods for managing the Interfaces
on the node. This class presents an abstraction
Public Class Methods
This API get the configuration of particular or all interface.
Request URL: IP-ADDR:REST-PORT/api/interfaces/cfgs/Ethernet0
@param conn [Class] Connect
object to the node @param interface [String] Interface Name or nil
@return [RestClient::Request] Rest
output from SONIC in JSON format as below
{ "interface": "<interfaceid>", "alias": "hundredGigE1/1" "fec": "none", "speed": "100000", "mtu": "9100", "lanes": "33,34,35,36", "admin_status": "up", }
# File lib/sonic-rbapi/interfaces.rb, line 165 def self.get_interface_cfg(conn, interface=nil) if (interface != nil) url = form_url(conn, @interface_cfg + '/' + interface.to_s) else url = form_url(conn, @interface_cfg) end hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API get the interface information.
Request URL: IP-ADDR:REST-PORT/api/interfaces/info/Ethernet0
http://IP-ADDR:REST-PORT/api/interfaces/info
@param conn [Class] Connect
object to the node @param interface [String] Interface Name
@return [RestClient::Request] Rest
output from SONIC in JSON format
{ "InterfaceName": Ethernet0 { "lanes": "", "alias": "", "admin_status": "up or down", "oper_status": "up or down", "speed": "", "transceiver": "" } }
# File lib/sonic-rbapi/interfaces.rb, line 47 def self.get_interface_info(conn, interface=nil) if interface == nil url = form_url(conn, @interface_info) else url = form_url(conn, @interface_info + '/' + interface.to_s) end hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API get the interface statistics.
Request URL: IP-ADDR:REST-PORT/api/interfaces/info/stats/Ethernet0
http://IP-ADDR:REST-PORT/api/interfaces/info/stats
@param conn [Class] Connect
object to the node @param interface [String] Interface Name
@return [RestClient::Request] Rest
output from SONIC in JSON format
{ "collected_time": "03/20/2019, 18:53:05", "Ethernet120": { "IF_IN_OCTETS": 0, "IF_IN_UCAST_PKTS": 0, "IF_IN_NON_UCAST_PKTS": 0, "IF_IN_DISCARDS": 0, "IF_IN_ERRORS": 0, ... } }
# File lib/sonic-rbapi/interfaces.rb, line 77 def self.get_interface_stats(conn, interface=nil) if interface == nil url = form_url(conn, @interface_stats) else url = form_url(conn, @interface_stats + '/' + interface.to_s) end hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API get the interface transceiver information.
Request URL: IP-ADDR:REST-PORT/api/interfaces/transceivers/Ethernet0
http://IP-ADDR:REST-PORT/api/interfaces/transceivers
@param conn [Class] Connect
object to the node @param interface [String] Interface Name
@return [RestClient::Request] Rest
output from SONIC in JSON format
{ "Interface Name": { Present :”true or false”, Encoding: “’, Length Cable Assembly(m): , Specification compliance: “” Vendor Date Code(YYYY-MM-DD Lot): “” Vendor Name: “” Vendor OUI: “” Vendor PN: “” Vendor Rev: “” Vendor SN: “” } }
# File lib/sonic-rbapi/interfaces.rb, line 111 def self.get_interface_transceivers(conn, interface=nil) if interface == nil url = form_url(conn, @interface_transceiver) else url = form_url(conn, @interface_transceiver + '/' + interface.to_s) end hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API updates properties of a interface.
Request URL: IP-ADDR:REST-PORT/api/interfaces/cfgs/Ethernet0
payload format of key-value pairs { "fec": "none", "mtu": "9100", "speed": "100000", "admin_status": "up", }
@param conn [Class] Connect
object to the node @param interface [String] Interface Name @param fec {String] Forwarding error correction setting(optional). Valid Values: “none”, “rs”, “fc” @param mtu [Integer] Maximum transmission unit (optional) @param speed [Integer] Interface's speed in Mbps (optional) @param admin_status [String] Admin status of the interface (mandatory). Valid Values: “up” or “down”
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/interfaces.rb, line 140 def self.update_interface_cfg(conn, interface, fec="none", mtu=9100, speed=100000, admin_status="up") url = form_url(conn, @interface_cfg + '/' + interface.to_s) hdr = form_hdr(conn) params = {"fec": fec, "mtu": mtu, "speed": speed, "admin_status": admin_status} params = params.to_json Rest.post(conn, url, hdr, params) end