Repository navigation
Writing a Cloudify Plugin
Let's create a Cloudify Plugin.
The simplest incarnation of a plugin has two components: an operation in a python script, and a blueprint.
With that in mind, let's create an operation that does nothing:
def do_nothing(**kwargs):
pass
Save that in a file called 'tasks.py' in a folder called 'nothing_plugin'.
Let's say that you want to run this script on the manager every time you run a deployment. Let's create a node type:
node_type:
cloudify.nothing_plugin.instance
derived_from: cloudify.nodes.ApplicationModule
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: nothing_package.nothing_plugin.tasks.do_nothing
Now at the top of that file add:
tosca_definitions_version: cloudify_dsl_1_0
plugins:
cloudify-plugin:
executor: central_deployment_agent
source: https://github.com/your-git-user/nothing_package/archive/master.zip
Save the file as 'plugin.yaml'.
Now let's create a package for this plugin. You can use the template: [https://github.com/cloudify-cosmo/cloudify-plugin-template](A Cloudify Plugin Template).
Or just make sure that you have a folder, let's call it 'nothing_package', with the following files:
./nothing_package/
./nothing_package/setup.py
./nothing_package/plugin.yaml
./nothing_package/nothing_plugin/
./nothing_package/nothing_plugin/tasks.py
Make sure that at least the following is in your setup.py file:
setup(
name='nothing_package',
description='does nothing',
packages=['nothing_plugin'],
install_requires=["cloudify-plugins-common"]
)
Now you have your plugin. Once you upload it to github, All you need to do is implement it.
If you have a manager up and running, create a new directory, and add a new file called 'blueprint.yaml'.
In the file, add the following:
tosca_definitions_version: cloudify_dsl_1_0
imports:
- http://www.getcloudify.org/spec/cloudify/3.1/types.yaml
- https://raw.githubusercontent.com/your-git-hub-user/nothing_package/master/plugin.yaml
node_templates:
dont_do_anything:
type: cloudify.nothing_plugin.instance
interfaces:
cloudify.interfaces.lifecycle:
start:
implementation: nothing_package.nothing_plugin.tasks.do_nothing
At this point the only thing left to do is run it! (On how to do that see the documentation on running uploading blueprints and creating deployments.
There is a lot of quality information scattered across the web on how to write a Cloudify Plugin. Writing a Cloudify Plugin is simple, if you know where to start. Here are some of the top places to look:
[http://getcloudify.org/guide/3.1/guide-plugin-creation.html](Plugin Authoring Guide)
[https://github.com/cloudify-cosmo/cloudify-plugin-template](A Cloudify Plugin Template)
A good example of a plugin is the script plugin, which enables you to run shell scripts.
[http://getcloudify.org/guide/3.1/plugin-script.html](Script Plugin Documentation)
[https://github.com/cloudify-cosmo/cloudify-script-plugin](Script Plugin)