]> review.fuel-infra Code Review - openstack-build/cinder-build.git/blob - trusty/debian/cinder-api.postinst.in
cinder 8.0.0-1 updated for Mitaka 9.0
[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}/keystone-auth-token
18                 AUTH_TOKEN=${RET}
19                 db_get ${PKG_NAME}/endpoint-ip
20                 PKG_ENDPOINT_IP=`echo ${RET} | egrep '^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$'`
21                 db_get ${PKG_NAME}/region-name
22                 REGION_NAME=${RET}
23
24                 if [ -n "${KEYSTONE_ENDPOINT_IP}" ] && [ -n "${PKG_ENDPOINT_IP}" ] && [ -n "${REGION_NAME}" ] && [ -n "${AUTH_TOKEN}" ] ; then
25                         SERVICE_NAME=cinder
26                         SERVICE_TYPE=volume
27                         SERVICE_DESC="OpenStack Block Storage"
28                         SERVICE_PORT=8776
29                         SERVICE_URL=/v1/'%(tenant_id)s'
30                         echo "Registering service and endpoints for ${SERVICE_NAME} with type ${SERVICE_TYPE} at http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}"
31                         NUM_LINES=$(openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 service list --format=csv | q -d , -H 'SELECT ID FROM - WHERE `Type`="'${SERVICE_TYPE}'"' | wc -l)
32                         if [ "${NUM_LINES}" = "0" ] ; then
33                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 service create \
34                                         --name=${SERVICE_NAME} --description="${SERVICE_DESC}" ${SERVICE_TYPE}
35
36                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 endpoint create \
37                                         --region "${REGION_NAME}" ${SERVICE_NAME} public http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
38
39                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 endpoint create \
40                                         --region "${REGION_NAME}" ${SERVICE_NAME} internal http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
41
42                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 endpoint create \
43                                         --region "${REGION_NAME}" ${SERVICE_NAME} admin http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
44                         fi
45
46                         SERVICE_NAME=cinderv2
47                         SERVICE_TYPE=volumev2
48                         SERVICE_DESC="OpenStack Block Storage v2"
49                         SERVICE_PORT=8776
50                         SERVICE_URL=/v2/'%(tenant_id)s'
51                         echo "Registering service and endpoints for ${SERVICE_NAME} with type ${SERVICE_TYPE} at http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}"
52                         NUM_LINES=$(openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 service list --format=csv | q -d , -H 'SELECT ID FROM - WHERE `Type`="'${SERVICE_TYPE}'"' | wc -l)
53                         if [ "${NUM_LINES}" = "0" ] ; then
54                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 service create \
55                                         --name=${SERVICE_NAME} --description="${SERVICE_DESC}" ${SERVICE_TYPE}
56
57                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 endpoint create \
58                                         --region "${REGION_NAME}" ${SERVICE_NAME} public http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
59
60                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 endpoint create \
61                                         --region "${REGION_NAME}" ${SERVICE_NAME} internal http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
62
63                                 openstack --os-token ${AUTH_TOKEN} --os-url=http://${KEYSTONE_ENDPOINT_IP}:35357/v3/ --os-domain-name default --os-identity-api-version=3 endpoint create \
64                                         --region "${REGION_NAME}" ${SERVICE_NAME} admin http://${PKG_ENDPOINT_IP}:${SERVICE_PORT}${SERVICE_URL}
65                         fi
66 #                       pkgos_register_endpoint_postinst cinder cinder volume "Cinder Volume Service" 8776 /v1/'%(tenant_id)s'
67 #                       pkgos_register_endpoint_postinst cinder cinderv2 volumev2 "Cinder Volume Service" 8776 /v2/'%(tenant_id)s'
68                 else
69                         echo "Problem in endpoint parameter (IPs or otherwise)."
70                 fi
71                 db_unregister ${PKG_NAME}/register-endpoint
72         else
73                 echo "Will not register "${SERVICE_NAME}" endpoint this time (no user request for it)."
74         fi
75         db_unregister ${PKG_NAME}/keystone-auth-token
76         db_stop
77 fi
78
79 #DEBHELPER#
80
81 exit 0