Skip to content

Commit 630d03e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Basic support of Ironic"
2 parents e45a6af + ce696b6 commit 630d03e

File tree

4 files changed

+254
-0
lines changed

4 files changed

+254
-0
lines changed

lib/ironic

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

stack.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ source $TOP_DIR/lib/heat
318318
source $TOP_DIR/lib/neutron
319319
source $TOP_DIR/lib/baremetal
320320
source $TOP_DIR/lib/ldap
321+
source $TOP_DIR/lib/ironic
321322

322323
# Look for Nova hypervisor plugin
323324
NOVA_PLUGINS=$TOP_DIR/lib/nova_plugins
@@ -785,6 +786,11 @@ if is_service_enabled tls-proxy; then
785786
# don't be naive and add to existing line!
786787
fi
787788

789+
if is_service_enabled ir-api ir-cond; then
790+
install_ironic
791+
configure_ironic
792+
fi
793+
788794
if [[ $TRACK_DEPENDS = True ]]; then
789795
$DEST/.venv/bin/pip freeze > $DEST/requires-post-pip
790796
if ! diff -Nru $DEST/requires-pre-pip $DEST/requires-post-pip > $DEST/requires.diff; then
@@ -953,6 +959,15 @@ if is_service_enabled g-reg; then
953959
init_glance
954960
fi
955961

962+
# Ironic
963+
# ------
964+
965+
if is_service_enabled ir-api ir-cond; then
966+
echo_summary "Configuring Ironic"
967+
init_ironic
968+
fi
969+
970+
956971

957972
# Neutron
958973
# -------
@@ -1202,6 +1217,12 @@ if is_service_enabled g-api g-reg; then
12021217
start_glance
12031218
fi
12041219

1220+
# Launch the Ironic services
1221+
if is_service_enabled ir-api ir-cond; then
1222+
echo_summary "Starting Ironic"
1223+
start_ironic
1224+
fi
1225+
12051226
# Create an access key and secret key for nova ec2 register image
12061227
if is_service_enabled key && is_service_enabled swift3 && is_service_enabled nova; then
12071228
NOVA_USER_ID=$(keystone user-list | grep ' nova ' | get_field 1)

stackrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ HEATCLIENT_BRANCH=${HEATCLIENT_BRANCH:-master}
9696
HORIZON_REPO=${HORIZON_REPO:-${GIT_BASE}/openstack/horizon.git}
9797
HORIZON_BRANCH=${HORIZON_BRANCH:-master}
9898

99+
# baremetal provisionint service
100+
IRONIC_REPO=${IRONIC_REPO:-${GIT_BASE}/openstack/ironic.git}
101+
IRONIC_BRANCH=${IRONIC_BRANCH:-master}
102+
99103
# unified auth system (manages accounts/tokens)
100104
KEYSTONE_REPO=${KEYSTONE_REPO:-${GIT_BASE}/openstack/keystone.git}
101105
KEYSTONE_BRANCH=${KEYSTONE_BRANCH:-master}

unstack.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ source $TOP_DIR/lib/cinder
3333
source $TOP_DIR/lib/horizon
3434
source $TOP_DIR/lib/swift
3535
source $TOP_DIR/lib/neutron
36+
source $TOP_DIR/lib/ironic
3637

3738
# Determine what system we are running on. This provides ``os_VENDOR``,
3839
# ``os_RELEASE``, ``os_UPDATE``, ``os_PACKAGE``, ``os_CODENAME``
@@ -79,6 +80,12 @@ if is_service_enabled s-proxy; then
7980
cleanup_swift
8081
fi
8182

83+
# Ironic runs daemons
84+
if is_service_enabled ir-api ir-cond; then
85+
stop_ironic
86+
cleanup_ironic
87+
fi
88+
8289
# Apache has the WSGI processes
8390
if is_service_enabled horizon; then
8491
stop_horizon

0 commit comments

Comments
 (0)