All new accounts created on Gitlab now require administrator approval. If you invite any collaborators, please let Flux staff know so they can approve the accounts.

setup-controller.sh 189 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/bin/sh

##
## Setup the OpenStack controller node.
##

set -x

DIRNAME=`dirname $0`

# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Grab our libs
. "$DIRNAME/setup-lib.sh"

if [ "$HOSTNAME" != "$CONTROLLER" ]; then
    exit 0;
fi

24 25
logtstart "controller"

26 27 28 29
if [ -f $SETTINGS ]; then
    . $SETTINGS
fi

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#
# openstack CLI commands seem flakey sometimes on Kilo and Liberty.
# Don't know if it's WSGI, mysql dropping connections, an NTP
# thing... but until it gets solved more permanently, have to retry :(.
#
__openstack() {
    __err=1
    __debug=
    __times=0
    while [ $__times -lt 16 -a ! $__err -eq 0 ]; do
	openstack $__debug "$@"
	__err=$?
        if [ $__err -eq 0 ]; then
            break
        fi
	__debug=" --debug "
	__times=`expr $__times + 1`
	if [ $__times -gt 1 ]; then
	    echo "ERROR: openstack command failed: sleeping and trying again!"
	    sleep 8
	fi
    done
}

54 55 56 57 58 59 60 61 62 63
#
# We're going to spin off our image downloader/configurator to better
# parallelize.  So make sure it has the packages it needs.
#
maybe_install_packages qemu-utils wget lockfile-progs rpm
if [ "$ARCH" = "aarch64" ]; then
    # need growpart
    maybe_install_packages cloud-guest-utils
fi

64 65
maybe_install_packages pssh
PSSH='/usr/bin/parallel-ssh -t 0 -O StrictHostKeyChecking=no '
66
PSCP='/usr/bin/parallel-scp -t 0 -O StrictHostKeyChecking=no '
67

68 69 70 71 72 73 74
# Make sure our repos are setup.
#apt-get install ubuntu-cloud-keyring
#echo "deb http://ubuntu-cloud.archive.canonical.com/ubuntu" \
#    "trusty-updates/juno main" > /etc/apt/sources.list.d/cloudarchive-juno.list

#sudo add-apt-repository ppa:ubuntu-cloud-archive/juno-staging 

75 76 77
#
# Setup mail to users
#
78
maybe_install_packages dma
79
maybe_install_packages mailutils
80 81
echo "$PFQDN" > /etc/mailname
sleep 2
82 83 84
echo "Your OpenStack instance is setting up on `hostname` ." \
    |  mail -s "OpenStack Instance Setting Up" ${SWAPPER_EMAIL} &

85 86 87 88 89
#
# Fire off the image downloader/configurator in the background.
#
$DIRNAME/setup-images.sh >> $OURDIR/setup-images.log 2>&1 &

90 91 92 93
#
# If we're >= Kilo, we might need the openstack CLI command.
#
if [ $OSVERSION -ge $OSKILO ]; then
94
    maybe_install_packages ${PYPKGPREFIX}-openstackclient
95 96
fi

97 98 99 100
#
# This is a nasty bug in oslo_service; see 
# https://review.openstack.org/#/c/256267/
#
101
if [ $OSVERSION -ge $OSKILO -a $OSVERSION -lt $OSNEWTON ]; then
102
    maybe_install_packages ${PYPKGPREFIX}-oslo.service
103 104 105
    patch -d / -p0 < $DIRNAME/etc/oslo_service-liberty-sig-MAINLOOP.patch
fi

106 107 108 109
#
# Install the database
#
if [ -z "${DB_ROOT_PASS}" ]; then
110
    logtstart "database"
111
    maybe_install_packages mariadb-server $DBDPACKAGE
112
    service_stop mysql
113 114 115 116 117 118 119 120 121 122
    # Change the root password; secure the users/dbs.
    mysqld_safe --skip-grant-tables --skip-networking &
    sleep 8
    DB_ROOT_PASS=`$PSWDGEN`
    # This does what mysql_secure_installation does on Ubuntu
    echo "use mysql; update user set password=PASSWORD(\"${DB_ROOT_PASS}\") where User='root'; delete from user where User=''; delete from user where User='root' and Host not in ('localhost', '127.0.0.1', '::1'); drop database test; delete from db where Db='test' or Db='test\\_%'; flush privileges;" | mysql -u root 
    # Shutdown our unprotected server
    mysqladmin --password=${DB_ROOT_PASS} shutdown
    # Put it on the management network and set recommended settings
    echo "[mysqld]" >> /etc/mysql/my.cnf
123
    echo "bind-address = $MGMTIP" >> /etc/mysql/my.cnf
124 125 126 127 128
    echo "default-storage-engine = innodb" >> /etc/mysql/my.cnf
    echo "innodb_file_per_table" >> /etc/mysql/my.cnf
    echo "collation-server = utf8_general_ci" >> /etc/mysql/my.cnf
    echo "init-connect = 'SET NAMES utf8'" >> /etc/mysql/my.cnf
    echo "character-set-server = utf8" >> /etc/mysql/my.cnf
David Johnson's avatar
David Johnson committed
129
    echo "max_connections = 4096" >> /etc/mysql/my.cnf
130
    # Restart it!
131 132
    service_restart mysql
    service_enable mysql
133 134
    # Save the passwd
    echo "DB_ROOT_PASS=\"${DB_ROOT_PASS}\"" >> $SETTINGS
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

    if [ -z "${MGMTLAN}" -a $OSVERSION -ge $OSLIBERTY ]; then
        # Make sure mysqld won't start until after the openvpn
	# mgmt net is up.
	cat <<EOF >/etc/init.d/legacy-openvpn-net-waiter
#!/bin/bash
#
### BEGIN INIT INFO
# Provides:          legacy-openvpn-net-waiter
# Required-Start:    \$network openvpn
# Required-Stop:
# Should-Start:      \$network openvpn
# X-Start-Before:    mysql
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Waits for an IP address to appear on the mgmt net device.
# Description:  Waits for an IP address to appear on the mgmt net device.
### END INIT INFO
#

. /lib/lsb/init-functions

case "\${1:-''}" in
    'start')
        while [ 1 -eq 1 ]; do
            ip addr show | grep -q "$MGMTIP"
            if [ \$? -eq 0 ]; then
                log_daemon_msg "Found net device with ip addr $MGMTIP; allowing services to start" "openvpn"
                break
            else
                sleep 1
            fi
        done
        ;;
    'stop')
        exit 0
        ;;
    'restart')
        exit 0
        ;;
    *)
        exit 1
        ;;
esac

exit 0
EOF

	chmod 755 /etc/init.d/legacy-openvpn-net-waiter

	#sed -i -e 's/^# Required-Start:\(.*\)$/# Required-Start:\1 mgmt-net-waiter/' /etc/init.d/mysql
	#sed -i -e 's/^# Should-Start:\(.*\)$/# Should-Start:\1 mgmt-net-waiter/' /etc/init.d/mysql

	update-rc.d legacy-openvpn-net-waiter defaults
	update-rc.d legacy-openvpn-net-waiter enable
	#update-rc.d mysql enable
    fi
192
    logtend "database"
193 194 195 196 197 198
fi

#
# Install a message broker
#
if [ -z "${RABBIT_PASS}" ]; then
199
    logtstart "rabbit"
200
    maybe_install_packages rabbitmq-server
201

202 203
    service_restart rabbitmq-server
    service_enable rabbitmq-server
204 205 206 207 208
    rabbitmqctl start_app
    while [ ! $? -eq 0 ]; do
	sleep 1
	rabbitmqctl start_app
    done
209

210 211
    if [ $OSVERSION -lt $OSNEWTON ]; then
	cat <<EOF > /etc/rabbitmq/rabbitmq.config
212 213 214 215 216 217 218 219
[
 {rabbit,
  [
   {loopback_users, []}
  ]}
]
.
EOF
220
    fi
221

David Johnson's avatar
David Johnson committed
222 223
    if [ ${OSCODENAME} = "juno" ]; then
	RABBIT_USER="guest"
224
    else
David Johnson's avatar
David Johnson committed
225 226 227
	RABBIT_USER="openstack"
	rabbitmqctl add_vhost /
    fi
228
    RABBIT_PASS=`$PSWDGEN`
229
    RABBIT_URL="rabbit://${RABBIT_USER}:${RABBIT_PASS}@${CONTROLLER}"
David Johnson's avatar
David Johnson committed
230 231 232 233 234
    rabbitmqctl change_password $RABBIT_USER $RABBIT_PASS
    if [ ! $? -eq 0 ]; then
	rabbitmqctl add_user ${RABBIT_USER} ${RABBIT_PASS}
	rabbitmqctl set_permissions ${RABBIT_USER} ".*" ".*" ".*"
    fi
235
    # Save the passwd
David Johnson's avatar
David Johnson committed
236
    echo "RABBIT_USER=\"${RABBIT_USER}\"" >> $SETTINGS
237
    echo "RABBIT_PASS=\"${RABBIT_PASS}\"" >> $SETTINGS
238
    echo "RABBIT_URL=\"${RABBIT_URL}\"" >> $SETTINGS
239

240
    rabbitmqctl stop_app
241 242
    service_restart rabbitmq-server
    rabbitmqctl start_app
243 244 245 246
    while [ ! $? -eq 0 ]; do
	sleep 1
	rabbitmqctl start_app
    done
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271

    if [ -z "${MGMTLAN}" -a $OSVERSION -ge $OSLIBERTY ]; then
        # Make sure rabbitmq won't start until after the openvpn
	# mgmt net is up.
	cat <<EOF >/etc/systemd/system/openvpn-net-waiter.service
[Unit]
Description=OpenVPN Device Waiter
After=network.target network-online.target local-fs.target
Wants=network.target
Before=rabbitmq-server.service
Requires=rabbitmq-server.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/etc/init.d/legacy-openvpn-net-waiter start
StandardOutput=journal+console
StandardError=journal+console

[Install]
WantedBy=multi-user.target
EOF

	systemctl enable openvpn-net-waiter.service
    fi
272
    logtend "rabbit"
273 274
fi

275 276 277 278 279 280 281 282 283
#
# If Keystone API Version v3, we have to supply a --domain sometimes.
#
DOMARG=""
#if [ $OSVERSION -gt $OSKILO ]; then
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
    DOMARG="--domain default"
fi

284 285 286 287
#
# Always install memcache now.
#
if [ -z "${MEMCACHE_DONE}" ]; then
288
    logtstart "memcache"
289
    maybe_install_packages memcached ${PYPKGPREFIX}-memcache
290 291 292 293 294 295 296 297

    # Ensure memcached also listens on private controller network
    cat <<EOF >> /etc/memcached.conf
-l ${MGMTIP}
EOF

    if [ ${HAVE_SYSTEMD} -eq 1 ]; then
	mkdir /etc/systemd/system/memcached.service.d
298 299 300
	systemctl list-units | grep -q networking\.service
	if [ $? -eq 0 ]; then
	    cat <<EOF >/etc/systemd/system/memcached.service.d/local-ifup.conf
301 302 303 304
[Unit]
Requires=networking.service
After=networking.service
EOF
305 306 307 308 309 310 311 312 313 314
	else
	    systemctl list-units | grep -q network-online\.target
	    if [ $? -eq 0 ]; then
		cat <<EOF >/etc/systemd/system/memcached.service.d/local-ifup.conf
[Unit]
Requires=network-online.target
After=network-online.target
EOF
	    fi
	fi
315 316 317 318 319
    fi
    service_restart memcached
    service_enable memcached

    echo "MEMCACHE_DONE=1" >> $SETTINGS
320
    logtend "memcache"
321 322
fi

323
if [ $OSVERSION -ge $OSROCKY -a -z "${ETCD_DONE}" ]; then
David Johnson's avatar
David Johnson committed
324
    logtstart "etcd"
325 326 327 328 329 330 331 332 333 334 335 336
    if [ $ARCH = "aarch64" ]; then
	#
	# We need to set a particular env var for unsupported
	# architectures, BEFORE we install.  Otherwise apt-get will
	# return error.
	#
	mkdir -p /etc/systemd/system/etcd.service.d
	cat <<EOF >/etc/systemd/system/etcd.service.d/local.conf
[Service]
Environment=ETCD_UNSUPPORTED_ARCH=arm64
EOF
    fi
David Johnson's avatar
David Johnson committed
337
    maybe_install_packages etcd etcd-server etcd-client
David Johnson's avatar
David Johnson committed
338 339 340
    if [ $OSVERSION -le $OSQUEENS ]; then
	mkdir -p /etc/etcd
	cat <<EOF >> /etc/etcd/etcd.conf.yaml
David Johnson's avatar
David Johnson committed
341 342 343 344
name: ${CONTROLLER}
data-dir: /var/lib/etcd
initial-cluster-state: 'new'
initial-cluster-token: 'etcd-cluster-01'
David Johnson's avatar
David Johnson committed
345
initial-cluster: ${CONTROLLER}=http:/:2380
David Johnson's avatar
David Johnson committed
346 347 348 349 350
initial-advertise-peer-urls: http://${MGMTIP}:2380
advertise-client-urls: http://${MGMTIP}:2379
listen-peer-urls: http://0.0.0.0:2380
listen-client-urls: http://${MGMTIP}:2379
EOF
David Johnson's avatar
David Johnson committed
351 352 353 354
	chown -R etcd:etcd /etc/etcd
	chmod 750 /etc/etcd
    else
	cat <<EOF >/etc/default/etcd
David Johnson's avatar
David Johnson committed
355
ETCD_NAME="$CONTROLLER"
David Johnson's avatar
David Johnson committed
356 357 358 359 360 361 362 363 364 365
ETCD_DATA_DIR="/var/lib/etcd"
ETCD_INITIAL_CLUSTER_STATE="new"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-01"
ETCD_INITIAL_CLUSTER="${CONTROLLER}=http://${MGMTIP}:2380"
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://${MGMTIP}:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://${MGMTIP}:2379"
ETCD_LISTEN_PEER_URLS="http://${MGMTIP}:2380"
ETCD_LISTEN_CLIENT_URLS="http://${MGMTIP}:2379"
EOF
    fi
David Johnson's avatar
David Johnson committed
366 367 368 369 370 371 372 373

    service_enable etcd
    service_restart etcd

    echo "ETCD_DONE=1" >> $SETTINGS
    logtend "etcd"
fi

374 375 376 377
#
# Install the Identity Service
#
if [ -z "${KEYSTONE_DBPASS}" ]; then
378
    logtstart "keystone"
379 380 381 382 383
    KEYSTONE_DBPASS=`$PSWDGEN`
    echo "create database keystone" | mysql -u root --password="$DB_ROOT_PASS"
    echo "grant all privileges on keystone.* to 'keystone'@'localhost' identified by '$KEYSTONE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
    echo "grant all privileges on keystone.* to 'keystone'@'%' identified by '$KEYSTONE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"

384
    maybe_install_packages keystone ${PYPKGPREFIX}-keystoneclient
385
    if [ $OSVERSION -ge $OSKILO -o $KEYSTONEUSEWSGI -eq 1 ]; then
386
	maybe_install_packages apache2
387 388 389 390 391
	if [ $ISPYTHON3 -eq 1 ]; then
	    maybe_install_packages libapache2-mod-wsgi-py3
	else
	    maybe_install_packages libapache2-mod-wsgi
	fi
392
	a2enmod wsgi
393
    fi
394 395 396

    ADMIN_TOKEN=`$PSWDGEN`

397 398
    crudini --set /etc/keystone/keystone.conf DEFAULT admin_token "$ADMIN_TOKEN"
    crudini --set /etc/keystone/keystone.conf database connection \
399
	"${DBDSTRING}://keystone:${KEYSTONE_DBPASS}@$CONTROLLER/keystone"
400 401 402 403 404 405 406 407 408 409 410 411 412

    crudini --set /etc/keystone/keystone.conf token expiration ${TOKENTIMEOUT}

    if [ $OSVERSION -le $OSJUNO ]; then
	crudini --set /etc/keystone/keystone.conf token provider \
	    'keystone.token.providers.uuid.Provider'
	crudini --set /etc/keystone/keystone.conf token driver \
	    'keystone.token.persistence.backends.sql.Token'
    elif [ $OSVERSION -le $OSKILO ]; then
	crudini --set /etc/keystone/keystone.conf token provider \
	    'keystone.token.providers.uuid.Provider'
	crudini --set /etc/keystone/keystone.conf revoke driver \
	    'keystone.contrib.revoke.backends.sql.Revoke'
413 414 415 416
	if [ $KEYSTONEUSEMEMCACHE -eq 1 ]; then
	    crudini --set /etc/keystone/keystone.conf token driver \
		'keystone.token.persistence.backends.memcache.Token'
	    crudini --set /etc/keystone/keystone.conf memcache servers \
417
		'127.0.0.1:11211'
418 419 420 421
	else
	    crudini --set /etc/keystone/keystone.conf token driver \
		'keystone.token.persistence.backends.sql.Token'
	fi
422 423 424 425
    else
	if [ $OSVERSION -le $OSMITAKA ]; then
	    crudini --set /etc/keystone/keystone.conf token provider 'uuid'
	    crudini --set /etc/keystone/keystone.conf revoke driver 'sql'
426
	else
427
	    crudini --set /etc/keystone/keystone.conf token provider fernet
428
	fi
429

430
	if [ $KEYSTONEUSEMEMCACHE -eq 1 ]; then
431
	    if [ $OSVERSION -lt $OSQUEENS ]; then
432 433
		crudini --set /etc/keystone/keystone.conf token driver 'memcache'
	    fi
434 435 436 437 438 439
	    if [ $OSVERSION -lt $OSSTEIN ]; then
		crudini --set /etc/keystone/keystone.conf cache \
		    backend dogpile.cache.memcached
		crudini --set /etc/keystone/keystone.conf cache \
		    backend_argument url:127.0.0.1:11211
	    fi
440 441 442 443 444 445 446 447
	    crudini --set /etc/keystone/keystone.conf cache \
		enable true
	    crudini --set /etc/keystone/keystone.conf cache \
		enabled true
	    crudini --set /etc/keystone/keystone.conf cache \
		memcache_servers 127.0.0.1:11211
	    crudini --set /etc/keystone/keystone.conf cache \
		memcached_servers 127.0.0.1:11211
448
	    crudini --set /etc/keystone/keystone.conf memcache servers \
449
		'127.0.0.1:11211'
David Johnson's avatar
David Johnson committed
450 451
	else
	    crudini --set /etc/keystone/keystone.conf token driver 'sql'
452
	fi
453
    fi
454

455 456
    crudini --set /etc/keystone/keystone.conf DEFAULT verbose ${VERBOSE_LOGGING}
    crudini --set /etc/keystone/keystone.conf DEFAULT debug ${DEBUG_LOGGING}
457 458 459

    su -s /bin/sh -c "/usr/bin/keystone-manage db_sync" keystone

David Johnson's avatar
David Johnson committed
460 461 462 463 464 465 466
    if [ $OSVERSION -ge $OSNEWTON ]; then
	keystone-manage fernet_setup --keystone-user keystone \
	    --keystone-group keystone
	keystone-manage credential_setup --keystone-user keystone \
	    --keystone-group keystone
    fi

467
    if [ $OSVERSION -eq $OSKILO -a $KEYSTONEUSEWSGI -eq 1 ]; then
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
	cat <<EOF >/etc/apache2/sites-available/wsgi-keystone.conf
Listen 5000
Listen 35357

<VirtualHost *:5000>
    WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone display-name=%{GROUP}
    WSGIProcessGroup keystone-public
    WSGIScriptAlias / /var/www/cgi-bin/keystone/main
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    <IfVersion >= 2.4>
      ErrorLogFormat "%{cu}t %M"
    </IfVersion>
    LogLevel info
    ErrorLog /var/log/apache2/keystone-error.log
    CustomLog /var/log/apache2/keystone-access.log combined
</VirtualHost>

<VirtualHost *:35357>
    WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone display-name=%{GROUP}
    WSGIProcessGroup keystone-admin
    WSGIScriptAlias / /var/www/cgi-bin/keystone/admin
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    <IfVersion >= 2.4>
      ErrorLogFormat "%{cu}t %M"
    </IfVersion>
    LogLevel info
    ErrorLog /var/log/apache2/keystone-error.log
    CustomLog /var/log/apache2/keystone-access.log combined
</VirtualHost>
EOF

	ln -s /etc/apache2/sites-available/wsgi-keystone.conf \
	    /etc/apache2/sites-enabled

	mkdir -p /var/www/cgi-bin/keystone
	wget -O /var/www/cgi-bin/keystone/admin "http://git.openstack.org/cgit/openstack/keystone/plain/httpd/keystone.py?h=stable/${OSCODENAME}"
506 507 508 509
	if [ ! $? -eq 0 ]; then
            # Try the EOL version...
            wget -O /var/www/cgi-bin/keystone/admin "http://git.openstack.org/cgit/openstack/keystone/plain/httpd/keystone.py?h=${OSCODENAME}-eol"
	fi
510 511 512
	cp -p /var/www/cgi-bin/keystone/admin /var/www/cgi-bin/keystone/main 
	chown -R keystone:keystone /var/www/cgi-bin/keystone
	chmod 755 /var/www/cgi-bin/keystone/*
David Johnson's avatar
David Johnson committed
513 514
    elif [ $OSVERSION -ge $OSLIBERTY -a $KEYSTONEUSEWSGI -eq 1 \
	   -a $OSVERSION -lt $OSNEWTON ]; then
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567
	cat <<EOF >/etc/apache2/sites-available/wsgi-keystone.conf
Listen 5000
Listen 35357

<VirtualHost *:5000>
    WSGIDaemonProcess keystone-public processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
    WSGIProcessGroup keystone-public
    WSGIScriptAlias / /usr/bin/keystone-wsgi-public
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    <IfVersion >= 2.4>
      ErrorLogFormat "%{cu}t %M"
    </IfVersion>
    ErrorLog /var/log/apache2/keystone.log
    CustomLog /var/log/apache2/keystone_access.log combined

    <Directory /usr/bin>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
    </Directory>
</VirtualHost>

<VirtualHost *:35357>
    WSGIDaemonProcess keystone-admin processes=5 threads=1 user=keystone group=keystone display-name=%{GROUP}
    WSGIProcessGroup keystone-admin
    WSGIScriptAlias / /usr/bin/keystone-wsgi-admin
    WSGIApplicationGroup %{GLOBAL}
    WSGIPassAuthorization On
    <IfVersion >= 2.4>
      ErrorLogFormat "%{cu}t %M"
    </IfVersion>
    ErrorLog /var/log/apache2/keystone.log
    CustomLog /var/log/apache2/keystone_access.log combined

    <Directory /usr/bin>
        <IfVersion >= 2.4>
            Require all granted
        </IfVersion>
        <IfVersion < 2.4>
            Order allow,deny
            Allow from all
        </IfVersion>
    </Directory>
</VirtualHost>
EOF

	ln -s /etc/apache2/sites-available/wsgi-keystone.conf \
	    /etc/apache2/sites-enabled
568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584
    else
	# Make sure various symlinks for keystone/wsgi are in place.
	if [ ! -e /etc/apache2/sites-enabled/keystone.conf -a \
	       -e /etc/apache2/sites-available/keystone.conf ]; then
	    ln -s /etc/apache2/sites-available/keystone.conf \
	        /etc/apache2/sites-enabled/
	fi
	if [ ! -e /etc/apache2/mods-enabled/wsgi.conf -a \
	       -e /etc/apache2/mods-available/wsgi.conf ]; then
	    ln -s /etc/apache2/mods-available/wsgi.conf \
	        /etc/apache2/mods-enabled/
	fi
	if [ ! -e /etc/apache2/mods-enabled/wsgi.load -a \
	       -e /etc/apache2/mods-available/wsgi.load ]; then
	    ln -s /etc/apache2/mods-available/wsgi.load \
	        /etc/apache2/mods-enabled/
	fi
585
	a2ensite keystone
586 587
    fi

588
    if [ $OSVERSION -le $OSJUNO -o $KEYSTONEUSEWSGI -eq 0 ]; then
589 590 591
	service_restart keystone
	service_enable keystone
    else
592 593 594
	service_stop keystone
	service_disable keystone

595 596 597
	service_restart apache2
	service_enable apache2
    fi
598 599 600 601 602 603 604 605 606 607
    rm -f /var/lib/keystone/keystone.db

    sleep 8

    # optional of course
    (crontab -l -u keystone 2>&1 | grep -q token_flush) || \
        echo '@hourly /usr/bin/keystone-manage token_flush >/var/log/keystone/keystone-tokenflush.log 2>&1' \
        >> /var/spool/cron/crontabs/keystone

    # Create admin token
608 609
    if [ $OSVERSION -lt $OSKILO ]; then
	export OS_SERVICE_TOKEN=$ADMIN_TOKEN
610
	export OS_SERVICE_ENDPOINT=http://$CONTROLLER:${KADMINPORT}/$KAPISTR
611 612
    else
	export OS_TOKEN=$ADMIN_TOKEN
613
	export OS_URL=http://$CONTROLLER:${KADMINPORT}/$KAPISTR
614 615 616 617 618 619 620

	if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
	    export OS_IDENTITY_API_VERSION=3
	else
	    export OS_IDENTITY_API_VERSION=2.0
	fi
    fi
621

622 623 624 625 626 627 628 629 630 631 632
    if [ $OSVERSION -lt $OSKILO ]; then
        # Create the service tenant:
	keystone tenant-create --name service --description "Service Tenant"
        # Create the service entity for the Identity service:
	keystone service-create --name keystone --type identity \
            --description "OpenStack Identity Service"
        # Create the API endpoint for the Identity service:
	keystone endpoint-create \
            --service-id `keystone service-list | awk '/ identity / {print $2}'` \
            --publicurl http://$CONTROLLER:5000/v2.0 \
            --internalurl http://$CONTROLLER:5000/v2.0 \
633
            --adminurl http://$CONTROLLER:${KADMINPORT}/v2.0 \
634 635 636 637 638 639 640 641 642
            --region $REGION
    else
	__openstack service create \
	    --name keystone --description "OpenStack Identity" identity

	if [ $KEYSTONEAPIVERSION -lt 3 ]; then
	    __openstack endpoint create \
		--publicurl http://${CONTROLLER}:5000/${KAPISTR} \
		--internalurl http://${CONTROLLER}:5000/${KAPISTR} \
643
		--adminurl http://${CONTROLLER}:${KADMINPORT}/${KAPISTR} \
644 645 646 647 648 649 650
		--region $REGION identity
	else
	    __openstack endpoint create --region $REGION \
		identity public http://${CONTROLLER}:5000/${KAPISTR}
	    __openstack endpoint create --region $REGION \
		identity internal http://${CONTROLLER}:5000/${KAPISTR}
	    __openstack endpoint create --region $REGION \
651
		identity admin http://${CONTROLLER}:${KADMINPORT}/${KAPISTR}
652 653
	fi
    fi
654 655 656

    if [ "x${ADMIN_PASS}" = "x" ]; then
        # Create the admin user -- temporarily use the random one for
657 658
        # ${ADMIN_API}; we change it right away below manually via sql
	APSWD="${ADMIN_API_PASS}"
659
    else
660 661 662 663 664 665 666
	APSWD="${ADMIN_PASS}"
    fi

    if [ $OSVERSION -eq $OSJUNO ]; then
        # Create the admin tenant
	keystone tenant-create --name admin --description "Admin Tenant"
	keystone user-create --name admin --pass "${APSWD}" \
667
	    --email "${SWAPPER_EMAIL}"
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
        # Create the admin role
	keystone role-create --name admin
        # Add the admin tenant and user to the admin role:
	keystone user-role-add --tenant admin --user admin --role admin
        # Create the _member_ role:
	keystone role-create --name _member_
        # Add the admin tenant and user to the _member_ role:
	keystone user-role-add --tenant admin --user admin --role _member_

        # Create the adminapi user
	keystone user-create --name ${ADMIN_API} --pass ${ADMIN_API_PASS} \
	    --email "${SWAPPER_EMAIL}"
	keystone user-role-add --tenant admin --user ${ADMIN_API} --role admin
	keystone user-role-add --tenant admin --user ${ADMIN_API} --role _member_
    else
683 684 685 686
	if [ $OSVERSION -ge $OSMITAKA ]; then
	    openstack domain create --description "Default Domain" default
	fi

687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702
	__openstack project create $DOMARG --description "Admin Project" admin
	__openstack user create $DOMARG --password "${APSWD}" \
	    --email "${SWAPPER_EMAIL}" admin
	__openstack role create admin
	__openstack role add --project admin --user admin admin

	__openstack role create user
	__openstack role add --project admin --user admin user

	__openstack project create $DOMARG --description "Service Project" service

        # Create the adminapi user
	__openstack user create $DOMARG --password ${ADMIN_API_PASS} \
	    --email "${SWAPPER_EMAIL}" ${ADMIN_API}
	__openstack role add --project admin --user ${ADMIN_API} admin
	__openstack role add --project admin --user ${ADMIN_API} user
703
    fi
704

705 706 707 708 709 710 711 712

    if [ "x${ADMIN_PASS}" = "x" ]; then
        #
        # Update the admin user with the passwd hash from our config
        #
	echo "update user set password='${ADMIN_PASS_HASH}' where name='admin'" \
	    | mysql -u root --password=${DB_ROOT_PASS} keystone
    fi
713

714 715 716 717 718 719
    if [ $OSVERSION -lt $OSKILO ]; then
	unset OS_SERVICE_TOKEN OS_SERVICE_ENDPOINT
    else
	unset OS_TOKEN OS_URL
	unset OS_IDENTITY_API_VERSION
    fi
720

721
    crudini --del /etc/keystone/keystone.conf DEFAULT admin_token
722 723

    # Save the passwd
724 725
    echo "ADMIN_API=\"${ADMIN_API}\"" >> $SETTINGS
    echo "ADMIN_API_PASS=\"${ADMIN_API_PASS}\"" >> $SETTINGS
726
    echo "KEYSTONE_DBPASS=\"${KEYSTONE_DBPASS}\"" >> $SETTINGS
727 728

    logtend "keystone"
729 730 731
fi

#
732
# Create the admin-openrc.{sh,py} files.
733
#
734 735 736
echo "export OS_TENANT_NAME=admin" > $OURDIR/admin-openrc-oldcli.sh
echo "export OS_USERNAME=${ADMIN_API}" >> $OURDIR/admin-openrc-oldcli.sh
echo "export OS_PASSWORD=${ADMIN_API_PASS}" >> $OURDIR/admin-openrc-oldcli.sh
737
echo "export OS_AUTH_URL=http://$CONTROLLER:${KADMINPORT}/v2.0" >> $OURDIR/admin-openrc-oldcli.sh
738 739 740 741

echo "OS_TENANT_NAME=\"admin\"" > $OURDIR/admin-openrc-oldcli.py
echo "OS_USERNAME=\"${ADMIN_API}\"" >> $OURDIR/admin-openrc-oldcli.py
echo "OS_PASSWORD=\"${ADMIN_API_PASS}\"" >> $OURDIR/admin-openrc-oldcli.py
742
echo "OS_AUTH_URL=\"http://$CONTROLLER:${KADMINPORT}/v2.0\"" >> $OURDIR/admin-openrc-oldcli.py
743 744 745 746 747
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
    echo "OS_IDENTITY_API_VERSION=3" >> $OURDIR/admin-openrc-oldcli.py
else
    echo "OS_IDENTITY_API_VERSION=2.0" >> $OURDIR/admin-openrc-oldcli.py
fi
748

749 750 751 752 753
#
# These trigger a bug with the openstack client -- it doesn't choose v2.0
# if they're set.
#
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
754 755 756 757 758 759 760
    if [ $OSVERSION -lt $OSMITAKA ]; then
	echo "export OS_PROJECT_DOMAIN_ID=default" > $OURDIR/admin-openrc-newcli.sh
	echo "export OS_USER_DOMAIN_ID=default" >> $OURDIR/admin-openrc-newcli.sh
    else
	echo "export OS_PROJECT_DOMAIN_NAME=default" > $OURDIR/admin-openrc-newcli.sh
	echo "export OS_USER_DOMAIN_NAME=default" >> $OURDIR/admin-openrc-newcli.sh
    fi
761 762 763 764 765
fi
echo "export OS_PROJECT_NAME=admin" >> $OURDIR/admin-openrc-newcli.sh
echo "export OS_TENANT_NAME=admin" >> $OURDIR/admin-openrc-newcli.sh
echo "export OS_USERNAME=${ADMIN_API}" >> $OURDIR/admin-openrc-newcli.sh
echo "export OS_PASSWORD=${ADMIN_API_PASS}" >> $OURDIR/admin-openrc-newcli.sh
766
echo "export OS_AUTH_URL=http://$CONTROLLER:${KADMINPORT}/${KAPISTR}" >> $OURDIR/admin-openrc-newcli.sh
767 768 769 770 771
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
    echo "export OS_IDENTITY_API_VERSION=3" >> $OURDIR/admin-openrc-newcli.sh
else
    echo "export OS_IDENTITY_API_VERSION=2.0" >> $OURDIR/admin-openrc-newcli.sh
fi
David Johnson's avatar
David Johnson committed
772 773 774
if [ $OSVERSION -ge $OSNEWTON ]; then
    echo "export OS_IMAGE_API_VERSION=2" >> $OURDIR/admin-openrc-newcli.sh
fi
775
if [ $OSVERSION -ge $OSQUEENS ]; then
776
    echo "export OS_AUTH_TYPE=password" >> $OURDIR/admin-openrc-newcli.sh
777
fi
David Johnson's avatar
David Johnson committed
778

779
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
780 781 782 783 784 785 786
    if [ $OSVERSION -lt $OSMITAKA ]; then
	echo "OS_PROJECT_DOMAIN_ID=\"default\"" > $OURDIR/admin-openrc-newcli.py
	echo "OS_USER_DOMAIN_ID=\"default\"" >> $OURDIR/admin-openrc-newcli.py
    else
	echo "OS_PROJECT_DOMAIN_NAME=\"default\"" > $OURDIR/admin-openrc-newcli.py
	echo "OS_USER_DOMAIN_NAME=\"default\"" >> $OURDIR/admin-openrc-newcli.py
    fi
787 788 789 790 791
fi
echo "OS_PROJECT_NAME=\"admin\"" >> $OURDIR/admin-openrc-newcli.py
echo "OS_TENANT_NAME=\"admin\"" >> $OURDIR/admin-openrc-newcli.py
echo "OS_USERNAME=\"${ADMIN_API}\"" >> $OURDIR/admin-openrc-newcli.py
echo "OS_PASSWORD=\"${ADMIN_API_PASS}\"" >> $OURDIR/admin-openrc-newcli.py
792
echo "OS_AUTH_URL=\"http://$CONTROLLER:${KADMINPORT}/${KAPISTR}\"" >> $OURDIR/admin-openrc-newcli.py
793 794 795 796 797
if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
    echo "OS_IDENTITY_API_VERSION=3" >> $OURDIR/admin-openrc-newcli.py
else
    echo "OS_IDENTITY_API_VERSION=2.0" >> $OURDIR/admin-openrc-newcli.py
fi
David Johnson's avatar
David Johnson committed
798 799 800
if [ $OSVERSION -ge $OSNEWTON ]; then
    echo "OS_IMAGE_API_VERSION=2" >> $OURDIR/admin-openrc-newcli.py
fi
801 802 803
if [ $OSVERSION -ge $OSQUEENS ]; then
    echo "OS_AUTH_TYPE='password'" >> $OURDIR/admin-openrc-newcli.py
fi
804

805 806 807 808 809 810 811
#
# From here on out, we need to be the adminapi user.
#
if [ $OSVERSION -eq $OSJUNO ]; then
    export OS_TENANT_NAME=admin
    export OS_USERNAME=${ADMIN_API}
    export OS_PASSWORD=${ADMIN_API_PASS}
812
    export OS_AUTH_URL=http://$CONTROLLER:${KADMINPORT}/${KAPISTR}
813 814 815 816 817

    ln -sf $OURDIR/admin-openrc-oldcli.sh $OURDIR/admin-openrc.sh
    ln -sf $OURDIR/admin-openrc-oldcli.py $OURDIR/admin-openrc.py
else
    if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
818 819 820 821 822 823 824
	if [ $OSVERSION -lt $OSMITAKA ]; then
	    export OS_PROJECT_DOMAIN_ID=default
	    export OS_USER_DOMAIN_ID=default
	else
	    export OS_PROJECT_DOMAIN_NAME=default
	    export OS_USER_DOMAIN_NAME=default
	fi
825 826 827 828 829
    fi
    export OS_PROJECT_NAME=admin
    export OS_TENANT_NAME=admin
    export OS_USERNAME=${ADMIN_API}
    export OS_PASSWORD=${ADMIN_API_PASS}
830
    export OS_AUTH_URL=http://${CONTROLLER}:${KADMINPORT}/${KAPISTR}
831 832 833 834 835 836 837 838 839
    if [ "x$KEYSTONEAPIVERSION" = "x3" ]; then
	export OS_IDENTITY_API_VERSION=3
    else
	export OS_IDENTITY_API_VERSION=2.0
    fi

    ln -sf $OURDIR/admin-openrc-newcli.sh $OURDIR/admin-openrc.sh
    ln -sf $OURDIR/admin-openrc-newcli.py $OURDIR/admin-openrc.py
fi
840

841 842 843 844
#
# Install the Image service
#
if [ -z "${GLANCE_DBPASS}" ]; then
845
    logtstart "glance"
846 847 848 849 850 851 852
    GLANCE_DBPASS=`$PSWDGEN`
    GLANCE_PASS=`$PSWDGEN`

    echo "create database glance" | mysql -u root --password="$DB_ROOT_PASS"
    echo "grant all privileges on glance.* to 'glance'@'localhost' identified by '$GLANCE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
    echo "grant all privileges on glance.* to 'glance'@'%' identified by '$GLANCE_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"

853 854 855 856 857
    if [ $OSVERSION -lt $OSKILO ]; then
	keystone user-create --name glance --pass $GLANCE_PASS
	keystone user-role-add --user glance --tenant service --role admin
	keystone service-create --name glance --type image \
	    --description "OpenStack Image Service"
858

859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
	keystone endpoint-create \
	    --service-id `keystone service-list | awk '/ image / {print $2}'` \
	    --publicurl http://$CONTROLLER:9292 \
	    --internalurl http://$CONTROLLER:9292 \
	    --adminurl http://$CONTROLLER:9292 \
	    --region $REGION
    else
	__openstack user create $DOMARG --password $GLANCE_PASS glance
	__openstack role add --user glance --project service admin
	__openstack service create --name glance \
	    --description "OpenStack Image Service" image

	if [ $KEYSTONEAPIVERSION -lt 3 ]; then
	    __openstack endpoint create \
		--publicurl http://$CONTROLLER:9292 \
		--internalurl http://$CONTROLLER:9292 \
		--adminurl http://$CONTROLLER:9292 \
		--region $REGION image
	else
	    __openstack endpoint create --region $REGION \
		image public http://$CONTROLLER:9292
	    __openstack endpoint create --region $REGION \
		image internal http://$CONTROLLER:9292
	    __openstack endpoint create --region $REGION \
		image admin http://$CONTROLLER:9292
	fi
    fi
886

887
    maybe_install_packages glance ${PYPKGPREFIX}-glanceclient
888

889
    crudini --set /etc/glance/glance-api.conf database connection \
890
	"${DBDSTRING}://glance:${GLANCE_DBPASS}@$CONTROLLER/glance"
891
    crudini --set /etc/glance/glance-api.conf DEFAULT auth_strategy keystone
892 893
    crudini --set /etc/glance/glance-api.conf DEFAULT verbose ${VERBOSE_LOGGING}
    crudini --set /etc/glance/glance-api.conf DEFAULT debug ${DEBUG_LOGGING}
894 895 896 897 898 899
    crudini --set /etc/glance/glance-api.conf paste_deploy flavor keystone

    if [ $OSVERSION -eq $OSJUNO ]; then
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    auth_uri http://${CONTROLLER}:5000/${KAPISTR}
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
900
	    identity_uri http://${CONTROLLER}:${KADMINPORT}
901 902 903 904 905 906 907
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    admin_tenant_name service
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    admin_user glance
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    admin_password "${GLANCE_PASS}"
    else
908 909
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    ${AUTH_URI_KEY} http://${CONTROLLER}:5000
910
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
911
	    auth_url http://${CONTROLLER}:${KADMINPORT}
912
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
913
	    ${AUTH_TYPE_PARAM} password
914
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
915
	    ${PROJECT_DOMAIN_PARAM} default
916
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
917
	    ${USER_DOMAIN_PARAM} default
918 919 920 921 922 923 924 925 926
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    project_name service
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    username glance
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    password "${GLANCE_PASS}"
	crudini --set /etc/glance/glance-api.conf glance_store default_store file
	crudini --set /etc/glance/glance-api.conf glance_store \
	    filesystem_store_datadir /var/lib/glance/images/
David Johnson's avatar
David Johnson committed
927
	#crudini --set /etc/glance/glance-api.conf DEFAULT notification_driver noop
David Johnson's avatar
David Johnson committed
928 929 930
	if [ $OSVERSION -ge $OSNEWTON ]; then
	    crudini --set /etc/glance/glance-api.conf glance_store stores file,http
	fi
931
    fi
932 933 934 935
    if [ $OSVERSION -ge $OSMITAKA -o $KEYSTONEUSEMEMCACHE -eq 1 ]; then
	crudini --set /etc/glance/glance-api.conf keystone_authtoken \
	    memcached_servers ${CONTROLLER}:11211
    fi
936

937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957
    if [ $OSVERSION -lt $OSSTEIN ]; then
	crudini --set /etc/glance/glance-registry.conf database \
	    connection "${DBDSTRING}://glance:${GLANCE_DBPASS}@$CONTROLLER/glance"
	crudini --set /etc/glance/glance-registry.conf DEFAULT auth_strategy keystone
	crudini --set /etc/glance/glance-registry.conf DEFAULT verbose ${VERBOSE_LOGGING}
	crudini --set /etc/glance/glance-registry.conf DEFAULT debug ${DEBUG_LOGGING}
	crudini --set /etc/glance/glance-registry.conf paste_deploy flavor keystone

	if [ $OSVERSION -eq $OSJUNO ]; then
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        auth_uri http://${CONTROLLER}:5000/${KAPISTR}
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
		identity_uri http://${CONTROLLER}:${KADMINPORT}
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        admin_tenant_name service
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        admin_user glance
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        admin_password "${GLANCE_PASS}"
	else
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
958
	        ${AUTH_URI_KEY} http://${CONTROLLER}:5000
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
		auth_url http://${CONTROLLER}:${KADMINPORT}
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        ${AUTH_TYPE_PARAM} password
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        ${PROJECT_DOMAIN_PARAM} default
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        ${USER_DOMAIN_PARAM} default
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        project_name service
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        username glance
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        password "${GLANCE_PASS}"
	    #crudini --set /etc/glance/glance-registry.conf DEFAULT notification_driver noop
	fi
	if [ $OSVERSION -ge $OSMITAKA -o $KEYSTONEUSEMEMCACHE -eq 1 ]; then
	    crudini --set /etc/glance/glance-registry.conf keystone_authtoken \
	        memcached_servers ${CONTROLLER}:11211
	fi
979
    fi
980 981 982

    su -s /bin/sh -c "/usr/bin/glance-manage db_sync" glance

983 984 985
    #
    # Possibly create a larger image storage space.
    #
986
    if [ -n "$GLANCE_LV_SIZE" -a ! $GLANCE_LV_SIZE = 0 ]; then
987 988 989
	if [ $OSVERSION -lt $OSSTEIN ]; then
	    service_stop glance-registry
	fi
990 991 992 993 994 995 996 997 998
	service_stop glance-api

	$DIRNAME/setup-extra-space.sh
	. $LOCALSETTINGS
	mkdir -p ${STORAGEDIR}/glance
	chown glance:glance ${STORAGEDIR}/glance
	chmod 770 ${STORAGEDIR}/glance

	if [ $LVM = 1 ]; then
999
	    lvcreate -L ${GLANCE_LV_SIZE}G -n glance $VGNAME
1000 1001 1002 1003 1004 1005 1006 1007
	    if [ -f /sbin/mkfs.ext4 ]; then
		ftype=ext4
	    else
		ftype=ext3
	    fi
	    mkfs.${ftype} /dev/$VGNAME/glance
	    echo "/dev/$VGNAME/glance ${STORAGEDIR}/glance none defaults 0 0" \
	        >> /etc/fstab
1008
	    mount /dev/$VGNAME/glance ${STORAGEDIR}/glance
1009 1010 1011 1012 1013 1014 1015 1016
	fi
	rsync -avz /var/lib/glance/ ${STORAGEDIR}/glance/
	rm -rf /var/lib/glance/*
	mount -o bind ${STORAGEDIR}/glance /var/lib/glance
	echo "${STORAGEDIR}/glance /var/lib/glance none defaults,bind 0 0" \
	    >> /etc/fstab
    fi

1017 1018 1019 1020
    if [ $OSVERSION -lt $OSSTEIN ]; then
	service_restart glance-registry
	service_enable glance-registry
    fi
1021 1022
    service_restart glance-api
    service_enable glance-api
1023 1024 1025 1026
    rm -f /var/lib/glance/glance.sqlite

    echo "GLANCE_DBPASS=\"${GLANCE_DBPASS}\"" >> $SETTINGS
    echo "GLANCE_PASS=\"${GLANCE_PASS}\"" >> $SETTINGS
1027 1028

    logtend "glance"
1029 1030 1031 1032 1033 1034
fi

#
# Install the Compute service on the controller
#
if [ -z "${NOVA_DBPASS}" ]; then
1035
    logtstart "nova"
1036 1037 1038
    NOVA_DBPASS=`$PSWDGEN`
    NOVA_PASS=`$PSWDGEN`

1039
    # Make sure we're consistent with the clients
1040
    maybe_install_packages nova-api
1041

1042 1043 1044 1045
    echo "create database nova" | mysql -u root --password="$DB_ROOT_PASS"
    echo "grant all privileges on nova.* to 'nova'@'localhost' identified by '$NOVA_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
    echo "grant all privileges on nova.* to 'nova'@'%' identified by '$NOVA_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"

1046 1047 1048 1049 1050 1051
    if [ $OSVERSION -ge $OSMITAKA ]; then
	echo "create database nova_api" | mysql -u root --password="$DB_ROOT_PASS"
	echo "grant all privileges on nova_api.* to 'nova'@'localhost' identified by '$NOVA_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
	echo "grant all privileges on nova_api.* to 'nova'@'%' identified by '$NOVA_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
    fi

1052 1053 1054 1055 1056 1057
    if [ $OSVERSION -ge $OSOCATA ]; then
	echo "create database nova_cell0" | mysql -u root --password="$DB_ROOT_PASS"
	echo "grant all privileges on nova_cell0.* to 'nova'@'localhost' identified by '$NOVA_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
	echo "grant all privileges on nova_cell0.* to 'nova'@'%' identified by '$NOVA_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
    fi

1058 1059 1060 1061
    if [ $OSVERSION -ge $OSROCKY ]; then
	PLACEMENT_DBPASS=`$PSWDGEN`
	echo "create database placement" | mysql -u root --password="$DB_ROOT_PASS"
	echo "grant all privileges on placement.* to 'placement'@'localhost' identified by '$PLACEMENT_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
David Johnson's avatar
David Johnson committed
1062
	echo "grant all privileges on placement.* to 'placement'@'%' identified by '$PLACEMENT_DBPASS'" | mysql -u root --password="$DB_ROOT_PASS"
1063 1064
    fi

1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
    if [ $OSVERSION -eq $OSJUNO ]; then
	keystone user-create --name nova --pass $NOVA_PASS
	keystone user-role-add --user nova --tenant service --role admin
	keystone service-create --name nova --type compute \
	    --description "OpenStack Compute Service"
	keystone endpoint-create \
	    --service-id `keystone service-list | awk '/ compute / {print $2}'` \
	    --publicurl http://$CONTROLLER:8774/v2/%\(tenant_id\)s \
	    --internalurl http://$CONTROLLER:8774/v2/%\(tenant_id\)s \
	    --adminurl http://$CONTROLLER:8774/v2/%\(tenant_id\)s \
	    --region $REGION
    else
	__openstack user create $DOMARG --password $NOVA_PASS nova
	__openstack role add --user nova --project service admin
	__openstack service create --name nova \
	    --description "OpenStack Compute Service" compute

	if [ $KEYSTONEAPIVERSION -lt 3 ]; then
	    __openstack endpoint create \
David Johnson's avatar
David Johnson committed
1084 1085 1086
		--publicurl http://$CONTROLLER:8774/${NAPISTR}/%\(tenant_id\)s \
		--internalurl http://$CONTROLLER:8774/${NAPISTR}/%\(tenant_id\)s \
		--adminurl http://$CONTROLLER:8774/${NAPISTR}/%\(tenant_id\)s \
1087
		--region $REGION compute
1088
	elif [ $OSVERSION -lt $OSNEWTON ]; then
1089
	    __openstack endpoint create --region $REGION \
David Johnson's avatar
David Johnson committed
1090
		compute public http://${CONTROLLER}:8774/${NAPISTR}/%\(tenant_id\)s
1091
	    __openstack endpoint create --region $REGION \
David Johnson's avatar
David Johnson committed
1092
		compute internal http://${CONTROLLER}:8774/${NAPISTR}/%\(tenant_id\)s
1093
	    __openstack endpoint create --region $REGION \
David Johnson's avatar
David Johnson committed
1094
		compute admin http://${CONTROLLER}:8774/${NAPISTR}/%\(tenant_id\)s
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110
	else
	    __openstack endpoint create --region $REGION \
		compute public http://${CONTROLLER}:8774/${NAPISTR}
	    __openstack endpoint create --region $REGION \
		compute internal http://${CONTROLLER}:8774/${NAPISTR}
	    __openstack endpoint create --region $REGION \
		compute admin http://${CONTROLLER}:8774/${NAPISTR}
	fi

	if [ $OSVERSION -ge $OSOCATA ]; then
	    PLACEMENT_PASS=`$PSWDGEN`
	    __openstack user create $DOMARG --password $PLACEMENT_PASS placement
	    __openstack role add --user placement --project service admin
	    __openstack service create --name placement \
	        --description "OpenStack Placement API" placement

1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
	    if [ $KEYSTONEAPIVERSION -lt 3 ]; then
		__openstack endpoint create \
		    --publicurl http://$CONTROLLER:8778 \
		    --internalurl http://$CONTROLLER:8778 \
		    --adminurl http://$CONTROLLER:8778 \
		    --region $REGION placement
	    elif [ $OSVERSION -lt $OSNEWTON ]; then
		__openstack endpoint create --region $REGION \
		    placement public http://${CONTROLLER}:8778
		__openstack endpoint create --region $REGION \
		    placement internal http://${CONTROLLER}:8778
		__openstack endpoint create --region $REGION \
		    placement admin http://${CONTROLLER}:8778
	    else
		__openstack endpoint create --region $REGION \
		    placement public http://${CONTROLLER}:8778
		__openstack endpoint create --region $REGION \
		    placement internal http://${CONTROLLER}:8778
		__openstack endpoint create --region $REGION \
		    placement admin http://${CONTROLLER}:8778
	    fi
1132 1133
	fi
    fi
1134

1135
    maybe_install_packages nova-api nova-conductor nova-consoleauth \
1136
	nova-novncproxy nova-scheduler ${PYPKGPREFIX}-novaclient
1137 1138 1139
    if [ $OSVERSION -lt $OSQUEENS ]; then
	maybe_install_packages nova-cert
    fi
1140 1141 1142 1143
    if [ $OSVERSION -ge $OSOCATA ]; then
	maybe_install_packages nova-placement-api
    fi
    
David Johnson's avatar
David Johnson committed
1144
    if [ ${ENABLE_NEW_SERIAL_SUPPORT} = 1 ]; then
1145
	maybe_install_packages nova-serialproxy
David Johnson's avatar
David Johnson committed
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
	mkdir -p $OURDIR/src
	( cd $OURDIR/src && git clone https://github.com/larsks/novaconsole )
	( cd $OURDIR/src && git clone https://github.com/liris/websocket-client )
	cat <<EOF > $OURDIR/novaconsole.sh
#!/bin/sh
source $OURDIR/admin-openrc.sh
export PYTHONPATH=$OURDIR/src/websocket-client:$OURDIR/src/novaconsole
exec $OURDIR/src/novaconsole/novaconsole/main.py $@
EOF
	chmod ug+x $OURDIR/novaconsole.sh
    fi

1158 1159 1160 1161 1162 1163
    # XXX: Liberty/Mitaka must have lost ec2 stuff by default?
    if [ $OSVERSION -ge $OSLIBERTY ]; then
	crudini --set /etc/nova/nova.conf \
	    DEFAULT enabled_apis osapi_compute,metadata
    fi

1164
    crudini --set /etc/nova/nova.conf database connection \
1165
	"${DBDSTRING}://nova:$NOVA_DBPASS@$CONTROLLER/nova"
1166 1167
    if [ $OSVERSION -ge $OSMITAKA ]; then
	crudini --set /etc/nova/nova.conf api_database connection \
1168
	    "${DBDSTRING}://nova:$NOVA_DBPASS@$CONTROLLER/nova_api"
1169
    fi
1170 1171
    if [ $OSVERSION -ge $OSROCKY ]; then
	crudini --set /etc/nova/nova.conf placement_database connection \
David Johnson's avatar
David Johnson committed
1172
	    "${DBDSTRING}://placement:$PLACEMENT_DBPASS@$CONTROLLER/placement"
1173
    fi
1174 1175
    crudini --set /etc/nova/nova.conf DEFAULT auth_strategy keystone
    crudini --set /etc/nova/nova.conf DEFAULT my_ip ${MGMTIP}
1176 1177 1178 1179 1180 1181
    if [ $OSVERSION -lt $OSMITAKA ]; then
	crudini --set /etc/nova/nova.conf glance host $CONTROLLER
    else
	crudini --set /etc/nova/nova.conf \
	    glance api_servers http://${CONTROLLER}:9292
    fi
1182 1183 1184 1185
    crudini --set /etc/nova/nova.conf DEFAULT verbose ${VERBOSE_LOGGING}
    crudini --set /etc/nova/nova.conf DEFAULT debug ${DEBUG_LOGGING}

    if [ $OSVERSION -lt $OSKILO ]; then
1186
	crudini --set /etc/nova/nova.conf DEFAULT rpc_backend rabbit
1187 1188 1189
	crudini --set /etc/nova/nova.conf DEFAULT rabbit_host $CONTROLLER
	crudini --set /etc/nova/nova.conf DEFAULT rabbit_userid ${RABBIT_USER}
	crudini --set /etc/nova/nova.conf DEFAULT rabbit_password "${RABBIT_PASS}"
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
    elif [ $OSVERSION -lt $OSNEWTON ]; then
	crudini --set /etc/nova/nova.conf DEFAULT rpc_backend rabbit
	crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
	    rabbit_host $CONTROLLER
	crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
	    rabbit_userid ${RABBIT_USER}
	crudini --set /etc/nova/nova.conf oslo_messaging_rabbit \
	    rabbit_password "${RABBIT_PASS}"
    else
	crudini --set /etc/nova/nova.conf DEFAULT transport_url $RABBIT_URL
    fi
1201

1202
    if [ $OSVERSION -lt $OSKILO ]; then
1203 1204 1205
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    auth_uri http://${CONTROLLER}:5000/${KAPISTR}
	crudini --set /etc/nova/nova.conf keystone_authtoken \
1206
	    identity_uri http://${CONTROLLER}:${KADMINPORT}
1207 1208 1209 1210 1211 1212 1213
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    admin_tenant_name service
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    admin_user nova
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    admin_password "${NOVA_PASS}"
    else
1214 1215
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    ${AUTH_URI_KEY} http://${CONTROLLER}:5000
1216
	crudini --set /etc/nova/nova.conf keystone_authtoken \
1217
	    auth_url http://${CONTROLLER}:${KADMINPORT}
1218
	crudini --set /etc/nova/nova.conf keystone_authtoken \
1219
	    ${AUTH_TYPE_PARAM} password
1220
	crudini --set /etc/nova/nova.conf keystone_authtoken \
1221
	    ${PROJECT_DOMAIN_PARAM} default
1222
	crudini --set /etc/nova/nova.conf keystone_authtoken \
1223
	    ${USER_DOMAIN_PARAM} default
1224 1225 1226 1227 1228 1229
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    project_name service
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    username nova
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    password "${NOVA_PASS}"
1230
    fi
1231

1232 1233 1234 1235
    if [ $OSVERSION -ge $OSMITAKA -o $KEYSTONEUSEMEMCACHE -eq 1 ]; then
	crudini --set /etc/nova/nova.conf keystone_authtoken \
	    memcached_servers ${CONTROLLER}:11211
    fi
1236

1237 1238 1239 1240
    if [ $OSVERSION -ge $OSMITAKA ]; then
	crudini --set /etc/nova/nova.conf DEFAULT use_neutron True
	crudini --set /etc/nova/nova.conf \
	    DEFAULT firewall_driver nova.virt.firewall.NoopFirewallDriver
1241
    fi
1242

1243 1244 1245
    if [ $OSVERSION -lt $OSLIBERTY ]; then
	crudini --set /etc/nova/nova.conf DEFAULT vncserver_listen ${MGMTIP}
	crudini --set /etc/nova/nova.conf DEFAULT vncserver_proxyclient_address ${MGMTIP}
1246
    elif [ $OSVERSION -lt $OSQUEENS ]; then
1247 1248
	crudini --set /etc/nova/nova.conf vnc vncserver_listen ${MGMTIP}
	crudini --set /etc/nova/nova.conf vnc vncserver_proxyclient_address ${MGMTIP}
1249 1250 1251 1252
    else
	crudini --set /etc/nova/nova.conf vnc enabled true
	crudini --set /etc/nova/nova.conf vnc server_listen ${MGMTIP}
	crudini --set /etc/nova/nova.conf vnc server_proxyclient_address ${MGMTIP}
1253
    fi
1254 1255 1256 1257 1258
    #
    # consoleauth is being deprecated as of Rocky.
    #
    # https://docs.openstack.org/nova/rocky/configuration/config.html#workarounds.enable_consoleauth
    if [ $OSVERSION -ge $OSROCKY ]; then
David Johnson's avatar
David Johnson committed
1259
	crudini --set /etc/nova/nova.conf workarounds enable_consoleauth true
1260
    fi
1261

1262 1263 1264 1265 1266 1267 1268 1269 1270 1271
    #
    # Apparently on Kilo and before, the default filters did not include
    # DiskFilter, but in Liberty it does.  This causes us problems for
    # our small root partition :).
    #
    if [ $OSVERSION -eq $OSKILO ]; then
	crudini --set /etc/nova/nova.conf DEFAULT scheduler_available_filters \
	    nova.scheduler.filters.all_filters
	crudini --set /etc/nova/nova.conf DEFAULT scheduler_default_filters \
	    'RetryFilter, AvailabilityZoneFilter, RamFilter, ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter, ServerGroupAntiAffinityFilter, ServerGroupAffinityFilter'
David Johnson's avatar
David Johnson committed
1272
    elif [ $OSVERSION -ge $OSLIBERTY -a $OSVERSION -lt $OSOCATA ]; then
1273 1274 1275 1276
	crudini --set /etc/nova/nova.conf DEFAULT scheduler_available_filters \
	    nova.scheduler.filters.all_filters
	crudini --set /etc/nova/nova.conf DEFAULT scheduler_default_filters \
	    'RetryFilter, AvailabilityZoneFilter, RamFilter, ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter, ServerGroupAntiAffinityFilter, ServerGroupAffinityFilter'
David Johnson's avatar
David Johnson committed
1277 1278 1279 1280 1281
    elif [ $OSVERSION -ge $OSOCATA ]; then
	crudini --set /etc/nova/nova.conf filter_scheduler available_filters \
	    nova.scheduler.filters.all_filters
	crudini --set /etc/nova/nova.conf filter_scheduler enabled_filters \
	    'RetryFilter, AvailabilityZoneFilter, RamFilter, ComputeFilter, ComputeCapabilitiesFilter, ImagePropertiesFilter, ServerGroupAntiAffinityFilter, ServerGroupAffinityFilter'
1282
    fi
1283

1284 1285 1286 1287
    if [ $OSVERSION -ge $OSKILO ]; then
	crudini --set /etc/nova/nova.conf oslo_concurrency \
	    lock_path /var/lib/nova/tmp
    fi
1288

David Johnson's avatar
David Johnson committed
1289
    if [ ${ENABLE_NEW_SERIAL_SUPPORT} = 1 ]; then
1290
	crudini --set /etc/nova/nova.conf serial_console enabled true
David Johnson's avatar
David Johnson committed
1291 1292
    fi