blob: 1ff3c81f067200326dc57599a93071603672df7c [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
36IRONIC_ROOTWRAP_FILTERS=$IRONIC_CONF_DIR/rootwrap.d
37IRONIC_POLICY_JSON=$IRONIC_CONF_DIR/policy.json
38
39# Support entry points installation of console scripts
40IRONIC_BIN_DIR=$(get_python_exec_prefix)
41
42# Ironic connection info. Note the port must be specified.
43IRONIC_SERVICE_PROTOCOL=http
44IRONIC_HOSTPORT=${IRONIC_HOSTPORT:-$SERVICE_HOST:6385}
45
46
47# Functions
48# ---------
49
Roman Prykhodchenko43e00662013-10-15 17:03:15 +030050# install_ironic() - Collect source and prepare
51function install_ironic() {
52 git_clone $IRONIC_REPO $IRONIC_DIR $IRONIC_BRANCH
53 setup_develop $IRONIC_DIR
54}
55
56# install_ironicclient() - Collect sources and prepare
57function install_ironicclient() {
58 git_clone $IRONICCLIENT_REPO $IRONICCLIENT_DIR $IRONICCLIENT_BRANCH
59 setup_develop $IRONICCLIENT_DIR
60}
61
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030062# cleanup_ironic() - Remove residual data files, anything left over from previous
63# runs that would need to clean up.
64function cleanup_ironic() {
65 sudo rm -rf $IRONIC_AUTH_CACHE_DIR
66}
67
68# configure_ironic() - Set config files, create data dirs, etc
69function configure_ironic() {
70 if [[ ! -d $IRONIC_CONF_DIR ]]; then
71 sudo mkdir -p $IRONIC_CONF_DIR
72 fi
73 sudo chown $STACK_USER $IRONIC_CONF_DIR
74
75 # Copy over ironic configuration file and configure common parameters.
76 cp $IRONIC_DIR/etc/ironic/ironic.conf.sample $IRONIC_CONF_FILE
77 iniset $IRONIC_CONF_FILE DEFAULT debug True
78 inicomment $IRONIC_CONF_FILE DEFAULT log_file
79 iniset $IRONIC_CONF_FILE DEFAULT sql_connection `database_connection_url ironic`
80 iniset $IRONIC_CONF_FILE DEFAULT use_syslog $SYSLOG
81
82 # Configure Ironic conductor, if it was enabled.
83 if is_service_enabled ir-cond; then
84 configure_ironic_conductor
85 fi
86
87 # Configure Ironic API, if it was enabled.
88 if is_service_enabled ir-api; then
89 configure_ironic_api
90 fi
91}
92
93# configure_ironic_api() - Is used by configure_ironic(). Performs
94# API specific configuration.
95function configure_ironic_api() {
Roman Prykhodchenkoc48c3122013-10-01 17:19:05 +030096 iniset $IRONIC_CONF_FILE DEFAULT auth_strategy keystone
97 iniset $IRONIC_CONF_FILE DEFAULT policy_file $IRONIC_POLICY_JSON
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +030098 iniset $IRONIC_CONF_FILE keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
99 iniset $IRONIC_CONF_FILE keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
100 iniset $IRONIC_CONF_FILE keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
Jamie Lennoxbd24a8d2013-09-20 16:26:42 +1000101 iniset $IRONIC_CONF_FILE keystone_authtoken cafile $KEYSTONE_SSL_CA
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300102 iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
103 iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
104 iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic
105 iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
106 if is_service_enabled qpid; then
107 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy qpid
108 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
109 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy rabbit
110 fi
111 iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT
112 iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api
113
114 cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON
115}
116
117# configure_ironic_conductor() - Is used by configure_ironic().
118# Sets conductor specific settings.
119function configure_ironic_conductor() {
120 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
121 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_ROOTWRAP_FILTERS
122
123 iniset $IRONIC_CONF DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
124}
125
126# create_ironic_cache_dir() - Part of the init_ironic() process
127function create_ironic_cache_dir() {
128 # Create cache dir
129 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api
130 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api
131 rm -f $IRONIC_AUTH_CACHE_DIR/api/*
132 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry
133 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry
134 rm -f $IRONIC_AUTH_CACHE_DIR/registry/*
135}
136
137# create_ironic_accounts() - Set up common required ironic accounts
138
139# Tenant User Roles
140# ------------------------------------------------------------------
141# service ironic admin # if enabled
142create_ironic_accounts() {
143
144 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
145 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
146
147 # Ironic
148 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
149 IRONIC_USER=$(keystone user-create \
150 --name=ironic \
151 --pass="$SERVICE_PASSWORD" \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100152 --tenant-id $SERVICE_TENANT \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300153 --email=ironic@example.com \
154 | grep " id " | get_field 2)
155 keystone user-role-add \
Dirk Mueller25049cd2014-01-09 13:53:52 +0100156 --tenant-id $SERVICE_TENANT \
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300157 --user_id $IRONIC_USER \
158 --role_id $ADMIN_ROLE
159 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
160 IRONIC_SERVICE=$(keystone service-create \
161 --name=ironic \
162 --type=baremetal \
163 --description="Ironic baremetal provisioning service" \
164 | grep " id " | get_field 2)
165 keystone endpoint-create \
166 --region RegionOne \
167 --service_id $IRONIC_SERVICE \
Roman Prykhodchenkof5002ef2013-09-24 19:09:26 +0300168 --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
169 --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
170 --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300171 fi
172 fi
173}
174
175
176# init_ironic() - Initialize databases, etc.
177function init_ironic() {
178 # (Re)create ironic database
179 recreate_database ironic utf8
180
181 # Migrate ironic database
182 $IRONIC_BIN_DIR/ironic-dbsync
183
184 create_ironic_cache_dir
185
186 # Create keystone artifacts for Ironic.
187 create_ironic_accounts
188}
189
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300190# start_ironic() - Start running processes, including screen
191function start_ironic() {
192 # Start Ironic API server, if enabled.
193 if is_service_enabled ir-api; then
194 start_ironic_api
195 fi
196
197 # Start Ironic conductor, if enabled.
198 if is_service_enabled ir-cond; then
199 start_ironic_conductor
200 fi
201}
202
203# start_ironic_api() - Used by start_ironic().
204# Starts Ironic API server.
205function start_ironic_api() {
206 screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE"
207 echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800208 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 -0400209 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300210 fi
211}
212
213# start_ironic_conductor() - Used by start_ironic().
214# Starts Ironic conductor.
215function start_ironic_conductor() {
216 screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE"
217 # TODO(romcheg): Find a way to check whether the conductor has started.
218}
219
220# stop_ironic() - Stop running processes
221function stop_ironic() {
222 # Kill the Ironic screen windows
223 screen -S $SCREEN_NAME -p ir-api -X kill
224 screen -S $SCREEN_NAME -p ir-cond -X kill
225}
226
227
228# Restore xtrace
229$XTRACE
230
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100231# Tell emacs to use shell-script-mode
232## Local variables:
233## mode: shell-script
234## End: