Class: Arista::EAPI::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/arista/eapi/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(switch, commands, options = {}) ⇒ Request

Returns a new instance of Request.



6
7
8
9
10
11
12
# File 'lib/arista/eapi/request.rb', line 6

def initialize(switch, commands, options = {})
  options[:format] ||= 'json'

  self.switch = switch
  self.commands = commands
  self.options = options
end

Instance Attribute Details

#commandsObject

Returns the value of attribute commands.



4
5
6
# File 'lib/arista/eapi/request.rb', line 4

def commands
  @commands
end

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/arista/eapi/request.rb', line 4

def options
  @options
end

#switchObject

Returns the value of attribute switch.



4
5
6
# File 'lib/arista/eapi/request.rb', line 4

def switch
  @switch
end

Instance Method Details

#executeObject



27
28
29
# File 'lib/arista/eapi/request.rb', line 27

def execute
  Arista::EAPI::Response.new(commands, RestClient.post(switch.url, payload))
end

#payloadObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/arista/eapi/request.rb', line 14

def payload
  @payload ||= JSON.generate({
    :jsonrpc => '2.0',
    :method  => 'runCmds',
    :id      => 1,
    :params  => {
      :version => 1,
      :cmds    => commands,
      :format  => options[:format]
    },
  })
end