Auto rebuild for xenial-mitaka
[openstack-build/cinder-build.git] / trusty / debian / cinder-api.postinst.in
1 #!/bin/sh
2
3 set -e
4
5 #PKGOS-INCLUDE#
6
7 if [ "$1" = "configure" ] || [ "$1" = "reconfigure" ] ; then
8         . /usr/share/debconf/confmodule
9
10         # We need special handling for Cinder, as it needs 2 endpoints
11         PKG_NAME=cinder
12         db_get ${PKG_NAME}/register-endpoint
13         if [ "${RET}" = "true" ] ; then
14                 # Setup the v1 endpoint
15                 db_get ${PKG_NAME}/keystone-ip
16                 KEYSTONE_ENDPOINT_IP=`echo ${RET} | egrep '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'`
17                 db_get ${PKG_NAME}/endpoint-ip
18                 PKG_ENDPOINT_IP=`echo ${RET} | egrep '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'`
19                 db_get ${PKG_NAME}/region-name
20                 REGION_NAME=${RET}
21                 db_get ${PKG_NAME}/keystone-project-name
22                 KEYSTONE_PROJECT_NAME=${RET}
23                 db_get ${PKG_NAME}/keystone-admin-name
24                 KEYSTONE_ADMIN_NAME=${RET}
25                 db_get ${PKG_NAME}/keystone-admin-password
26                 KEYSTONE_ADMIN_PASSWORD=${RET}
27
28                 if [ -n "${KEYSTONE_ENDPOINT_IP}" ] && [ -n "${PKG_ENDPOINT_IP}" ] && [ -n "${REGION_NAME}" ] && [ -n "${KEYSTONE_PROJECT_NAME}" ] && [ -n "${KEYSTONE_ADMIN_NAME}" ]  && [ -n "${KEYSTONE_ADMIN_PASSWORD}" ] ; then
29                         export OS_PROJECT_DOMAIN_ID=default
30                         export OS_USER_DOMAIN_ID=default
31                         export OS_TENANT_NAME=${KEYSTONE_PROJECT_NAME}
32                         export OS_PROJECT_NAME=${KEYSTONE_PROJECT_NAME}
33                         export OS_USERNAME=${KEYSTONE_ADMIN_NAME}
34                         export OS_PASSWORD=${KEYSTONE_ADMIN_PASSWORD}
35                         export OS_AUTH_URL=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/
36                         export OS_IDENTITY_API_VERSION=3
37                         export OS_AUTH_VERSION=3
38                         export OS_PROJECT_DOMAIN_ID=default
39                         export OS_USER_DOMAIN_ID=default
40                         export OS_NO_CACHE=1
41
42                         SERVICE_NAME=cinder
43                         SERVICE_TYPE=volume
44                         SERVICE_DESC="OpenStack Block Storage"
45                         SERVICE_PORT=8776
46                         SERVICE_URL=/v1/'%(tenant_id)s'
47                         echo "Registering service and endpoints for ${SERVICE_NAME} with type ${SERVICE_TYPE} at http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}"
48                         NUM_LINES=$(openstack service list --format=csv | q -d , -H 'SELECT ID FROM - WHERE `Type`="'${SERVICE_TYPE}'"' | wc -l)
49                         if [ "${NUM_LINES}" = "0" ] ; then
50                                 openstack service create --name=${SERVICE_NAME} --description="${SERVICE_DESC}" ${SERVICE_TYPE}
51                                 openstack endpoint create --region "${REGION_NAME}" ${SERVICE_NAME} public   http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
52                                 openstack endpoint create --region "${REGION_NAME}" ${SERVICE_NAME} internal http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
53                                 openstack endpoint create --region "${REGION_NAME}" ${SERVICE_NAME} admin    http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
54                         fi
55
56                         SERVICE_NAME=cinderv2
57                         SERVICE_TYPE=volumev2
58                         SERVICE_DESC="OpenStack Block Storage v2"
59                         SERVICE_PORT=8776
60                         SERVICE_URL=/v2/'%(tenant_id)s'
61                         echo "Registering service and endpoints for ${SERVICE_NAME} with type ${SERVICE_TYPE} at http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}"
62                         NUM_LINES=$(openstack service list --format=csv | q -d , -H 'SELECT ID FROM - WHERE `Type`="'${SERVICE_TYPE}'"' | wc -l)
63                         if [ "${NUM_LINES}" = "0" ] ; then
64                                 openstack service create --name=${SERVICE_NAME} --description="${SERVICE_DESC}" ${SERVICE_TYPE}
65                                 openstack endpoint create --region "${REGION_NAME}" ${SERVICE_NAME} public   http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
66                                 openstack endpoint create --region "${REGION_NAME}" ${SERVICE_NAME} internal http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
67                                 openstack endpoint create --region "${REGION_NAME}" ${SERVICE_NAME} admin    http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
68                         fi
69 #                       pkgos_register_endpoint_postinst cinder cinder volume "Cinder Volume Service" 8776 /v1/'%(tenant_id)s'
70 #                       pkgos_register_endpoint_postinst cinder cinderv2 volumev2 "Cinder Volume Service" 8776 /v2/'%(tenant_id)s'
71                 else
72                         echo "Problem in endpoint parameter (IPs or otherwise)."
73                 fi
74                 db_unregister ${PKG_NAME}/register-endpoint
75         else
76                 echo "Will not register "${SERVICE_NAME}" endpoint this time (no user request for it)."
77         fi
78         db_unregister ${PKG_NAME}/keystone-admin-password
79         db_stop
80 fi
81
82 #DEBHELPER#
83
84 exit 0