Class: PuppetX::Eos::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/eos/modules/daemon.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ PuppetX::Eos::Daemon

Initializes a new instance of Daemon.



51
52
53
# File 'lib/puppet_x/eos/modules/daemon.rb', line 51

def initialize(api)
  @api = api
end

Instance Method Details

#create(name, command) ⇒ Boolean

Configures a new daemon agent in EOS using eAPI



91
92
93
94
# 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) ⇒ Boolean

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



104
105
106
# File 'lib/puppet_x/eos/modules/daemon.rb', line 104

def delete(name)
  @api.config("no daemon #{name}") == [{}]
end

#getallHash<String, String>

Returns a hash of configured daemons from the running config

Example

{
  "agent": "command"
}


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