Class: System

Inherits:
Object
  • Object
show all
Defined in:
lib/sonic-rbapi/system.rb

Overview

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

Class Method Summary collapse

Class Method Details

.download_system_img(conn, image_url) ⇒ RestClient::Request

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

Parameters:

  • conn (Class)

    Connect object to the node

  • image_url (String)

    URL to download system image from remote Web server (http ot https)

Returns:

  • (RestClient::Request)

    Rest output from SONIC in JSON format



92
93
94
95
96
97
98
# 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) ⇒ RestClient::Request

This API gets the system meta data parameters

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

Parameters:

  • conn (Class)

    Connect object to the node

Returns:

  • (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"
    ...
    



42
43
44
45
46
# 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) ⇒ RestClient::Request

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

Parameters:

  • conn (Class)

    Connect object to the node

  • mac_addr (String) (defaults to: nil)

    Base MAC address of the system

  • hostname (String) (defaults to: nil)

    Hostname of the system

Returns:

  • (RestClient::Request)

    Rest output from SONIC in JSON format



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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