Class: Interfaces

Inherits:
Object
  • Object
show all
Defined in:
lib/sonic-rbapi/interfaces.rb

Overview

The Interface class provides a class implementation and methods for managing the Interfaces on the node. This class presents an abstraction

Class Method Summary collapse

Class Method Details

.get_interface_cfg(conn, interface = nil) ⇒ RestClient::Request

This API get the configuration of particular or all interface.

Request URL: IP-ADDR:REST-PORT/api/interfaces/cfgs/Ethernet0

Parameters:

  • conn (Class)

    Connect object to the node

  • interface (String) (defaults to: nil)

    Interface Name or nil

Returns:

  • (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",
    



165
166
167
168
169
170
171
172
173
# 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

.get_interface_info(conn, interface = nil) ⇒ RestClient::Request

This API get the interface information.

Request URL: IP-ADDR:REST-PORT/api/interfaces/info/Ethernet0

http://IP-ADDR:REST-PORT/api/interfaces/info

Parameters:

  • conn (Class)

    Connect object to the node

  • interface (String) (defaults to: nil)

    Interface Name

Returns:

  • (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": ""
    }
    

    }



47
48
49
50
51
52
53
54
55
# 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

.get_interface_stats(conn, interface = nil) ⇒ RestClient::Request

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

Parameters:

  • conn (Class)

    Connect object to the node

  • interface (String) (defaults to: nil)

    Interface Name

Returns:

  • (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,
        ...
    }
    

    }



77
78
79
80
81
82
83
84
85
# 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

.get_interface_transceivers(conn, interface = nil) ⇒ RestClient::Request

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

Parameters:

  • conn (Class)

    Connect object to the node

  • interface (String) (defaults to: nil)

    Interface Name

Returns:

  • (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: “”
    }
    

    }



111
112
113
114
115
116
117
118
119
# 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

.update_interface_cfg(conn, interface, fec = "none", mtu = 9100, speed = 100000, admin_status = "up") ⇒ RestClient::Request

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",
}

Parameters:

  • conn (Class)

    Connect object to the node

  • interface (String)

    Interface Name

  • fec (String) (defaults to: "none")

    Forwarding error correction setting(optional). Valid Values: “none”, “rs”, “fc”

  • mtu (Integer) (defaults to: 9100)

    Maximum transmission unit (optional)

  • speed (Integer) (defaults to: 100000)

    Interface’s speed in Mbps (optional)

  • admin_status (String) (defaults to: "up")

    Admin status of the interface (mandatory). Valid Values: “up” or “down”

Returns:

  • (RestClient::Request)

    Rest output from SONIC in JSON format



140
141
142
143
144
145
146
# 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