class Config
The Config
class provides a class implementation and methods for managing the configs on the node. This class presents an abstraction
Public Class Methods
This API gets the switch configuration.
Request URL: IP-ADDR:REST-PORT/api/configs?cfgblk=running
@param conn [Class] Connect
object to the node @param cfgblk [String] Configuration blocks. Valid values are “running” and “bootup”
@return [RestClient::Request] Rest
output from SONIC in JSON format as below
{ "PORTCHANNEL": { "PortChannel200": { "mtu": "9100", "admin_status": "up", "fallback": "true", "min_links": "2" } }, "INTERFACE": { "Ethernet4|4.4.4.1/24": {}, "Ethernet8|10.0.0.4/31": {} }, ... }
# File lib/sonic-rbapi/config.rb, line 48 def self.get_switch_config(conn, cfgblk) url = form_url(conn, @config_cfg + '?cfgblk=' + cfgblk) hdr = form_hdr(conn) Rest.get(conn, url, hdr) end
This API configure the switch actions related to configurations.
Request URL: IP-ADDR:REST-PORT/api/configs
payload format of key-value pairs { "action": "config_save" "protocol": "tftp" "serverip": "", "config_file": "", "username": "", "passwd": "”, "port": <int>, }
@param conn [Class] Connect
object to the node @param action [String] Configuration actions
Valid Values: - "config_save" to save running configuration to bootup configuration file (default). - "config_upload" Upload file from a server to startup configuration block. Server details can be obtained from the further parameters.
@param protocol [String] Protocol to communicate which includes “tftp” or “scp” or “http” @param server_ip [String] Server ip address @param config_file [String] Configuration file @param username [String] Username to login the server @param password [String] Password for the server @param port [Integer] TCP port used by file transfer protocol
@return [RestClient::Request] Rest
output from SONIC in JSON format
# File lib/sonic-rbapi/config.rb, line 82 def self.switch_config_action(conn, action="config_save", protocol=nil, server_ip=nil, config_file=nil, username=nil, password=nil, port=0) url = form_url(conn, @config_cfg) hdr = form_hdr(conn) params = {"action": action} if protocol != nil p1 = {"protocol": protocol} params = params.merge(p1) end if server_ip != nil p1 = {"serverip": server_ip} params = params.merge(p1) end if config_file != nil p1 = {"config_file": config_file} params = params.merge(p1) end if username != nil p1 = {"username": username} params = params.merge(p1) end if password != nil p1 = {"passwd": password} params = params.merge(p1) end if port != nil p1 = {"port": port} params = params.merge(p1) end params = params.to_json Rest.post(conn, url, hdr, params) end