Skip to content

Commit 2c65e71

Browse files
committed
Implement devstack external plugins
This is an initial pass at plugin infrastructure for devstack which allows specifying an external repository via: enable_plugin <name> <giturl> [branch] It implements the devstack specification for this at I173dee3d57967b1d2ffd30e4868a2832aeac97ce Change-Id: I8e4175313b3cf0b12e981122358b1288a7eb0746
1 parent 7d6df52 commit 2c65e71

4 files changed

Lines changed: 141 additions & 32 deletions

File tree

doc/source/plugins.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,45 @@ The arguments are:
9292
- **clean** - Called by ``clean.sh`` before other services are cleaned,
9393
but after ``unstack.sh`` has been called.
9494

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.
110+
- ``plugin.sh`` - the actual plugin. It will be executed by devstack
111+
during it's run. The run order will be done in the registration
112+
order for these plugins, and will occur immediately after all in
113+
tree extras.d dispatch at the phase in question. The plugin.sh
114+
looks like the extras.d dispatcher above **except** it should not
115+
include the is_service_enabled conditional. All external plugins are
116+
always assumed to be enabled.
117+
118+
Plugins are registered by adding the following to the localrc section
119+
of ``local.conf``.
120+
121+
They are added in the following format::
122+
123+
enable_plugin <NAME> <GITURL> [GITREF]
124+
125+
- ``name`` - an arbitrary name. (ex: glustfs, docker, zaqar, congress)
126+
- ``giturl`` - a valid git url that can be cloned
127+
- ``gitref`` - an optional git ref (branch / ref / tag) that will be
128+
cloned. Defaults to master.
129+
130+
An example would be as follows::
131+
132+
enable_plugin glusterfs https://github.com/sdague/devstack-plugins glusterfs
133+
95134
Hypervisor
96135
==========
97136

functions-common

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ declare -A GITREPO
4444
declare -A GITBRANCH
4545
declare -A GITDIR
4646

47-
4847
# Config Functions
4948
# ================
5049

@@ -1722,6 +1721,97 @@ function setup_package {
17221721
fi
17231722
}
17241723

1724+
# Plugin Functions
1725+
# =================
1726+
1727+
DEVSTACK_PLUGINS=${DEVSTACK_PLUGINS:-""}
1728+
1729+
# enable_plugin <name> <url> [branch]
1730+
#
1731+
# ``name`` is an arbitrary name - (aka: glusterfs, nova-docker, zaqar)
1732+
# ``url`` is a git url
1733+
# ``branch`` is a gitref. If it's not set, defaults to master
1734+
function enable_plugin {
1735+
local name=$1
1736+
local url=$2
1737+
local branch=${3:-master}
1738+
DEVSTACK_PLUGINS+=",$name"
1739+
GITREPO[$name]=$url
1740+
GITDIR[$name]=$DEST/$name
1741+
GITBRANCH[$name]=$branch
1742+
}
1743+
1744+
# fetch_plugins
1745+
#
1746+
# clones all plugins
1747+
function fetch_plugins {
1748+
local plugins="${DEVSTACK_PLUGINS}"
1749+
local plugin
1750+
1751+
# short circuit if nothing to do
1752+
if [[ -z $plugins ]]; then
1753+
return
1754+
fi
1755+
1756+
echo "Fetching devstack plugins"
1757+
for plugin in ${plugins//,/ }; do
1758+
git_clone_by_name $plugin
1759+
done
1760+
}
1761+
1762+
# load_plugin_settings
1763+
#
1764+
# Load settings from plugins in the order that they were registered
1765+
function load_plugin_settings {
1766+
local plugins="${DEVSTACK_PLUGINS}"
1767+
local plugin
1768+
1769+
# short circuit if nothing to do
1770+
if [[ -z $plugins ]]; then
1771+
return
1772+
fi
1773+
1774+
echo "Loading plugin settings"
1775+
for plugin in ${plugins//,/ }; do
1776+
local dir=${GITDIR[$plugin]}
1777+
# source any known settings
1778+
if [[ -f $dir/devstack/settings ]]; then
1779+
source $dir/devstack/settings
1780+
fi
1781+
done
1782+
}
1783+
1784+
# run_plugins
1785+
#
1786+
# Run the devstack/plugin.sh in all the plugin directories. These are
1787+
# run in registration order.
1788+
function run_plugins {
1789+
local mode=$1
1790+
local phase=$2
1791+
for plugin in ${plugins//,/ }; do
1792+
local dir=${GITDIR[$plugin]}
1793+
if [[ -f $dir/devstack/plugin.sh ]]; then
1794+
source $dir/devstack/plugin.sh $mode $phase
1795+
fi
1796+
done
1797+
}
1798+
1799+
function run_phase {
1800+
local mode=$1
1801+
local phase=$2
1802+
if [[ -d $TOP_DIR/extras.d ]]; then
1803+
for i in $TOP_DIR/extras.d/*.sh; do
1804+
[[ -r $i ]] && source $i $mode $phase
1805+
done
1806+
fi
1807+
# the source phase corresponds to settings loading in plugins
1808+
if [[ "$mode" == "source" ]]; then
1809+
load_plugin_settings
1810+
else
1811+
run_plugins $mode $phase
1812+
fi
1813+
}
1814+
17251815

17261816
# Service Functions
17271817
# =================

stack.sh

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -564,15 +564,14 @@ source $TOP_DIR/lib/neutron
564564
source $TOP_DIR/lib/ldap
565565
source $TOP_DIR/lib/dstat
566566

567+
# Clone all external plugins
568+
fetch_plugins
569+
567570
# Extras Source
568571
# --------------
569572

570573
# Phase: source
571-
if [[ -d $TOP_DIR/extras.d ]]; then
572-
for i in $TOP_DIR/extras.d/*.sh; do
573-
[[ -r $i ]] && source $i source
574-
done
575-
fi
574+
run_phase source
576575

577576
# Interactive Configuration
578577
# -------------------------
@@ -714,12 +713,7 @@ source $TOP_DIR/tools/fixup_stuff.sh
714713
# ------------------
715714

716715
# Phase: pre-install
717-
if [[ -d $TOP_DIR/extras.d ]]; then
718-
for i in $TOP_DIR/extras.d/*.sh; do
719-
[[ -r $i ]] && source $i stack pre-install
720-
done
721-
fi
722-
716+
run_phase stack pre-install
723717

724718
install_rpc_backend
725719

@@ -865,11 +859,7 @@ fi
865859
# --------------
866860

867861
# Phase: install
868-
if [[ -d $TOP_DIR/extras.d ]]; then
869-
for i in $TOP_DIR/extras.d/*.sh; do
870-
[[ -r $i ]] && source $i stack install
871-
done
872-
fi
862+
run_phase stack install
873863

874864
if [[ $TRACK_DEPENDS = True ]]; then
875865
$DEST/.venv/bin/pip freeze > $DEST/requires-post-pip
@@ -1142,11 +1132,7 @@ fi
11421132
# ====================
11431133

11441134
# Phase: post-config
1145-
if [[ -d $TOP_DIR/extras.d ]]; then
1146-
for i in $TOP_DIR/extras.d/*.sh; do
1147-
[[ -r $i ]] && source $i stack post-config
1148-
done
1149-
fi
1135+
run_phase stack post-config
11501136

11511137

11521138
# Local Configuration
@@ -1328,11 +1314,7 @@ merge_config_group $TOP_DIR/local.conf extra
13281314
# ==========
13291315

13301316
# Phase: extra
1331-
if [[ -d $TOP_DIR/extras.d ]]; then
1332-
for i in $TOP_DIR/extras.d/*.sh; do
1333-
[[ -r $i ]] && source $i stack extra
1334-
done
1335-
fi
1317+
run_phase stack extra
13361318

13371319
# Local Configuration
13381320
# ===================

unstack.sh

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ if [[ -d $TOP_DIR/extras.d ]]; then
6666
done
6767
fi
6868

69+
load_plugin_settings
70+
6971
# Determine what system we are running on. This provides ``os_VENDOR``,
7072
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
7173
GetOSVersion
@@ -78,11 +80,7 @@ fi
7880
# ==========
7981

8082
# Phase: unstack
81-
if [[ -d $TOP_DIR/extras.d ]]; then
82-
for i in $TOP_DIR/extras.d/*.sh; do
83-
[[ -r $i ]] && source $i unstack
84-
done
85-
fi
83+
run_phase unstack
8684

8785
if [[ "$Q_USE_DEBUG_COMMAND" == "True" ]]; then
8886
source $TOP_DIR/openrc

0 commit comments

Comments
 (0)