1- # -*- mode: Shell-script -*-
21# functions - Common functions used by DevStack components
32#
4- # ENABLED_SERVICES is used by is_service_enabled()
3+ # The following variables are assumed to be defined by certain functions:
4+ # ``DISTRO``
5+ # ``ENABLED_SERVICES``
6+ # ``EROR_ON_CLONE``
7+ # ``FILES``
8+ # ``GLANCE_HOSTPORT``
9+ # ``OFFLINE``
10+ # ``PIP_DOWNLOAD_CACHE``
11+ # ``RECLONE``
12+ # ``TRACK_DEPENDS``
13+ # ``http_proxy``, ``https_proxy``, ``no_proxy``
514
615
716# Save trace setting
817XTRACE=$( set +o | grep xtrace)
918set +o xtrace
1019
1120
12- # Exit 0 if address is in network or 1 if
13- # address is not in network or netaddr library
14- # is not installed.
21+ # Exit 0 if address is in network or 1 if address is not in
22+ # network or netaddr library is not installed.
23+ # address_in_net ip-address ip-range
1524function address_in_net() {
1625 python -c "
1726import netaddr
@@ -21,7 +30,8 @@ sys.exit(netaddr.IPAddress('$1') not in netaddr.IPNetwork('$2'))
2130}
2231
2332
24- # apt-get wrapper to set arguments correctly
33+ # Wrapper for ``apt-get`` to set cache and proxy environment variables
34+ # Uses globals ``OFFLINE``, ``*_proxy`
2535# apt_get operation package [package ...]
2636function apt_get() {
2737 [[ " $OFFLINE " = " True" || -z " $@ " ]] && return
@@ -88,15 +98,16 @@ function get_field() {
8898
8999
90100# get_packages() collects a list of package names of any type from the
91- # prerequisite files in ``files/{apts|pips }``. The list is intended
92- # to be passed to a package installer such as apt or pip .
101+ # prerequisite files in ``files/{apts|rpms }``. The list is intended
102+ # to be passed to a package installer such as apt or yum .
93103#
94- # Only packages required for the services in ENABLED_SERVICES will be
104+ # Only packages required for the services in `` ENABLED_SERVICES`` will be
95105# included. Two bits of metadata are recognized in the prerequisite files:
96106# - ``# NOPRIME`` defers installation to be performed later in stack.sh
97107# - ``# dist:DISTRO`` or ``dist:DISTRO1,DISTRO2`` limits the selection
98108# of the package to the distros listed. The distro names are case insensitive.
99109#
110+ # Uses globals ``DISTRO``, ``ENABLED_SERVICES``
100111# get_packages dir
101112function get_packages() {
102113 local package_dir=$1
@@ -241,6 +252,7 @@ GetOSVersion() {
241252}
242253
243254# git update using reference as a branch.
255+ # git_update_branch ref
244256function git_update_branch() {
245257
246258 GIT_BRANCH=$1
@@ -254,6 +266,7 @@ function git_update_branch() {
254266
255267# git update using reference as a tag. Be careful editing source at that repo
256268# as working copy will be in a detached mode
269+ # git_update_tag ref
257270function git_update_tag() {
258271
259272 GIT_TAG=$1
@@ -289,6 +302,7 @@ function GetDistro() {
289302# Set global RECLONE=yes to simulate a clone when dest-dir exists
290303# Set global ERROR_ON_CLONE=True to abort execution with an error if the git repo
291304# does not exist (default is False, meaning the repo will be cloned).
305+ # Uses global ``OFFLINE``
292306# git_clone remote dest-dir branch
293307function git_clone {
294308 [[ " $OFFLINE " = " True" ]] && return
@@ -394,16 +408,20 @@ $option = $value
394408
395409
396410# is_service_enabled() checks if the service(s) specified as arguments are
397- # enabled by the user in ** ENABLED_SERVICES** .
411+ # enabled by the user in `` ENABLED_SERVICES`` .
398412#
399- # If there are multiple services specified as arguments the test performs a
400- # boolean OR or if any of the services specified on the command line
401- # return true.
413+ # Multiple services specified as arguments are ``OR``'ed together; the test
414+ # is a short-circuit boolean, i.e it returns on the first match.
402415#
403- # There is a special cases for some 'catch-all' services::
416+ # There are special cases for some 'catch-all' services::
404417# **nova** returns true if any service enabled start with **n-**
418+ # **cinder** returns true if any service enabled start with **c-**
419+ # **ceilometer** returns true if any service enabled start with **ceilometer**
405420# **glance** returns true if any service enabled start with **g-**
406421# **quantum** returns true if any service enabled start with **q-**
422+ #
423+ # Uses global ``ENABLED_SERVICES``
424+ # is_service_enabled service [service ...]
407425function is_service_enabled() {
408426 services=$@
409427 for service in ${services} ; do
@@ -417,7 +435,9 @@ function is_service_enabled() {
417435 return 1
418436}
419437
420- # remove extra commas from the input string (ENABLED_SERVICES)
438+
439+ # remove extra commas from the input string (i.e. ``ENABLED_SERVICES``)
440+ # _cleanup_service_list service-list
421441function _cleanup_service_list () {
422442 echo " $1 " | sed -e '
423443 s/,,/,/g;
@@ -426,15 +446,17 @@ function _cleanup_service_list () {
426446 '
427447}
428448
449+
429450# enable_service() adds the services passed as argument to the
430- # ** ENABLED_SERVICES** list, if they are not already present.
451+ # `` ENABLED_SERVICES`` list, if they are not already present.
431452#
432453# For example:
433- #
434454# enable_service n-vol
435455#
436456# This function does not know about the special cases
437457# for nova, glance, and quantum built into is_service_enabled().
458+ # Uses global ``ENABLED_SERVICES``
459+ # enable_service service [service ...]
438460function enable_service() {
439461 local tmpsvcs=" ${ENABLED_SERVICES} "
440462 for service in $@ ; do
@@ -446,15 +468,17 @@ function enable_service() {
446468 disable_negated_services
447469}
448470
471+
449472# disable_service() removes the services passed as argument to the
450- # ** ENABLED_SERVICES** list, if they are present.
473+ # `` ENABLED_SERVICES`` list, if they are present.
451474#
452475# For example:
453- #
454476# disable_service n-vol
455477#
456478# This function does not know about the special cases
457479# for nova, glance, and quantum built into is_service_enabled().
480+ # Uses global ``ENABLED_SERVICES``
481+ # disable_service service [service ...]
458482function disable_service() {
459483 local tmpsvcs=" ,${ENABLED_SERVICES} ,"
460484 local service
@@ -466,17 +490,22 @@ function disable_service() {
466490 ENABLED_SERVICES=$( _cleanup_service_list " $tmpsvcs " )
467491}
468492
493+
469494# disable_all_services() removes all current services
470- # from ** ENABLED_SERVICES** to reset the configuration
495+ # from `` ENABLED_SERVICES`` to reset the configuration
471496# before a minimal installation
497+ # Uses global ``ENABLED_SERVICES``
498+ # disable_all_services
472499function disable_all_services() {
473500 ENABLED_SERVICES=" "
474501}
475502
476- # We are looking for services with a - at the beginning to force
477- # excluding those services. For example if you want to install all the default
478- # services but not nova-volume (n-vol) you can have this set in your localrc :
503+
504+ # Remove all services starting with '-'. For example, to install all default
505+ # services except nova-volume (n-vol) set in `` localrc`` :
479506# ENABLED_SERVICES+=",-n-vol"
507+ # Uses global ``ENABLED_SERVICES``
508+ # disable_negated_services
480509function disable_negated_services() {
481510 local tmpsvcs=" ${ENABLED_SERVICES} "
482511 local service
@@ -488,6 +517,7 @@ function disable_negated_services() {
488517 ENABLED_SERVICES=$( _cleanup_service_list " $tmpsvcs " )
489518}
490519
520+
491521# Distro-agnostic package installer
492522# install_package package [package ...]
493523function install_package() {
@@ -513,7 +543,8 @@ function is_set() {
513543}
514544
515545
516- # pip install wrapper to set cache and proxy environment variables
546+ # Wrapper for ``pip install`` to set cache and proxy environment variables
547+ # Uses globals ``OFFLINE``, ``PIP_DOWNLOAD_CACHE``, ``TRACK_DEPENDES``, ``*_proxy`
517548# pip_install package [package ...]
518549function pip_install {
519550 [[ " $OFFLINE " = " True" || -z " $@ " ]] && return
@@ -554,8 +585,9 @@ function restart_service() {
554585}
555586
556587
557- # pip install the dependencies of the package before we do the setup.py
558- # develop, so that pip and not distutils process the dependency chain
588+ # ``pip install`` the dependencies of the package before ``setup.py develop``
589+ # so pip and not distutils processes the dependency chain
590+ # Uses globals ``TRACK_DEPENDES``, ``*_proxy`
559591# setup_develop directory
560592function setup_develop() {
561593 if [[ $TRACK_DEPENDS = True ]] ; then
@@ -606,7 +638,9 @@ function stop_service() {
606638
607639
608640# Normalize config values to True or False
609- # VAR=`trueorfalse default-value test-value`
641+ # Accepts as False: 0 no false False FALSE
642+ # Accepts as True: 1 yes true True TRUE
643+ # VAR=$(trueorfalse default-value test-value)
610644function trueorfalse() {
611645 local default=$1
612646 local testval=$2
@@ -620,8 +654,8 @@ function trueorfalse() {
620654
621655# Retrieve an image from a URL and upload into Glance
622656# Uses the following variables:
623- # ** FILES** must be set to the cache dir
624- # ** GLANCE_HOSTPORT**
657+ # `` FILES`` must be set to the cache dir
658+ # `` GLANCE_HOSTPORT``
625659# upload_image image-url glance-token
626660function upload_image() {
627661 local image_url=$1
@@ -717,7 +751,8 @@ function upload_image() {
717751}
718752
719753
720- # yum wrapper to set arguments correctly
754+ # Wrapper for ``yum`` to set proxy environment variables
755+ # Uses globals ``OFFLINE``, ``*_proxy`
721756# yum_install package [package ...]
722757function yum_install() {
723758 [[ " $OFFLINE " = " True" ]] && return
@@ -731,3 +766,8 @@ function yum_install() {
731766
732767# Restore xtrace
733768$XTRACE
769+
770+
771+ # Local variables:
772+ # -*- mode: Shell-script -*-
773+ # End:
0 commit comments