Execute arbitrary code. Specify a list of resources, such as scripts, binaries, dependencies in a single node template. The root script file exec will contain all of your instructions.
Example Node Template
application:
type: cloudify.nodes.Execution
properties:
resource_config:
resource_list:
- resources/exec
- resources/my_binary
- resources/data.json
relationships:
- type: cloudify.relationships.contained_in
target: host
Example Exec Script
#!/bin/bash
# content of resources/exec
source ./my_file
./my_binary -arg my_file <$(cat ./data.json)
What happens
The plugin creates a temporary directory. It copies all of the files to it.
It will then execute the exec file relative to the temporary directory.
Note: By default the plugin looks to execute a file named exec in the temporary directory. This may be overridden.
- Cloudify Manager, 3.4.2+.
- You need a minimal VM. Any node type derived from
cloudify.nodes.Computewill do.
There is only one task defined in the plugin execute. This function wraps a subprocess.Popen constructor.
cloudify.interfaces.lifecycle.createimplementation: exec.exec_plugin.tasks.execute
The create operation can be remapped to other lifecycle interface operations, such as start or stop, etc.
Other subprocess.Popen features can be via inputs, for example add environment variables:
application:
type: cloudify.nodes.Execution
properties:
resource_config:
resource_list:
- resources/exec
- resources/install.sh
- resources/uninstall.sh
relationships:
- type: cloudify.relationships.contained_in
target: host
interfaces:
cloudify.interfaces.lifecycle:
create:
implementation: exec.exec_plugin.tasks.execute
inputs:
resource_config: { get_property: [ SELF, resource_config ] }
subprocess_args_overrides:
env:
JOB: 'install'
delete:
implementation: exec.exec_plugin.tasks.execute
inputs:
resource_config: { get_property: [ SELF, resource_config ] }
subprocess_args_overrides:
env:
JOB: 'uninstall'You can call different scripts from different lifecycle operations in the main exec file by adding conditional bash logic:
if [[ "$JOB" == "install" ]]
then
chmod 755 install.sh
./install.sh
elif [[ "$JOB" == "uninstall" ]]
then
chmod 755 uninstall.sh
./uninstall.sh
fi
Relative to your blueprint, create some folder with a file in it named exec.
#!/bin/bash
# content of resources/hello_world/exec
echo "hello world"Next write a blueprint.
The Cloudify Agent on some VM will execute your code. Here is an example VM.
host:
type: cloudify.nodes.Compute
properties:
ip: { get_input: host_ip }
agent_config:
install_method: remote
port: 22
user: { get_input: username }
key: { get_secret: agent_key_private }
Create a execution node template in your blueprint such as this:
application:
type: cloudify.nodes.Execution
properties:
resource_config:
resource_list:
- resources/hello_world/exec
relationships:
- type: cloudify.relationships.contained_in
target: host
See below for blueprint installation instructions.
This example shows another use case: executing an Ansible workflow.
The blueprint uses the following files:
exec, which contains the core instructions.helloworld.yaml, which is an Ansible Playbook.hosts.tmp, which is the Ansible Inventory file.
The blueprint itself includes the files:
application:
type: cloudify.nodes.Execution
properties:
resource_config:
resource_list:
- resources/ansible/exec
- resources/ansible/helloworld.yml
- resources/ansible/hosts.tmp
relationships:
- type: cloudify.relationships.contained_in
target: hostYou need your Cloudify Manager, with a secret for agent_key_private IP of a Ubuntu 14.04 VM to run this example. Use the instructions in the next step.
$ cfy blueprints upload examples/blueprint.yaml -b experiment-no-01
$ cfy deployments create --skip-plugins-validation -i host_ip=192.168.120.11 -b experiment-no-01
$ cfy executions start install -vv -d experiment-no-01
$ cfy executions start uninstall -vv -d experiment-no-01If you have a Kubernetes Cluster with Helm and Tiller running, you can install ONAP using the Helm files in resources/helm.
For official blueprint examples using this Cloudify plugin, please see Cloudify Community Blueprints Examples.