class System

The System class provides a class implementation and methods for managing and setting up system configuration and images. This class presents an abstraction

Public Class Methods

download_system_img(conn, image_url) click to toggle source

This API download and install system image

Request URL: IP-ADDR:REST-PORT/api/devices

payload format of key-value pairs
     {
      "image_url": "image_url"
     }

@param conn [Class] Connect object to the node @param image_url [String] URL to download system image from remote Web server (http ot https)

@return [RestClient::Request] Rest output from SONIC in JSON format

# File lib/sonic-rbapi/system.rb, line 92
def self.download_system_img(conn, image_url)
  url = form_url(conn, @system_cfg)
  hdr = form_hdr(conn)
  params = {"image_url": image_url}
  params = params.to_json
  Rest.post(conn, url, hdr, params)
end
get_system_data(conn) click to toggle source

This API gets the system meta data parameters

Request URL: IP-ADDR:REST-PORT/api/devices

@param conn [Class] Connect object to the node

@return [RestClient::Request] Rest output from SONIC in JSON format as below

{
 "mac": "b4:8c:db:b9:a0:00",
 "hwsku": "YYY",
 "hostname": "<string>",
 "platform": "x86_64",
 "version": <sonic-version>,
 "ASIC": <asic-type>
 "type": "LeafRouter"
 ...
}
# File lib/sonic-rbapi/system.rb, line 42
def self.get_system_data(conn)
  url = form_url(conn, @system_cfg)
  hdr = form_hdr(conn)
  Rest.get(conn, url, hdr)
end
update_system_data(conn, mac_addr=nil, hostname=nil) click to toggle source

This API updates system mac_addr and hostname

Request URL: IP-ADDR:REST-PORT/api/devices

payload format of key-value pairs
     {
      "mac_addr": "00:01:02:03:04:05",
      "hostname": "hostname"
     }

@param conn [Class] Connect object to the node @param mac_addr [String] Base MAC address of the system @param hostname [String] Hostname of the system

@return [RestClient::Request] Rest output from SONIC in JSON format

# File lib/sonic-rbapi/system.rb, line 62
def self.update_system_data(conn, mac_addr=nil, hostname=nil)
  url = form_url(conn, @system_cfg)
  hdr = form_hdr(conn)
  if mac_addr != nil
    params = {"mac_addr": mac_addr}
  end
  if hostname != nil
    p1 =  {"hostname": hostname}
    if mac_addr != nil
      params = params.merge(p1)
    else
      params = p1
    end
  end
  params = params.to_json
  Rest.put(conn, url, hdr, params)
end