blob: ff99e58c199c9af4518206b0ff75e10362d989d1 [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() {
96 iniset $IRONIC_CONF_FILE keystone_authtoken auth_host $KEYSTONE_AUTH_HOST
97 iniset $IRONIC_CONF_FILE keystone_authtoken auth_port $KEYSTONE_AUTH_PORT
98 iniset $IRONIC_CONF_FILE keystone_authtoken auth_protocol $KEYSTONE_AUTH_PROTOCOL
99 iniset $IRONIC_CONF_FILE keystone_authtoken auth_uri $KEYSTONE_SERVICE_PROTOCOL://$KEYSTONE_SERVICE_HOST:$KEYSTONE_SERVICE_PORT/
100 iniset $IRONIC_CONF_FILE keystone_authtoken admin_tenant_name $SERVICE_TENANT_NAME
101 iniset $IRONIC_CONF_FILE keystone_authtoken admin_user ironic
102 iniset $IRONIC_CONF_FILE keystone_authtoken admin_password $SERVICE_PASSWORD
103 if is_service_enabled qpid; then
104 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy qpid
105 elif [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; then
106 iniset $IRONIC_CONF_FILE DEFAULT notifier_strategy rabbit
107 fi
108 iniset_rpc_backend ironic $IRONIC_CONF_FILE DEFAULT
109 iniset $IRONIC_CONF_FILE keystone_authtoken signing_dir $IRONIC_AUTH_CACHE_DIR/api
110
111 cp -p $IRONIC_DIR/etc/ironic/policy.json $IRONIC_POLICY_JSON
112}
113
114# configure_ironic_conductor() - Is used by configure_ironic().
115# Sets conductor specific settings.
116function configure_ironic_conductor() {
117 cp $IRONIC_DIR/etc/ironic/rootwrap.conf $IRONIC_ROOTWRAP_CONF
118 cp -r $IRONIC_DIR/etc/ironic/rootwrap.d $IRONIC_ROOTWRAP_FILTERS
119
120 iniset $IRONIC_CONF DEFAULT rootwrap_config $IRONIC_ROOTWRAP_CONF
121}
122
123# create_ironic_cache_dir() - Part of the init_ironic() process
124function create_ironic_cache_dir() {
125 # Create cache dir
126 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/api
127 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/api
128 rm -f $IRONIC_AUTH_CACHE_DIR/api/*
129 sudo mkdir -p $IRONIC_AUTH_CACHE_DIR/registry
130 sudo chown $STACK_USER $IRONIC_AUTH_CACHE_DIR/registry
131 rm -f $IRONIC_AUTH_CACHE_DIR/registry/*
132}
133
134# create_ironic_accounts() - Set up common required ironic accounts
135
136# Tenant User Roles
137# ------------------------------------------------------------------
138# service ironic admin # if enabled
139create_ironic_accounts() {
140
141 SERVICE_TENANT=$(keystone tenant-list | awk "/ $SERVICE_TENANT_NAME / { print \$2 }")
142 ADMIN_ROLE=$(keystone role-list | awk "/ admin / { print \$2 }")
143
144 # Ironic
145 if [[ "$ENABLED_SERVICES" =~ "ir-api" ]]; then
146 IRONIC_USER=$(keystone user-create \
147 --name=ironic \
148 --pass="$SERVICE_PASSWORD" \
149 --tenant_id $SERVICE_TENANT \
150 --email=ironic@example.com \
151 | grep " id " | get_field 2)
152 keystone user-role-add \
153 --tenant_id $SERVICE_TENANT \
154 --user_id $IRONIC_USER \
155 --role_id $ADMIN_ROLE
156 if [[ "$KEYSTONE_CATALOG_BACKEND" = 'sql' ]]; then
157 IRONIC_SERVICE=$(keystone service-create \
158 --name=ironic \
159 --type=baremetal \
160 --description="Ironic baremetal provisioning service" \
161 | grep " id " | get_field 2)
162 keystone endpoint-create \
163 --region RegionOne \
164 --service_id $IRONIC_SERVICE \
Roman Prykhodchenkof5002ef2013-09-24 19:09:26 +0300165 --publicurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
166 --adminurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT" \
167 --internalurl "$IRONIC_SERVICE_PROTOCOL://$IRONIC_HOSTPORT"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300168 fi
169 fi
170}
171
172
173# init_ironic() - Initialize databases, etc.
174function init_ironic() {
175 # (Re)create ironic database
176 recreate_database ironic utf8
177
178 # Migrate ironic database
179 $IRONIC_BIN_DIR/ironic-dbsync
180
181 create_ironic_cache_dir
182
183 # Create keystone artifacts for Ironic.
184 create_ironic_accounts
185}
186
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300187# start_ironic() - Start running processes, including screen
188function start_ironic() {
189 # Start Ironic API server, if enabled.
190 if is_service_enabled ir-api; then
191 start_ironic_api
192 fi
193
194 # Start Ironic conductor, if enabled.
195 if is_service_enabled ir-cond; then
196 start_ironic_conductor
197 fi
198}
199
200# start_ironic_api() - Used by start_ironic().
201# Starts Ironic API server.
202function start_ironic_api() {
203 screen_it ir-api "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-api --config-file=$IRONIC_CONF_FILE"
204 echo "Waiting for ir-api ($IRONIC_HOSTPORT) to start..."
JUN JIE NAN0aa85342013-09-13 15:47:09 +0800205 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 -0400206 die $LINENO "ir-api did not start"
Roman Prykhodchenkoce696b62013-08-09 10:40:45 +0300207 fi
208}
209
210# start_ironic_conductor() - Used by start_ironic().
211# Starts Ironic conductor.
212function start_ironic_conductor() {
213 screen_it ir-cond "cd $IRONIC_DIR; $IRONIC_BIN_DIR/ironic-conductor --config-file=$IRONIC_CONF_FILE"
214 # TODO(romcheg): Find a way to check whether the conductor has started.
215}
216
217# stop_ironic() - Stop running processes
218function stop_ironic() {
219 # Kill the Ironic screen windows
220 screen -S $SCREEN_NAME -p ir-api -X kill
221 screen -S $SCREEN_NAME -p ir-cond -X kill
222}
223
224
225# Restore xtrace
226$XTRACE
227
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100228# Tell emacs to use shell-script-mode
229## Local variables:
230## mode: shell-script
231## End: