Up to MCollective 2.0 the discovery system could only discover against installed agents, configuration management classes or facts and the node identities. We’re extending this to support discovery against many sources through a simple plugin system.
NOTE: This feature is available since version 2.1.0
The basic idea is that you could do discovery statements like the ones below:
You could also use these data sources in your own agents or other plugins:
NOTE: As opposed to the DiscoveryPlugins which are used by the client to communicate to the nodes using direct addressing, data plugins on the other hand refer to data that the nodes can provide, and hence this uses the normal broadcast discovery paradigm.
These new data sources are plugins so you can provide via the plugin system and they require DDL documents. The DDL will be used on both the client and the server to provide strict validation and configuration.
The DDL for these plugins will affect the client libraries in the following ways:
On the servers the DDL will:
You can view the output from a data plugin using the rpcutil agent:
The same action can be used to retrieve data programatically.
The data plugins should not change the system in anyway, you should take care to create plugins that only reads the state of the system. If you want to affect the status of the system you should write Agents.
These plugins are kept simple as they will be typed on the command line so the following restrictions are present:
Writing data plugins is easy and mimic the basics of writing agents, below we have a simple sysctl plugin that was used in the examples earlier:
The class names have to be Something_data and they must inherit from Base as in the example here. The file would be saved in the libdir as data/sysctl_data.rb and data/sysctl_data.ddl.
This plugin will only be activated if the file /sbin/sysctl exist, is executable and if the system is a Linux server. This allow us to install it on a Windows machine where it will just be disabled and those machines will never be discovered using this function.
We then create a block that would be the main body of the query. We use the MCollective::Shell class to run sysctl, parse the output and save it into the result hash.
The result hash is the only way to return values from these plugins. You can only save simple strings, numbers or booleans in the result.
As mentioned every data plugin requires a DDL. These DDL files mimic those of the SimpleRPC Agents.
Below you’ll find a DDL for the above sysctl data plugin:
The timeout must be set correctly, if your data source is slow you need to reflect that in the timeout here. The timeout will be used on the clients to decide how long to wait for discovery responses from the network so getting this wrong will result in nodes not being discovered.
Each data plugin can only have one dataquery block with exactly 1 input block but could have multiple output blocks.
It’s important to get the validation correct, here we only accept the characters we know are legal in sysctl variables on Linux. We will specifically never allow backticks to be used in arguments to avoid accidental shell exploits.
Note the correlation between output names and the use in discovery and agents here we create an output called value this means we would use it in discovery as:
And we would output the result from our plugin code as:
And in any agent where we might use the data source:
These have to match everywhere, you cannot reference undeclared data and you cannot use input that does not validate against the DDL declared validations.
Refer to the full DDL documentation for details on all possible values of the metadata, input and output blocks.
As with agents the DDL can be used to generate documentation, if you wanted to know what the input and output values are for a specific plugin you can use mco plugin doc to see generated documentation.
application to see remotely what plugins a node has available: