Class: Config
- Inherits:
-
Object
- Object
- Config
- Defined in:
- lib/sonic-rbapi/config.rb
Overview
The Config class provides a class implementation and methods for managing the configs on the node. This class presents an abstraction
Class Method Summary collapse
-
.get_switch_config(conn, cfgblk) ⇒ RestClient::Request
This API gets the switch configuration.
-
.switch_config_action(conn, action = "config_save", protocol = nil, server_ip = nil, config_file = nil, username = nil, password = nil, port = 0) ⇒ RestClient::Request
This API configure the switch actions related to configurations.
Class Method Details
.get_switch_config(conn, cfgblk) ⇒ RestClient::Request
This API gets the switch configuration.
Request URL: IP-ADDR:REST-PORT/api/configs?cfgblk=running
48 49 50 51 52 |
# 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 |
.switch_config_action(conn, action = "config_save", protocol = nil, server_ip = nil, config_file = nil, username = nil, password = nil, port = 0) ⇒ RestClient::Request
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>,
}
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# 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 |