Method: Rbeapi::Client::Node#enable
- Defined in:
- lib/rbeapi/client.rb
#enable(commands, opts = {}) ⇒ Array<Hash>
The enable method is a convenience method that will handling putting the switch into privilege mode prior to executing commands.
rubocop:disable Metrics/MethodLength
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/rbeapi/client.rb', line 402 def enable(commands, opts = {}) commands = [*commands] unless commands.respond_to?('each') encoding = opts.fetch(:encoding, 'json') opts[:encoding] = encoding strict = opts.fetch(:strict, false) results = [] if strict responses = run_commands(commands, opts) responses.each_with_index do |resp, idx| results << make_response(commands[idx], resp, encoding) end else commands.each do |cmd| begin response = run_commands(cmd, opts) results << make_response(cmd, response.first, encoding) rescue Rbeapi::Eapilib::CommandError => exc raise unless exc.error_code == 1003 opts[:encoding] = 'text' response = run_commands(cmd, opts) results << make_response(cmd, response.first, encoding) end end end results end |