Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

14945 - Add a datasource to introspect an agent

Add a data plugin that can be used to discover on properties of running
agents.

This will allow for discovery queries like below:

    mco find -S "agent('puppetd').version = 1.6"

The full metadata is available
  • Loading branch information...
commit ba86f7762d53c218b5959b70f845847e89784ad3 1 parent 92cf43f
@ripienaar ripienaar authored
View
22 plugins/mcollective/data/agent_data.ddl
@@ -0,0 +1,22 @@
+metadata :name => "Agent",
+ :description => "Meta data about installed MColletive Agents",
+ :author => "R.I.Pienaar <rip@devco.net>",
+ :license => "ASL 2.0",
+ :version => "1.0",
+ :url => "http://marionette-collective.org/",
+ :timeout => 1
+
+dataquery :description => "Agent Meta Data" do
+ input :query,
+ :prompt => "Agent Name",
+ :description => "Valid agent name",
+ :type => :string,
+ :validation => /^[\w\_]+$/,
+ :maxlength => 20
+
+ [:license, :timeout, :description, :url, :version, :author].each do |item|
+ output item,
+ :description => "Agent #{item}",
+ :display_as => item.to_s.capitalize
+ end
+end
View
17 plugins/mcollective/data/agent_data.rb
@@ -0,0 +1,17 @@
+module MCollective
+ module Data
+ class Agent_data<Base
+ query do |plugin|
+ raise "No agent called #{plugin} found" unless PluginManager.include?("#{plugin}_agent")
+
+ agent = PluginManager["#{plugin}_agent"]
+
+ result[:agent] = plugin
+
+ [:license, :timeout, :description, :url, :version, :author].each do |item|
+ result[item] = agent.meta[item]
+ end
+ end
+ end
+ end
+end
View
43 spec/unit/plugins/mcollective/data/agent_data_spec.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/env rspec
+
+require 'spec_helper'
+
+require File.dirname(__FILE__) + "/../../../../../plugins/mcollective/data/agent_data.rb"
+
+module MCollective
+ module Data
+ describe Agent_data do
+ describe "#query_data" do
+ before do
+ @ddl = mock
+ @ddl.stubs(:meta).returns({:timeout => 1})
+ DDL.stubs(:new).returns(@ddl)
+ @plugin = Agent_data.new
+ end
+
+ it "should fail for unknown agents" do
+ expect { @plugin.query_data("rspec") }.to raise_error("No agent called rspec found")
+ end
+
+ it "should retrieve the correct agent and data" do
+ agent = mock
+ agent.stubs(:meta).returns({:license => "license",
+ :timeout => "timeout",
+ :description => "description",
+ :url => "url",
+ :version => "version",
+ :author => "author"})
+
+ PluginManager.stubs(:[]).with("rspec_agent").returns(agent)
+ PluginManager.expects(:include?).with("rspec_agent").returns(true)
+
+ @plugin.query_data("rspec")
+
+ [:license, :timeout, :description, :url, :version, :author].each do |item|
+ @plugin.result[item].should == item.to_s
+ end
+ end
+ end
+ end
+ end
+end
View
2  spec/unit/plugins/mcollective/data/fstat_data_spec.rb
@@ -12,7 +12,7 @@ module Data
@ddl = mock
@ddl.stubs(:meta).returns({:timeout => 1})
DDL.stubs(:new).returns(@ddl)
- @plugin = MCollective::Data::Fstat_data.new
+ @plugin = Fstat_data.new
@time = Time.now
View
2  website/changelog.md
@@ -8,6 +8,8 @@ toc: false
|Date|Description|Ticket|
|----|-----------|------|
+|2012/06/11|Add a discovery source capable of doing introspection on running agents|14945|
+|2012/06/11|Only do identity filter optimisations for the *mc* discovery source|14942|
|*2012/06/08*|*Release 2.1.0*|14846|
|2012/06/07|Force discovery state to be reset when changing collectives in the RPC client|14874|
|2012/06/07|Create code generators for agents and data plugins|14717|

0 comments on commit ba86f77

Please sign in to comment.
Something went wrong with that request. Please try again.