3 # Copyright (c) 2018 Huawei Technologies Co., Ltd. All Rights Reserved.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # 'stack' user is just for install keystone through devstack
20 if id "${STACK_USER_NAME}" &> /dev/null; then
23 sudo useradd -s /bin/bash -d "${STACK_HOME}" -m "${STACK_USER_NAME}"
24 echo "stack ALL=(ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/stack
29 userdel "${STACK_USER_NAME}" -f -r
30 rm /etc/sudoers.d/stack
33 devstack_local_conf(){
34 DEV_STACK_LOCAL_CONF=${DEV_STACK_DIR}/local.conf
35 cat > "$DEV_STACK_LOCAL_CONF" << DEV_STACK_LOCAL_CONF_DOCK
37 # use TryStack git mirror
38 GIT_BASE=$STACK_GIT_BASE
40 # If the "*_PASSWORD" variables are not set here you will be prompted to enter
41 # values for them by "stack.sh" and they will be added to "local.conf".
42 ADMIN_PASSWORD=$STACK_PASSWORD
43 DATABASE_PASSWORD=$STACK_PASSWORD
44 RABBIT_PASSWORD=$STACK_PASSWORD
45 SERVICE_PASSWORD=$STACK_PASSWORD
47 # Neither is set by default.
50 # path of the destination log file. A timestamp will be appended to the given name.
51 LOGFILE=\$DEST/logs/stack.sh.log
53 # Old log files are automatically removed after 7 days to keep things neat. Change
54 # the number of days by setting "LOGDAYS".
57 ENABLED_SERVICES=mysql,key
58 # Using stable/queens branches
59 # ---------------------------------
60 KEYSTONE_BRANCH=$STACK_BRANCH
61 KEYSTONECLIENT_BRANCH=$STACK_BRANCH
62 DEV_STACK_LOCAL_CONF_DOCK
63 chown stack:stack "$DEV_STACK_LOCAL_CONF"
67 cat >> "$OPENSDS_CONFIG_DIR/opensds.conf" << OPENSDS_GLOBAL_CONFIG_DOC
71 memcached_servers = $HOST_IP:11211
72 signing_dir = /var/cache/opensds
73 cafile = /opt/stack/data/ca-bundle.pem
74 auth_uri = http://$HOST_IP/identity
75 project_domain_name = Default
76 project_name = service
77 user_domain_name = Default
78 password = $STACK_PASSWORD
79 username = $OPENSDS_SERVER_NAME
80 auth_url = http://$HOST_IP/identity
83 OPENSDS_GLOBAL_CONFIG_DOC
85 cp "$OPENSDS_DIR/examples/policy.json" "$OPENSDS_CONFIG_DIR"
88 create_user_and_endpoint(){
89 . "$DEV_STACK_DIR/openrc" admin admin
90 openstack user create --domain default --password "$STACK_PASSWORD" "$OPENSDS_SERVER_NAME"
91 openstack role add --project service --user opensds admin
92 openstack group create service
93 openstack group add user service opensds
94 openstack role add service --project service --group service
95 openstack group add user admins admin
96 openstack service create --name "opensds$OPENSDS_VERSION" --description "OpenSDS Block Storage" "opensds$OPENSDS_VERSION"
97 openstack endpoint create --region RegionOne "opensds$OPENSDS_VERSION" public "http://$HOST_IP:50040/$OPENSDS_VERSION/%\(tenant_id\)s"
98 openstack endpoint create --region RegionOne "opensds$OPENSDS_VERSION" internal "http://$HOST_IP:50040/$OPENSDS_VERSION/%\(tenant_id\)s"
99 openstack endpoint create --region RegionOne "opensds$OPENSDS_VERSION" admin "http://$HOST_IP:50040/$OPENSDS_VERSION/%\(tenant_id\)s"
102 delete_redundancy_data() {
103 . "$DEV_STACK_DIR/openrc" admin admin
104 openstack project delete demo
105 openstack project delete alt_demo
106 openstack project delete invisible_to_admin
107 openstack user delete demo
108 openstack user delete alt_demo
112 if [ ! -d "${DEV_STACK_DIR}" ];then
113 git clone "${STACK_GIT_BASE}/openstack-dev/devstack.git" -b "${STACK_BRANCH}" "${DEV_STACK_DIR}"
114 chown stack:stack -R "${DEV_STACK_DIR}"
123 # If keystone is ready to start, there is no need continue next step.
124 if wait_for_url "http://$HOST_IP/identity" "keystone" 0.25 4; then
128 cd "${DEV_STACK_DIR}"
129 su "$STACK_USER_NAME" -c "${DEV_STACK_DIR}/stack.sh" >/dev/null
130 create_user_and_endpoint
131 delete_redundancy_data
135 su "$STACK_USER_NAME" -c "${DEV_STACK_DIR}/clean.sh" >/dev/null
139 su "$STACK_USER_NAME" -c "${DEV_STACK_DIR}/unstack.sh" >/dev/null
143 rm "${STACK_HOME:?'STACK_HOME must be defined and cannot be empty'}/*" -rf
147 # ***************************
148 TOP_DIR=$(cd $(dirname "$0") && pwd)
150 # OpenSDS configuration directory
151 OPENSDS_CONFIG_DIR=${OPENSDS_CONFIG_DIR:-/etc/opensds}
153 source "$TOP_DIR/util.sh"
154 source "$TOP_DIR/sdsrc"
158 echo "Starting install keystone..."
162 echo "Starting uninstall keystone..."
166 echo "Starting cleanup keystone..."
170 echo "Starting uninstall purge keystone..."
174 echo "The value of the parameter can only be one of the following: install/uninstall/cleanup/uninstall_purge"