Class: Config

Inherits:
Object
  • Object
show all
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

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

Parameters:

  • conn (Class)

    Connect object to the node

  • cfgblk (String)

    Configuration blocks. Valid values are “running” and “bootup”

Returns:

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

    }



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

Parameters:

  • conn (Class)

    Connect object to the node

  • action (String) (defaults to: "config_save")

    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.
    
  • protocol (String) (defaults to: nil)

    Protocol to communicate which includes “tftp” or “scp” or “http”

  • server_ip (String) (defaults to: nil)

    Server ip address

  • config_file (String) (defaults to: nil)

    Configuration file

  • username (String) (defaults to: nil)

    Username to login the server

  • password (String) (defaults to: nil)

    Password for the server

  • port (Integer) (defaults to: 0)

    TCP port used by file transfer protocol

Returns:

  • (RestClient::Request)

    Rest output from SONIC in JSON format



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