class Portchnl
The Portchnl
class provides a class implementation and methods for managing Portchannel on the node. This class presents an abstraction
Public Class Methods
This API creates a portchannel.
Request URL: IP-ADDR:REST-PORT/api/portchnls/cfgs/10
payload format of key-value pairs { "admin_status": "up", "mtu": 9100, "fallback": true }
@param conn [Class] Connect
object to the node @param pch_id [Integer] Portchannel id @param admin_status [String] Admin status of the port-channel. Valid values “up” or “down” @param mtu [Integer] Max transmission unit. Valid Values: 1500-9100 @param fallback [Boolean] Fallback value “true” or “false”
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/portchnl.rb, line 105 def self.create_portchnl(conn, pch_id, admin_status='up', mtu=9100, fallback='false') url = form_url(conn, @portchnl_cfg + '/' + pch_id.to_s) hdr = form_hdr(conn) params = {"admin_status": admin_status, "mtu": mtu, "fallback": fallback} params = params.to_json Rest.post(conn, url, hdr, params) end
This API deletes specified portchannel.
Request URL: IP-ADDR:REST-PORT/api/portchnls/cfgs/10
@param conn [Class] Connect
object to the node @param pch_id [Integer] Portchannel Id
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/portchnl.rb, line 170 def self.delete_portchnl(conn, pch_id) url = form_url(conn, @portchnl_cfg + '/' + pch_id.to_s) hdr = form_hdr(conn) Rest.delete(conn, url, hdr) end
This API gets all the portchannel startup configuration.
Request URL: IP-ADDR:REST-PORT/api/portchnls/cfgs
@param conn [Class] Connect
object to the node
@return [RestClient::Request] Rest
output from SONIC in JSON format as below
{ "PortChannel200": { "members": ["Ethernet8", "Ethernet32", "Ethernet16"], "mtu": "9100", "admin_status": "up", "fallback": "true", }, }
# File lib/sonic-rbapi/portchnl.rb, line 156 def self.get_portchnl_cfg(conn) url = form_url(conn, @portchnl_cfg) hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API gets the portchannel information.
Request URL: IP-ADDR:REST-PORT/api/portchnls/info/summary - Get PortChannel summary information
http://IP-ADDR:REST-PORT/api/portchnls/info/state - Get Portchannel state information
@param conn [Class] Connect
object to the node @param filter [String] String to get PortChannel summary or state @param pch_id [Integer] Portchannel Id
@return [RestClient::Request] Rest
output from SONIC in JSON format
{ "PortChannelName": { "admin_status": "up", "oper_status": "down", "mtu": "9100", "members": { ":Interface": { "status": "Active or Inactive or Up or Down" } } } { “Member Name1”:{ "info": { "dev_addr": "mac", "ifindex": , }, "actor_lacpdu_info": { "key": , "port":, "port_priority":, "state": 0, "system": "a4:8c:db:b9:c4:00", "system_priority": 65535 }, "partner_lacpdu_info": { "key": 0, "port": 0, "port_priority": 0, "state": 0, "system": "00:00:00:00:00:00", "system_priority": 0 }, "aggregator": { "id": 0, "selected": false }, }, “Member Name2”:{ }, ……….. }
# File lib/sonic-rbapi/portchnl.rb, line 78 def self.get_portchnl_info(conn, filter, pch_id=nil) if pch_id != nil url = form_url(conn, @portchnl_info + '/' + filter + '/PortChannel' + pch_id.to_s) else url = form_url(conn, @portchnl_info + '/' + filter) end hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API updates the properties of a particular portchannel.
Request URL: IP-ADDR:REST-PORT/api/portchnls/cfgs/10
payload format of key-value pairs { "add_member": ["Ethernet0", "Ethernet4"], "rem_member": ["Ethernet12"] }
@param conn [Class] Connect
object to the node @param pch_id [Integer] Portchannel id @param add_members [Array] List of ports to be added to the portchnl @param rem_members [Array] List of ports to be removed from the portchnl
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/portchnl.rb, line 128 def self.update_portchnl_members(conn, pch_id, add_members=nil, rem_members=nil) url = form_url(conn, @portchnl_cfg + '/' + pch_id.to_s) hdr = form_hdr(conn) if add_members == nil || rem_members == nil puts("update_portchnl_members: wrong paramers\n") end params = {"add_member": add_members} p1 = {"rem_member": rem_members} params = params.merge(p1) params = params.to_json Rest.put(conn, url, hdr, params) end