Class: PuppetWebhook::Mcollective

Inherits:
Object
  • Object
show all
Includes:
MCollective::RPC
Defined in:
lib/plugins/mcollective.rb

Overview

Creates an Mcollective Agent object for running MCO agents

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent, command, timeouts = nil, options = nil, nodes = [], **args) ⇒ Mcollective

rubocop:disable Metrics/ParameterLists



9
10
11
12
13
14
15
16
17
# File 'lib/plugins/mcollective.rb', line 9

def initialize(agent, command, timeouts = nil, options = nil, nodes = [], **args) # rubocop:disable Metrics/ParameterLists
  @agent = agent
  @command = command
  @timeout = timeouts[:timeout] || '120'
  @dtimeout = timeouts[:dtimeout] || '10'
  @options = options
  @nodes = nodes
  @args = args
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



6
7
8
# File 'lib/plugins/mcollective.rb', line 6

def results
  @results
end

#statsObject (readonly)

Returns the value of attribute stats.



6
7
8
# File 'lib/plugins/mcollective.rb', line 6

def stats
  @stats
end

Instance Method Details

#clientObject



31
32
33
34
35
36
37
38
# File 'lib/plugins/mcollective.rb', line 31

def client
  client = MCollective::RPC::Client.new(@agent, config_file: MCollective::Util.config_file_for_user, options: MCollective::Util.default_options) # rubocop:disable Metrics/LineLength
  client.config = @options if @options
  client.timeout = @timeout if @timeout
  client.discovery_timeout = @dtimeout if @dtimeout
  client.progress = false
  client
end

#runObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/plugins/mcollective.rb', line 19

def run
  LOGGER.info("Starting request for #{@agent}##{@command}")

  begin
    @results = client.send(@command, @args)
  rescue StandardError => e
    LOGGER.error("Error: #{e}")
  end

  @stats = client.stats
end