#!/bin/sh set -e CONF=/etc/magnum/magnum.conf #PKGOS-INCLUDE# create_magnum_domain () { local ADMIN_USER ADMIN_PASS NO_PROTO AFTER_PORT WRITE_CRED_URL WRITE_CRED_PROTO ADMIN_USER=${1} ADMIN_PASS=${2} db_get magnum/ksat-public-url KEYSTONE_PUBLIC_ENDPOINT=${RET} # Should we create a new keystone user? db_get magnum/ksat-create-service-user if [ "${RET}" = "true" ] ; then # Set command line credentials export OS_USERNAME=${ADMIN_USER} db_get magnum/ksat-admin-project-name export OS_TENANT_NAME=${RET} export OS_PROJECT_NAME=${RET} export OS_PASSWORD=${ADMIN_PASS} export OS_AUTH_URL=${KEYSTONE_PUBLIC_ENDPOINT} export OS_IDENTITY_API_VERSION=3 export OS_PROJECT_DOMAIN_ID=default export OS_USER_DOMAIN_ID=default export OS_AUTH_TYPE=password db_get magnum/magnum_domain_name if [ -n "${RET}" ] ; then MAGNUM_DOMAIN_NAME=${RET} fi echo "===> magnum-common: Creating domain ${MAGNUM_DOMAIN_NAME} ..." openstack domain create --or-show --description "Owns users and projects created by magnum" ${MAGNUM_DOMAIN_NAME} fi } write_admin_creds () { local WRITE_CRED_CONF_FNAME WRITE_CRED_PKG_NAME WRITE_CRED_SECTION NO_PROTO AFTER_PORT WRITE_CRED_URL WRITE_CRED_PROTO WRITE_CRED_CONF_FNAME=${1} WRITE_CRED_SECTION_KSAT=${2} WRITE_CRED_SECTION_MAGNUM=${3} WRITE_CRED_PKG_NAME=${4} db_get ${WRITE_CRED_PKG_NAME}/configure_ksat if [ "${RET}" = "true" ] ; then db_get ${WRITE_CRED_PKG_NAME}/ksat-public-url KEYSTONE_PUBLIC_ENDPOINT=${RET} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_KSAT} www_authenticate_uri ${KEYSTONE_PUBLIC_ENDPOINT} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_MAGNUM} www_authenticate_uri ${KEYSTONE_PUBLIC_ENDPOINT} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_KSAT} auth_uri ${KEYSTONE_PUBLIC_ENDPOINT} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_MAGNUM} auth_uri ${KEYSTONE_PUBLIC_ENDPOINT} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_KSAT} auth_url ${KEYSTONE_PUBLIC_ENDPOINT} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_MAGNUM} auth_url ${KEYSTONE_PUBLIC_ENDPOINT} db_get ${WRITE_CRED_PKG_NAME}/ksat-region pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_KSAT} region_name ${RET} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_MAGNUM} region_name ${RET} db_get ${WRITE_CRED_PKG_NAME}/ksat-service-username SERVICE_USERNAME=${RET} db_get ${WRITE_CRED_PKG_NAME}/ksat-service-project-name SERVICE_PROJECTNAME=${RET} db_get ${WRITE_CRED_PKG_NAME}/ksat-service-password SERVICE_PASSWORD=${RET} # Should we create a new keystone user? db_get ${WRITE_CRED_PKG_NAME}/ksat-create-service-user if [ "${RET}" = "true" ] ; then # Set command line credentials db_get ${WRITE_CRED_PKG_NAME}/ksat-admin-username export OS_USERNAME=${RET} db_get ${WRITE_CRED_PKG_NAME}/ksat-admin-project-name export OS_TENANT_NAME=${RET} export OS_PROJECT_NAME=${RET} db_get ${WRITE_CRED_PKG_NAME}/ksat-admin-password export OS_PASSWORD=${RET} export OS_AUTH_URL=${KEYSTONE_PUBLIC_ENDPOINT} export OS_IDENTITY_API_VERSION=3 export OS_PROJECT_DOMAIN_ID=default export OS_USER_DOMAIN_ID=default export OS_AUTH_TYPE=password # And create that new service user with role admin echo "Creating project ${SERVICE_PROJECTNAME} ..." openstack project create --or-show ${SERVICE_PROJECTNAME} --description "Debian service project" echo "Creating user ${SERVICE_USERNAME} ..." openstack user create --or-show --password ${SERVICE_PASSWORD} --project ${SERVICE_PROJECTNAME} --email root@localhost --enable ${SERVICE_USERNAME} # This should not be needed right now, so removing it... # Edit: This is not truth, admin role is needed, it is also documented in documentation {kevko} echo "Adding role admin to the user ${SERVICE_USERNAME}" openstack role add --project ${SERVICE_PROJECTNAME} --user ${SERVICE_USERNAME} admin # Edit : This is bad >> {kevko} #echo "Adding role service to the user ${SERVICE_USERNAME} ..." #openstack role add --project ${SERVICE_PROJECTNAME} --user ${SERVICE_USERNAME} service fi echo "===> opensatck-pkg-tools: writing ${WRITE_CRED_SECTION_KSAT} credentials for user ${SERVICE_USERNAME} and project ${SERVICE_PROJECTNAME} ..." echo "===> opensatck-pkg-tools: writing ${WRITE_CRED_SECTION_MAGNUM} credentials for user ${SERVICE_USERNAME} and project ${SERVICE_PROJECTNAME} ..." pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_KSAT} username ${SERVICE_USERNAME} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_MAGNUM} username ${SERVICE_USERNAME} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_KSAT} project_name ${SERVICE_PROJECTNAME} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_MAGNUM} project_name ${SERVICE_PROJECTNAME} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_KSAT} password ${SERVICE_PASSWORD} pkgos_inifile set ${WRITE_CRED_CONF_FNAME} ${WRITE_CRED_SECTION_MAGNUM} password ${SERVICE_PASSWORD} fi # For security reasons, we don't keep the auth-token in the debconf # memory, so we purge it with db_unregister. db_unregister ${WRITE_CRED_PKG_NAME}/ksat-admin-password # Very likely, we don't want any upgrade to touch an already # working value of keystone_authtoken, so it's best to just # unregister this. db_unregister ${WRITE_CRED_PKG_NAME}/configure_ksat } create_magnum_domain_admin () { local ADMIN_USER ADMIN_PASS NO_PROTO AFTER_PORT WRITE_CRED_URL WRITE_CRED_PROTO ADMIN_USER=${1} ADMIN_PASS=${2} db_get magnum/ksat-public-url KEYSTONE_PUBLIC_ENDPOINT=${RET} # Should we create a new keystone user? db_get magnum/ksat-create-service-user if [ "${RET}" = "true" ] ; then # Set command line credentials export OS_USERNAME=${ADMIN_USER} db_get magnum/ksat-admin-project-name export OS_TENANT_NAME=${RET} export OS_PROJECT_NAME=${RET} export OS_PASSWORD=${ADMIN_PASS} export OS_AUTH_URL=${KEYSTONE_PUBLIC_ENDPOINT} export OS_IDENTITY_API_VERSION=3 export OS_PROJECT_DOMAIN_ID=default export OS_USER_DOMAIN_ID=default export OS_AUTH_TYPE=password db_get magnum/magnum_domain_admin_username if [ -n "${RET}" ] ; then MAGNUM_DOMAIN_ADMIN=${RET} fi db_get magnum/magnum_domain_admin_password if [ -n "${RET}" ] ; then MAGNUM_DOMAIN_ADMIN_PASS=${RET} fi db_get magnum/magnum_domain_name if [ -n "${RET}" ] ; then MAGNUM_DOMAIN_NAME=${RET} fi echo "===> magnum-common: Creating user ${MAGNUM_DOMAIN_ADMIN} ..." openstack user create --or-show --domain ${MAGNUM_DOMAIN_NAME} --password ${MAGNUM_DOMAIN_ADMIN_PASS} --email root@localhost --enable ${MAGNUM_DOMAIN_ADMIN} echo "===> magnum-common: Adding role domain admin to the user ${MAGNUM_DOMAIN_ADMIN} for domain ${MAGNUM_DOMAIN_NAME}" openstack role add --domain ${MAGNUM_DOMAIN_NAME} --user-domain ${MAGNUM_DOMAIN_NAME} --user ${MAGNUM_DOMAIN_ADMIN} admin fi } create_docker_volume_type () { local ADMIN_USER ADMIN_PASS NO_PROTO AFTER_PORT WRITE_CRED_URL WRITE_CRED_PROTO ADMIN_USER=${1} ADMIN_PASS=${2} db_get magnum/ksat-public-url KEYSTONE_PUBLIC_ENDPOINT=${RET} # Should we create a new keystone user? db_get magnum/ksat-create-service-user if [ "${RET}" = "true" ] ; then # Set command line credentials export OS_USERNAME=${ADMIN_USER} db_get magnum/ksat-admin-project-name export OS_TENANT_NAME=${RET} export OS_PROJECT_NAME=${RET} export OS_PASSWORD=${ADMIN_PASS} export OS_AUTH_URL=${KEYSTONE_PUBLIC_ENDPOINT} export OS_IDENTITY_API_VERSION=3 export OS_PROJECT_DOMAIN_ID=default export OS_USER_DOMAIN_ID=default export OS_AUTH_TYPE=password db_get magnum/default_docker_volume_type if [ -n "${RET}" ] ; then # --or-show not working , so we have to do workaround with show if ! openstack volume type show ${RET} > /dev/null; then echo "===> magnum-common: Creating cinder volume type ${RET} ..." openstack volume type create ${RET} --description "Cinder volume type used by magnum." else echo "===> magnum-common: Cinder volume type ${RET} already exist." fi pkgos_inifile set ${CONF} cinder default_docker_volume_type ${RET} fi fi } manage_trust_config () { db_get magnum/magnum_domain_admin_username pkgos_inifile set ${CONF} trust trustee_domain_admin_name ${RET} db_get magnum/magnum_domain_admin_password pkgos_inifile set ${CONF} trust trustee_domain_admin_password ${RET} db_get magnum/magnum_domain_name pkgos_inifile set ${CONF} trust trustee_domain_name ${RET} db_get magnum/keystone_interface pkgos_inifile set ${CONF} trust trustee_keystone_interface ${RET} } manage_cinder_os_region () { db_get magnum/cinder_os_region_name if [ -n "${RET}" ] ; then pkgos_inifile set ${CONF} cinder_client region_name ${RET} fi } if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ] ; then . /usr/share/debconf/confmodule . /usr/share/dbconfig-common/dpkg/postinst pkgos_var_user_group magnum pkgos_write_new_conf magnum magnum.conf if [ -r /etc/magnum/policy.json ] ; then mv /etc/magnum/policy.json /etc/magnum/disabled.policy.json.old fi pkgos_write_new_conf magnum api-paste.ini pkgos_write_new_conf magnum keystone_auth_default_policy.json pkgos_rabbit_write_conf ${CONF} oslo_messaging_rabbit magnum db_get magnum/configure_db if [ "$RET" = "true" ]; then pkgos_dbc_postinst ${CONF} database connection magnum $@ echo "Now calling magnum-db-manage: this may take a while..." su -s /bin/sh -c 'magnum-db-manage --config-file=/etc/magnum/magnum.conf upgrade' magnum fi db_get magnum/configure_ksat if [ "${RET}" = "true" ] ; then db_get magnum/ksat-admin-password ADMIN_PASS=${RET} db_get magnum/ksat-admin-username ADMIN_USER=${RET} db_get magnum/ksat-service-password SERVICE_PASS=${RET} write_admin_creds ${CONF} keystone_authtoken keystone_auth magnum db_get magnum/ksat-service-username SERVICE_USER=${RET} pkgos_inifile set ${CONF} keystone_authtoken admin_user ${SERVICE_USER} pkgos_inifile set ${CONF} keystone_authtoken admin_password ${SERVICE_PASS} pkgos_inifile set ${CONF} keystone_auth admin_user ${SERVICE_USER} pkgos_inifile set ${CONF} keystone_auth admin_password ${SERVICE_PASS} db_get magnum/ksat-service-project-name ADMIN_TENANT_NAME=${RET} pkgos_inifile set ${CONF} keystone_authtoken admin_tenant_name ${ADMIN_TENANT_NAME} pkgos_inifile set ${CONF} keystone_auth admin_tenant_name ${ADMIN_TENANT_NAME} create_magnum_domain ${ADMIN_USER} ${ADMIN_PASS} create_magnum_domain_admin ${ADMIN_USER} ${ADMIN_PASS} db_get magnum/create_volume_type if [ "${RET}" = "true" ] ; then create_docker_volume_type ${ADMIN_USER} ${ADMIN_PASS} fi fi db_get magnum/configure_with_debconf if [ "${RET}" = "true" ] ; then manage_trust_config manage_cinder_os_region fi db_unregister magnum/configure_with_debconf fi #DEBHELPER# exit 0