blob: afbc3e09e4abdb4bb9950cc88ef3ce0beda6b007 [file] [log] [blame]
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +03001# lib/ironic
2# Functions to control the configuration and operation of the **Ironic** service
3
4# Dependencies:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - ``functions`` file
7# - ``DEST``, ``DATA_DIR``, ``STACK_USER`` must be defined
8# - ``SERVICE_{TENANT_NAME|PASSWORD}`` must be defined
9# - ``SERVICE_HOST``
10# - ``KEYSTONE_TOKEN_FORMAT`` must be defined
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030011
12# ``stack.sh`` calls the entry points in this order:
13#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010014# - install_ironic
15# - install_ironicclient
16# - init_ironic
17# - start_ironic
18# - stop_ironic
19# - cleanup_ironic
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030020
21# Save trace setting
22XTRACE=$(set +o | grep xtrace)
23set +o xtrace
24
25
26# Defaults
27# --------
28
29# Set up default directories
30IRONIC_DIR=$DEST/ironic
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030031IRONICCLIENT_DIR=$DEST/python-ironicclient
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030032IRONIC_AUTH_CACHE_DIR=${IRONIC_AUTH_CACHE_DIR:-/var/cache/ironic}
33IRONIC_CONF_DIR=${IRONIC_CONF_DIR:-/etc/ironic}
34IRONIC_CONF_FILE=$IRONIC_CONF_DIR/ironic.conf
35IRONIC_ROOTWRAP_CONF=$IRONIC_CONF_DIR/rootwrap.conf
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030036IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json
37
38# Support entry points installation of console scripts
39IRONIC_BIN_DIR=$(get_python_exec_prefix)
40
41# Ironic connection info. Note the port must be specified.
42IRONIC_SERVICE_PROTOCOL=http
43IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385}
44
45
46# Functions
47# ---------
48
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030049# install_ironic() - Collect source and prepare
50function install_ironic() {
51 git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
52 setup_develop $IRONIC_DIR
53}
54
55# install_ironicclient() - Collect sources and prepare
56function install_ironicclient() {
57 git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH
58 setup_develop $IRONICCLIENT_DIR
59}
60
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030061# cleanup_ironic() - Remove residual data files, anything left over from previous
62# runs that would need to clean up.
63function cleanup_ironic() {
64 sudo rm -rf $IRONIC_AUTH_CACHE_DIR
65}
66
67# configure_ironic() - Set config files, create data dirs, etc
68function configure_ironic() {
69 if [[ ! -d $IRONIC_CONF_DIR ]]; then
70 sudo mkdir -p $IRONIC_CONF_DIR
71 fi
72 sudo chown $STACK_USER $IRONIC_CONF_DIR
73
74 # Copy over ironic configuration file and configure common parameters.
75 cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE
76 iniset $IRONIC_CONF_FILE DEFAULT debug True
77 inicomment $IRONIC_CONF_FILE DEFAULT log_file
78 iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic`
79 iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG
80
81 # Configure Ironic conductor, if it was enabled.
82 if is_service_enabled ir-cond; then
83 configure_ironic_conductor
84 fi
85
86 # Configure Ironic API, if it was enabled.
87 if is_service_enabled ir-api; then
88 configure_ironic_api
89 fi
90}
91
92# configure_ironic_api() - Is used by configure_ironic(). Performs
93# API specific configuration.
94function configure_ironic_api() {
Roman Prykhodchenkoc48c3122013-10-01 17:19:05 +030095 iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone
96 iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030097 iniset $IRONIC_CONF_FILE keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
98 iniset $IRONIC_CONF_FILE keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
99 iniset $IRONIC_CONF_FILE keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000100 iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300101 iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
102 iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
103 iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic
104 iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
105 if is_service_enabled qpid; then
106 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy qpid
107 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
108 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy rabbit
109 fi
110 iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT
111 iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api
112
113 cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON
114}
115
116# configure_ironic_conductor() - Is used by configure_ironic().
117# Sets conductor specific settings.
118function configure_ironic_conductor() {
119 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
Lucas Alvares Gomes279295c2014-01-14 11:37:51 +0000120 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_CONF_DIR
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300121
122 iniset $IRONIC_CONF DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
123}
124
125# create_ironic_cache_dir() - Part of the init_ironic() process
126function create_ironic_cache_dir() {
127 # Create cache dir
128 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api
129 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api
130 rm -f $IRONIC_AUTH_CACHE_DIR/api/*
131 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry
132 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry
133 rm -f $IRONIC_AUTH_CACHE_DIR/registry/*
134}
135
136# create_ironic_accounts() - Set up common required ironic accounts
137
138# Tenant User Roles
139# ------------------------------------------------------------------
140# service ironic admin # if enabled
141create_ironic_accounts() {
142
143 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
144 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
145
146 # Ironic
147 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
148 IRONIC_USER=$(keystone user-create \
149 --name=ironic \
150 --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100151 --tenant-id $SERVICE_TENANT \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300152 --email=ironic@example.com \
153 | grep " id " | get_field 2)
154 keystone user-role-add \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100155 --tenant-id $SERVICE_TENANT \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300156 --user_id $IRONIC_USER \
157 --role_id $ADMIN_ROLE
158 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
159 IRONIC_SERVICE=$(keystone service-create \
160 --name=ironic \
161 --type=baremetal \
162 --description="Ironic baremetal provisioning service" \
163 | grep " id " | get_field 2)
164 keystone endpoint-create \
165 --region RegionOne \
166 --service_id $IRONIC_SERVICE \
Roman Prykhodchenkof5002ef2013-09-24 19:09:26 +0300167 --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
168 --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
169 --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300170 fi
171 fi
172}
173
174
175# init_ironic() - Initialize databases, etc.
176function init_ironic() {
177 # (Re)create ironic database
178 recreate_database ironic utf8
179
180 # Migrate ironic database
181 $IRONIC_BIN_DIR/ironic-dbsync
182
183 create_ironic_cache_dir
184
185 # Create keystone artifacts for Ironic.
186 create_ironic_accounts
187}
188
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300189# start_ironic() - Start running processes, including screen
190function start_ironic() {
191 # Start Ironic API server, if enabled.
192 if is_service_enabled ir-api; then
193 start_ironic_api
194 fi
195
196 # Start Ironic conductor, if enabled.
197 if is_service_enabled ir-cond; then
198 start_ironic_conductor
199 fi
200}
201
202# start_ironic_api() - Used by start_ironic().
203# Starts Ironic API server.
204function start_ironic_api() {
205 screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE"
206 echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800207 if ! timeout $SERVICE_TIMEOUT sh -c "while ! wget --no-proxy -q -O- http://$IRONIC_HOSTPORT; do sleep 1; done"; then
Sean Dague101b4242013-10-22 08:47:11 -0400208 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300209 fi
210}
211
212# start_ironic_conductor() - Used by start_ironic().
213# Starts Ironic conductor.
214function start_ironic_conductor() {
215 screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE"
216 # TODO(romcheg): Find a way to check whether the conductor has started.
217}
218
219# stop_ironic() - Stop running processes
220function stop_ironic() {
221 # Kill the Ironic screen windows
222 screen -S $SCREEN_NAME -p ir-api -X kill
223 screen -S $SCREEN_NAME -p ir-cond -X kill
224}
225
226
227# Restore xtrace
228$XTRACE
229
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100230# Tell emacs to use shell-script-mode
231## Local variables:
232## mode: shell-script
233## End: