Class: MCollective::Util::Playbook::Nodes::McollectiveNodes

Inherits:
Object
  • Object
show all
Defined in:
lib/mcollective/util/playbook/nodes/mcollective_nodes.rb

Instance Method Summary collapse

Constructor Details

#initializeMcollectiveNodes

Returns a new instance of McollectiveNodes.



6
7
8
9
10
11
12
13
14
# File 'lib/mcollective/util/playbook/nodes/mcollective_nodes.rb', line 6

def initialize
  @discovery_method = "mc"
  @agents = []
  @facts = []
  @classes = []
  @identity = []
  @federations = []
  @compound = nil
end

Instance Method Details

#client(from_cache: true) ⇒ RPC::Client

Creates and cache an RPC::Client for the configured agent

Parameters:

  • from_cache (Boolean) (defaults to: true)

    when false a new instance is always returned

Returns:



25
26
27
28
29
30
31
# File 'lib/mcollective/util/playbook/nodes/mcollective_nodes.rb', line 25

def client(from_cache: true)
  if from_cache
    @_rpc_client ||= create_and_configure_client
  else
    create_and_configure_client
  end
end

#create_and_configure_clientRPC::Client

TODO:

discovery

Creates a new RPC::Client and configures it with the configured settings

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/mcollective/util/playbook/nodes/mcollective_nodes.rb', line 37

def create_and_configure_client
  client = RPC::Client.new(@agents[0], :configfile => Util.config_file_for_user, :options => Util.default_options)
  client.progress = false
  client.discovery_method = @discovery_method

  @classes.each do |filter|
    client.class_filter(filter)
  end

  @facts.each do |filter|
    client.fact_filter(filter)
  end

  @agents.each do |filter|
    client.agent_filter(filter)
  end

  @identity.each do |filter|
    client.identity_filter(filter)
  end

  client.compound_filter(@compound) if @compound

  client
end

#discoverObject



91
92
93
# File 'lib/mcollective/util/playbook/nodes/mcollective_nodes.rb', line 91

def discover
  client.discover
end

#from_hash(data) ⇒ McollectiveNodes

Initialize the nodes source from a hash

Parameters:

  • data (Hash)

    input data matching nodes.json schema

Returns:



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/mcollective/util/playbook/nodes/mcollective_nodes.rb', line 67

def from_hash(data)
  @config = Config.instance

  # Allow specifying federations at playbook execution time
  if data["federations"]
    if data["federations"].instance_of?(String)
      @config.federations = [data["federations"]]
    else
      @config.federations = data["federations"]
    end
  end

  @discovery_method = data.fetch("discovery_method", "mc")
  @agents = data.fetch("agents", ["rpcutil"])
  @facts = data.fetch("facts", [])
  @classes = data.fetch("classes", [])
  @identity = data.fetch("identities", [])
  @compound = data["compound"]

  @_rpc_client = nil

  self
end

#prepareObject



16
# File 'lib/mcollective/util/playbook/nodes/mcollective_nodes.rb', line 16

def prepare; end

#validate_configuration!Object

TODO:


19
# File 'lib/mcollective/util/playbook/nodes/mcollective_nodes.rb', line 19

def validate_configuration!; end