Skip to main content

py-mco-agent

Overview

py-mco-agent contains a collection of tools for writing mcollective agents in the Python language.

Installation

pip install py-mco-agent

This library requires a version of Choria with external agent support.

Implementing Agents

The bare minimum steps to implement a python mcollective agent are:

  • Add a python file without a .py extension to /opt/puppetlabs/mcollective/plugins/mcollective/agent/parrot
#!/usr/bin/python3
from choria_external.dispatcher import dispatch
from mco_agent import Agent, action, register_actions

# Subclass Agent and decorate it with the @register_actions
@register_actions
class Parrot(Agent):

    # Create a class method for your action and decorate it with @action
    @action
    def echo(self):
        # This example action just repeats the message input back to the caller
        prefix = self.config.get('prefix', '')
        if not prefix:
            self.logger.warning("Using default prefix!")
        self.reply.data['message'] = prefix + self.request.data['message']

if __name__ == '__main__':
    dispatch(Parrot)
  • Add a choria JSON DDL file to the same location named parrot.json (see examples/agent/parrot.json)

Reference

Agent

Provides a base class for implementing mcollective agents

Public methods:

  • should_activate Returns a boolean value to indicate whether the agent should be activated on this host. By default returns True and the agent is always activated. Subclasses may choose to override this method and deactivate themselves under appropriate conditions such as missing pre-requisites.

Decorators:

  • @action Instance methods should be decorated with the @action decorator to register them as available agent actions
  • @register_actions The plugin class should be decorated with this method to trigger registration all action methods within

Instance variables:

  • logger Contains a python logger which can be used to send log information back to choria (debug and info are sent to stdout, which is only displayed in verbose mode; warnings and errors are sent to stderr which are displayed always). The logger is set to use the mcorpc.agent_name hierarchy. By default all other logging is disabled to prevent pollution of the mcorpc reply. This is done by setting the log level on the root logger to 100. You can re-enable logging by adjusting the log-level on either the root logger or a specific child if required.
  • config Contains a dict-like object which can be used to read configuration settings from the agent's choria plugin configuration file (/etc/puppetlabs/mcollective/plugin.d/agentname.cfg by default).

Metadata

Release files for py-mco-agent 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-mco-agent 0.4.0
File Size Uploaded Provenance Actions
py-mco-agent-0.4.0.tar.gz 5.1 kB Without provenance Details for py-mco-agent-0.4.0.tar.gz

Release files / py-mco-agent-0.4.0.tar.gz

Download URL py-mco-agent-0.4.0.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
79138e89e33f4f950e70b7f7e183515793e67f62cefc6daa0c8e9dd685536854
BLAKE2b-256 checksum
How to use checksums
7b76d778546c3ab90446137cf2481641c175686de35ee59436efdf8d25a34d7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.8

Security for py-mco-agent 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page