The plugin is invoked by the core component when the core component is used by one of the Pineapple clients. To trigger invocation by the core component the plugin needs to be configured.
Three steps are needed to configure the plugin:
For more info about configuration of plugins:
When the plugin is invoked with an operation (e.g. deploy-configuration) and a module model which defines a list of SSH commands the plugin will iterate over the list and execute them in sequence. The supported commands are:
The purpose of defining a resource for this plugin is twofold:
To define a new resource, add a resource element to the target environment in the configuration file ${pineapple.home.dir}/conf/resources.xml:
<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://pineapple.dev.java.net/ns/environment_1_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <environments> <environment id="local" > <resources> <resource id="vagrant-ssh" credential-id-ref="vagrant-ssh" plugin-id="com.alpha.pineapple.plugin.ssh" /> <property value="127.0.0.1" key="host"/> <property value="2222" key="port"/> <property value="1000" key="timeout"/> </resource> </resources> </environment> </environments> </configuration>
The semantics of the resource element is:
Identifies the resource uniquely in the current environment. This ID is referenced from models which intends to use the plugin.
Id for the credential which is used to lookup user name and password for this resource.
Please notice: The plugin only support authentication using user/password. Authentication using a certificate isn't supported (yet).
A credential defines authentication information used to access a protected resource. The remote host accessed by using SSH is protected by a user-id/password. So a credential needs to be defined.
The credentials are by default defined in the file ${pineapple.home.dir}/conf/credentials.xml.
The credentials file is also defined using the environment configuration schema which defines the http://pineapple.dev.java.net/ns/environment_1_0 namespace. Since credential files only contain elements from a single namespace all the elements and attributes are unqualified. The header and root element should be defined as (look in the Environment configuration document for more details):
<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://pineapple.dev.java.net/ns/environment_1_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
Credentials are grouped by environment the same way as resources are. If the required environment doesn't exists in the credential files, then define it, and add the credential to it.
Add a new environment sub element with the id linux-default to the environments element in the credential file:
<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://pineapple.dev.java.net/ns/environment_1_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <environments> <environment id="local" /> </environments> </configuration>
Add a new credential to the environment:
<?xml version="1.0" encoding="UTF-8"?> <configuration xmlns="http://pineapple.dev.java.net/ns/environment_1_0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <environments> <environment id="local"> <credentials> <credential id="vagrant-ssh" user="vagrant" password="vagrant" /> </credentials> </environment> </environments> </configuration>
The semantics of the credential elements is explained in the next sub sections:
Id of the credential in the current environment.
Notice: The example id vagrant-ssh is referenced from the resource example defined in the previous section.
A module defines the input used by Pineapple to execute operations. A module is defined by a directory layout. Part of a module is the model(s) which defines what happens when the module is invoked. A model is put together by one or more sub models from different plugins. Each plugin defines its own schema for its particular model
This plugin defines a schema named The SSH plugin schema which defines the http://pineapple.dev.java.net/ns/plugin/ssh_1_0 namespace. For more information about where the schema can be found, refer to the Schema locations for plugins page.
The list of SSH commands (e.g. copy-from and execute) which should be executed when the plugin is invoked are defined in the module model files which are located at ${module-dir}/models/${environment}.xml where:
If the model file doesn't exist for an environment where the SSH commands should be run, then create the model file and name it after the target environment, e.g. local.xml for an environment named local.
Module model files are defined using the module model configuration schema which defines the http://pineapple.dev.java.net/ns/module_model_1_0 namespace. Since module model files contain elements from multiple namespace all the elements and attributes should be qualified. The header and root element should be defined as (look in the Modules configuration document for more details):
This example shows definition of the minimal model file for local:
<?xml version="1.0" encoding="UTF-8"?> <mmd:models xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" />
The next step is to include the The SSH plugin schema to get access to the entities defined by the schema:
<?xml version="1.0" encoding="UTF-8"?> <mmd:models xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0" />
Now we have a minimal module model file with three namespaces:
Add a new model with a target-resource attribute. The value of the target-resource should match the id of the resource which was defined previously in the section Define resource, e.g. vagrant-ssh:
<?xml version="1.0" encoding="UTF-8"?> <mmd:models xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0" /> <mmd:model target-resource="vagrant-ssh"> <mmd:content /> </mmd:model> </mmd:models>
Add content to the model which uses the plugin through the vagrant-ssh reference:
<?xml version="1.0" encoding="UTF-8"?> <mmd:models xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0" /> <mmd:model target-resource="vagrant-ssh"> <mmd:content> <shp:ssh> </shp:ssh> </mmd:content> </mmd:model> </mmd:models>
Define a sequence of SSH commands which should be executed when Pineapple is invoked with the model:
<?xml version="1.0" encoding="UTF-8"?> <mmd:models xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:mmd="http://pineapple.dev.java.net/ns/module_model_1_0" xmlns:shp="http://pineapple.dev.java.net/ns/plugin/ssh_1_0" /> <mmd:model target-resource="vagrant-ssh"> <mmd:content> <shp:ssh> <shp:copy-to source="modulepath:bin/apt.conf" destination="/tmp/apt.conf"/> <shp:execute command="sudo cp /tmp/apt.conf /etc/apt/apt.conf.d/99my-apt-conf" /> <shp:execute command="sudo apt-get install unzip" /> <shp:execute command="sudo apt-get install chkconfig" /> <!-- total memory --> <shp:assert-contains command="grep MemTotal /proc/meminfo" expected-value="132154992" /> <!-- kernel swappiness --> <shp:assert-equals command="cat /proc/sys/vm/swappiness" expected-value="0" /> </shp:ssh> </mmd:content> </mmd:model> </mmd:models>
The copy-to command copies a single file from the node where Pineapple is running to a remote host defined in the targeted resource.
The source attribute defines the path on the Pineapple node where the source file canbe found. The command support the usage of the modulepath: prefix in the source attribute which is resolved to the absolute directory where the model is defined.
The destination attribute defines the path on the remote host accessed with SSH where the file should be copied.
The optional chmod attribute defines the file permissions for the remote file. The value is the octal representation of OGW (e.g. owner, group and world).
The optional chown attribute defines the user ownership of the remote file. The value is the identifier (UID) of the new owner.
The optional chgrp attribute defines the the group ownership of the remote file. The value is the identifier (UID) of the new owner.
The optional substitute-variables boolean attribute defines if variable substitution should be peformed on the source file prior to copying it to the remote host. If enabled then Pineapple will validate that the file exists and that it isn't larger than 1 MB which is the default maximum size for files processed in this manner. The restriction is imposed to avoid processing large binary files by accident. The default value is true, e.g. variable substitution is enabled by default.
The execute command execute a single shell command on the remote host defined in the targeted resource.
The command attribute defines the shell command or script to execute. The output of the command in the form of standard out, error out and the shell return code are reported back.
The assert-contains command execute a single shell command on the remote host defined in the targeted resource. The returned output in standard out is then asserted with an expected value. If the output contains the expected value then the test succeeds.
The command attribute defines the shell command or script to execute. The output of the command in the form of standard out, error out and the shell return code are reported back.
The expected-value attribute defines the expected value which must be present in the returned standard out output for the test to succeed.
The assert-equals command execute a single shell command on the remote host defined in the targeted resource. The returned output in standard out is then asserted with an expected value. If the output is equal (e.g. a string comparison) to the expected value then the command succeeds.
The command attribute defines the shell command or script to execute. The output of the command in the form of standard out, error out and the shell return code are reported back.
The expected-value attribute defines the expected value which must be equal to the returned standard out output for the test to succeed.