Plugin File Structure
Version 4 (Anil Gulecha, 01/04/2011 03:03 am)
Plugin File Structure
We will take a look at how a plugin is organized, and what files consist a plugin.
NexentaStor plugins are a collection of debian packages. Typically, a plugin can consist of any plugin that extends the three components of the Nexenta Appliance, namely: **nms** (Nexenta Management Service), **nmc** (Nexenta Management Console), **nmv** (Nexenta Management View).
The best way to write a plugin is to simply use one of the multiple open plugins as reference to write up an empty plugin with all the initial bits in place. Let's the the following two example plugins and discuss their structure to help understand the purpose of various files : *ddclient* and *simple-encryption*.
## Package Example: ddclient ##
This image shows the file structure of the ddclient package. You can download this package offline via the commands listed on the [repository page](http://www.nexentastor.org/projects/ddclient/repository).
The main package directory nmc-ddcleint forms all of plugin, i.e, the plugin only has the nmc component. This folder has another directory (*debian*) and 2 perl modules (*Ddclient.pm*, *metafile.pm*)
* *<ins>Ddclient.pm</ins>* - This is the main plugin module, that provides the functionality required. In this particular case, the plugin is basically a wrapper over underlying ddclient facilities. We will go into a line by line explanation later on.
* *<ins>metafile.pm</ins>* - This module is included in all plugin packages. This includes basic plugin information like name, description, plugin group, etc. We will go into a line by line explanation later on.
* *<ins>debian/</ins>* - This directory is present in any debian package, and contains package meta-information (name, dependencies), and build rules (like a Makefile) that builds the packages. This folder can also optionally contain post/pre install/removal scripts if required by your plugin package.
* *<ins>debian/control</ins>* - This file lays out the information official package name, version, dependencies. In this case the package ddclient (which provides the functionality to sync your IP address with dyndns.org and other services) is listed as a dependency.
* *<ins>debian/changelog</ins>* - This is a plain text changelog that maintains a log of what changes were made subsequent versions. An entry is to be added manually for every version of the package released. The 'dch' command makes it easy to edit this file, and maintain the syntax required.
* *<ins>debian/rules</ins>* - This is the main build file. It is a Makefile that lays out the targets *clean*, *deploy-dirs*, *binary-arch* and *binary*. These respectively clean the workspace, install files in temporary directory structure, builds the binary debian package respectively.
* *<ins>debian/copyright</ins>* - This file includes the licensing information about the package.
## Package Example: simple-encryption ##
The simple-encryption plugin is a slightly more complicated plugin than ddclient. It consists of two packages, one each for nmc and nms. The directory contents is shown below.
At the top level are the two package directories: *<ins>nmc-simple-encryption</ins>* and *<ins>nms-simple-encryption</ins>*. We will discuss the new files seen here, and skip what we discussed with the ddclient package.
* *<ins>debian/compat</ins>* - This is an optional file that specifies debhelper compatibility. In all probability you will not have to use this.
* *<ins>nmc-simple-encryption/SimpleEncryption.pm</ins>* - This is the nmc module. When installed, it is loaded by the NexentaStor plugin system, which links the functionality provided into nmc.
* *<ins>nms-simple-encryption/SimpleEncryption.pm</ins>* - This is the nms modules. When installed, it is loaded by the NexentaStor plugin system, which links the functionality provided into nms.