class PuppetX::Eos::Daemon

The Daemon class provides management of daemons using EOS CLI commands over eAPI. This class provides method for creating and deleting daemons

Public Class Methods

new(api) click to toggle source

Initializes a new instance of Daemon.

@param [PuppetX::Eos::Eapi] api An instance of Eapi

@return [PuppetX::Eos::Daemon] instance

# File lib/puppet_x/eos/modules/daemon.rb, line 51
def initialize(api)
  @api = api
end

Public Instance Methods

create(name, command) click to toggle source

Configures a new daemon agent in EOS using eAPI

@param [String] name The name of the daemon agent @param [String] command The path to the daemon executable

@return [Boolean] True if the commands succeed otherwise False

# File lib/puppet_x/eos/modules/daemon.rb, line 91
def create(name, command)
  return false unless File.executable?(command)
  @api.config(["daemon #{name}", "command #{command}"]) == [{}, {}]
end
delete(name) click to toggle source

Deletes a previously configured daemon from the running-configuration in EOS using eAPI

@param [String] name The name of the agent to delete

@return [Boolean] True if the operation was successful otherwise

False
# File lib/puppet_x/eos/modules/daemon.rb, line 104
def delete(name)
  @api.config("no daemon #{name}") == [{}]
end
getall() click to toggle source

Returns a hash of configured daemons from the running config

Example

{
  "agent": "command"
}

@return [Hash<String, String>] Hash of configured agents

# File lib/puppet_x/eos/modules/daemon.rb, line 64
def getall
  result = @api.enable('show running-config section daemon',
                       format: 'text')
  response = {}
  key = nil
  result.first['output'].split("\n").each do |entry|
    token = entry.strip.match(/^daemon\s(?<name>.*)$/)
    unless token.nil?
      key = token['name']
      response[key] = nil
    end
    token = entry.strip.match(/^command\s(?<command>.*)$/)
    unless token.nil?
      value = token['command']
      response[key] = value
    end
  end
  response
end