| Dean Troyer | 0986a7b | 2014-10-29 22:08:13 -0500 | [diff] [blame] | 1 | ======= | 
|  | 2 | Plugins | 
|  | 3 | ======= | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 4 |  | 
|  | 5 | DevStack has a couple of plugin mechanisms to allow easily adding | 
|  | 6 | support for additional projects and features. | 
|  | 7 |  | 
|  | 8 | Extras.d Hooks | 
| Sean Dague | 3293046 | 2014-11-18 06:51:16 -0500 | [diff] [blame] | 9 | ============== | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 10 |  | 
| Dean Troyer | ea3cdfa | 2014-11-08 08:29:16 -0600 | [diff] [blame] | 11 | These hooks are an extension of the service calls in | 
|  | 12 | ``stack.sh`` at specific points in its run, plus ``unstack.sh`` and | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 13 | ``clean.sh``. A number of the higher-layer projects are implemented in | 
|  | 14 | DevStack using this mechanism. | 
|  | 15 |  | 
|  | 16 | The script in ``extras.d`` is expected to be mostly a dispatcher to | 
|  | 17 | functions in a ``lib/*`` script. The scripts are named with a | 
|  | 18 | zero-padded two digits sequence number prefix to control the order that | 
| YAMAMOTO Takashi | b1a153e | 2015-02-09 12:43:12 +0900 | [diff] [blame] | 19 | the scripts are called, and with a suffix of ``.sh``. DevStack reserves | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 20 | for itself the sequence numbers 00 through 09 and 90 through 99. | 
|  | 21 |  | 
|  | 22 | Below is a template that shows handlers for the possible command-line | 
|  | 23 | arguments: | 
|  | 24 |  | 
|  | 25 | :: | 
|  | 26 |  | 
|  | 27 | # template.sh - DevStack extras.d dispatch script template | 
|  | 28 |  | 
|  | 29 | # check for service enabled | 
|  | 30 | if is_service_enabled template; then | 
|  | 31 |  | 
|  | 32 | if [[ "$1" == "source" ]]; then | 
|  | 33 | # Initial source of lib script | 
|  | 34 | source $TOP_DIR/lib/template | 
|  | 35 | fi | 
|  | 36 |  | 
|  | 37 | if [[ "$1" == "stack" && "$2" == "pre-install" ]]; then | 
|  | 38 | # Set up system services | 
|  | 39 | echo_summary "Configuring system services Template" | 
|  | 40 | install_package cowsay | 
|  | 41 |  | 
|  | 42 | elif [[ "$1" == "stack" && "$2" == "install" ]]; then | 
|  | 43 | # Perform installation of service source | 
|  | 44 | echo_summary "Installing Template" | 
|  | 45 | install_template | 
|  | 46 |  | 
|  | 47 | elif [[ "$1" == "stack" && "$2" == "post-config" ]]; then | 
|  | 48 | # Configure after the other layer 1 and 2 services have been configured | 
|  | 49 | echo_summary "Configuring Template" | 
|  | 50 | configure_template | 
|  | 51 |  | 
|  | 52 | elif [[ "$1" == "stack" && "$2" == "extra" ]]; then | 
|  | 53 | # Initialize and start the template service | 
|  | 54 | echo_summary "Initializing Template" | 
|  | 55 | ##init_template | 
|  | 56 | fi | 
|  | 57 |  | 
|  | 58 | if [[ "$1" == "unstack" ]]; then | 
|  | 59 | # Shut down template services | 
|  | 60 | # no-op | 
|  | 61 | : | 
|  | 62 | fi | 
|  | 63 |  | 
|  | 64 | if [[ "$1" == "clean" ]]; then | 
|  | 65 | # Remove state and transient data | 
|  | 66 | # Remember clean.sh first calls unstack.sh | 
|  | 67 | # no-op | 
|  | 68 | : | 
|  | 69 | fi | 
|  | 70 | fi | 
|  | 71 |  | 
|  | 72 | The arguments are: | 
|  | 73 |  | 
|  | 74 | -  **source** - Called by each script that utilizes ``extras.d`` hooks; | 
|  | 75 | this replaces directly sourcing the ``lib/*`` script. | 
|  | 76 | -  **stack** - Called by ``stack.sh`` three times for different phases | 
|  | 77 | of its run: | 
|  | 78 |  | 
|  | 79 | -  **pre-install** - Called after system (OS) setup is complete and | 
|  | 80 | before project source is installed. | 
|  | 81 | -  **install** - Called after the layer 1 and 2 projects source and | 
|  | 82 | their dependencies have been installed. | 
|  | 83 | -  **post-config** - Called after the layer 1 and 2 services have | 
|  | 84 | been configured. All configuration files for enabled services | 
|  | 85 | should exist at this point. | 
|  | 86 | -  **extra** - Called near the end after layer 1 and 2 services have | 
|  | 87 | been started. This is the existing hook and has not otherwise | 
|  | 88 | changed. | 
|  | 89 |  | 
|  | 90 | -  **unstack** - Called by ``unstack.sh`` before other services are shut | 
|  | 91 | down. | 
|  | 92 | -  **clean** - Called by ``clean.sh`` before other services are cleaned, | 
|  | 93 | but after ``unstack.sh`` has been called. | 
|  | 94 |  | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 95 |  | 
|  | 96 | Externally Hosted Plugins | 
|  | 97 | ========================= | 
|  | 98 |  | 
|  | 99 | Based on the extras.d hooks, DevStack supports a standard mechansim | 
|  | 100 | for including plugins from external repositories. The plugin interface | 
|  | 101 | assumes the following: | 
|  | 102 |  | 
|  | 103 | An external git repository that includes a ``devstack/`` top level | 
|  | 104 | directory. Inside this directory there can be 2 files. | 
|  | 105 |  | 
|  | 106 | - ``settings`` - a file containing global variables that will be | 
|  | 107 | sourced very early in the process. This is helpful if other plugins | 
|  | 108 | might depend on this one, and need access to global variables to do | 
|  | 109 | their work. | 
| Sean Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 110 |  | 
|  | 111 | Your settings should include any ``enable_service`` lines required | 
|  | 112 | by your plugin. This is especially important if you are kicking off | 
|  | 113 | services using ``run_process`` as it only works with enabled | 
|  | 114 | services. | 
|  | 115 |  | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 116 | - ``plugin.sh`` - the actual plugin. It will be executed by devstack | 
|  | 117 | during it's run. The run order will be done in the registration | 
|  | 118 | order for these plugins, and will occur immediately after all in | 
|  | 119 | tree extras.d dispatch at the phase in question.  The plugin.sh | 
| Sean Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 120 | looks like the extras.d dispatcher above. | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 121 |  | 
|  | 122 | Plugins are registered by adding the following to the localrc section | 
|  | 123 | of ``local.conf``. | 
|  | 124 |  | 
|  | 125 | They are added in the following format:: | 
|  | 126 |  | 
| Sean Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 127 | [[local|localrc]] | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 128 | enable_plugin <NAME> <GITURL> [GITREF] | 
|  | 129 |  | 
|  | 130 | - ``name`` - an arbitrary name. (ex: glustfs, docker, zaqar, congress) | 
|  | 131 | - ``giturl`` - a valid git url that can be cloned | 
|  | 132 | - ``gitref`` - an optional git ref (branch / ref / tag) that will be | 
|  | 133 | cloned. Defaults to master. | 
|  | 134 |  | 
|  | 135 | An example would be as follows:: | 
|  | 136 |  | 
| Sean Dague | 33127a1 | 2015-02-09 15:17:27 -0500 | [diff] [blame] | 137 | enable_plugin ec2api git://git.openstack.org/stackforge/ec2api | 
| Sean Dague | 2c65e71 | 2014-12-18 09:44:56 -0500 | [diff] [blame] | 138 |  | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 139 | Hypervisor | 
| Sean Dague | 3293046 | 2014-11-18 06:51:16 -0500 | [diff] [blame] | 140 | ========== | 
| Sean M. Collins | 09e550c | 2014-10-21 11:40:08 -0400 | [diff] [blame] | 141 |  | 
|  | 142 | Hypervisor plugins are fairly new and condense most hypervisor | 
|  | 143 | configuration into one place. | 
|  | 144 |  | 
|  | 145 | The initial plugin implemented was for Docker support and is a useful | 
|  | 146 | template for the required support. Plugins are placed in | 
|  | 147 | ``lib/nova_plugins`` and named ``hypervisor-<name>`` where ``<name>`` is | 
|  | 148 | the value of ``VIRT_DRIVER``. Plugins must define the following | 
|  | 149 | functions: | 
|  | 150 |  | 
|  | 151 | -  ``install_nova_hypervisor`` - install any external requirements | 
|  | 152 | -  ``configure_nova_hypervisor`` - make configuration changes, including | 
|  | 153 | those to other services | 
|  | 154 | -  ``start_nova_hypervisor`` - start any external services | 
|  | 155 | -  ``stop_nova_hypervisor`` - stop any external services | 
|  | 156 | -  ``cleanup_nova_hypervisor`` - remove transient data and cache |