From 21d627c7a49e17d539d0690fd9fd24760a6e42b7 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Thu, 26 Mar 2015 19:19:10 +0000 Subject: cinder: Move setup scripts to Ansible. Also change systemd units and configure extension to match this change --- openstack/usr/share/openstack/cinder.yml | 75 ++++++++++++ .../usr/share/openstack/openstack-cinder-setup | 132 --------------------- 2 files changed, 75 insertions(+), 132 deletions(-) create mode 100644 openstack/usr/share/openstack/cinder.yml delete mode 100644 openstack/usr/share/openstack/openstack-cinder-setup (limited to 'openstack/usr/share/openstack') diff --git a/openstack/usr/share/openstack/cinder.yml b/openstack/usr/share/openstack/cinder.yml new file mode 100644 index 00000000..f5f9ddc8 --- /dev/null +++ b/openstack/usr/share/openstack/cinder.yml @@ -0,0 +1,75 @@ +--- +- hosts: localhost + vars_files: + - "/etc/openstack/cinder.conf" + tasks: + - name: Create the cinder user. + user: name=cinder comment="Openstack Cinder Daemons" shell=/sbin/nologin home=/var/lib/cinder + + - name: Create the /var folders for cinder + file: path={{ item }} state=directory owner=cinder group=cinder + with_items: + - /var/run/cinder + - /var/lock/cinder + - /var/log/cinder + - /var/lib/cinder + - /var/lib/cinder/volumer + + - file: path=/etc/cinder state=directory + - name: Add the configuration needed for cinder in /etc/cinder using templates + template: src=/usr/share/openstack/cinder/{{ item }} dest=/etc/cinder/{{ item }} + with_lines: + - (cd /usr/share/openstack/cinder && find -type f) + + - keystone_user: > + user={{ CINDER_USER }} + password={{ CINDER_PASSWORD }} + tenant=service + token={{ KEYSTONE_TEMPORARY_ADMIN_TOKEN }} + + - keystone_user: > + role=admin + user={{ CINDER_USER }} + tenant=service + token={{ KEYSTONE_TEMPORARY_ADMIN_TOKEN }} + + - keystone_service: > + name=cinder + type=volume + description="Openstack Block Storage" + publicurl='http://{{ CONTROLLER_HOST_ADDRESS }}:8776/v1/%(tenant_id)s' + internalurl='http://{{ CONTROLLER_HOST_ADDRESS }}:8776/v1/%(tenant_id)s' + adminurl='http://{{ CONTROLLER_HOST_ADDRESS }}:8776/v1/%(tenant_id)s' + region='regionOne' + token={{ KEYSTONE_TEMPORARY_ADMIN_TOKEN }} + + - keystone_service: > + name=cinderv2 + type=volumev2 + description="Openstack Block Storage" + publicurl='http://{{ CONTROLLER_HOST_ADDRESS }}:8776/v2/%(tenant_id)s' + internalurl='http://{{ CONTROLLER_HOST_ADDRESS }}:8776/v2/%(tenant_id)s' + adminurl='http://{{ CONTROLLER_HOST_ADDRESS }}:8776/v2/%(tenant_id)s' + region='regionOne' + token={{ KEYSTONE_TEMPORARY_ADMIN_TOKEN }} + + - postgresql_user: name={{ CINDER_DB_USER }} + sudo: yes + sudo_user: cinder + - postgresql_db: name=cinder owner={{ CINDER_DB_USER }} + sudo: yes + sudo_user: cinder + + - cinder_manage: action=dbsync + sudo: yes + sudo_user: cinder + + - name: Enable and start openstack-cinder services + service: name={{ item }} enabled=yes state=started + with_items: + - openstack-cinder-api + - openstack-cinder-scheduler + - openstack-cinder-volume + - openstack-cinder-backup + + - lvg: vg=cinder-volumes pvs={{ CINDER_DEVICE }} diff --git a/openstack/usr/share/openstack/openstack-cinder-setup b/openstack/usr/share/openstack/openstack-cinder-setup deleted file mode 100644 index eb97d55a..00000000 --- a/openstack/usr/share/openstack/openstack-cinder-setup +++ /dev/null @@ -1,132 +0,0 @@ -#!/bin/sh -# -# Copyright (C) 2014 Codethink Limited -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -set -e - -# Create required system users and groups - -getent group cinder >/dev/null || groupadd -r --gid 165 cinder -getent passwd cinder >/dev/null || \ - useradd --uid 165 -r -g cinder -d /var/lib/cinder -s /sbin/nologin \ - -c "OpenStack Cinder Daemons" cinder - -# Create the keystone user and services - -export OS_SERVICE_TOKEN=##KEYSTONE_TEMPORARY_ADMIN_TOKEN## -export OS_SERVICE_ENDPOINT='http://onenode:35357/v2.0' - -keystone user-create --name ##CINDER_USER## --pass ##CINDER_PASSWORD## -keystone user-role-add --tenant service --user ##CINDER_USER## --role admin - -# Register the Block Storage service with the Identity service so other OpenStack services -# can locate it -keystone service-create --name ##CINDER_USER## --type volume --description "OpenStack Block Storage" -keystone endpoint-create --service-id $(keystone service-list | awk '/ volume / {print $2}') \ - --publicurl ##CINDER_PUBLIC_URL## \ - --internalurl ##CINDER_INTERNAL_URL## \ - --adminurl ##CINDER_ADMIN_URL## - -# Register a service and endpoint for version 2 of the Block Storage service API -keystone service-create --name ##CINDER_USER_V2## \ - --type volumev2 --description "OpenStack Block Storage" -keystone endpoint-create --service-id $(keystone service-list | awk '/ volumev2 / {print $2}') \ - --publicurl ##CINDER_PUBLIC_URL_V2## \ - --internalurl ##CINDER_INTERNAL_URL_V2## \ - --adminurl ##CINDER_ADMIN_URL_V2## - -# Create run directory for cinder -if [ ! -d /var/run/cinder ]; then - mkdir -p /var/run/cinder - chown -R cinder:cinder /var/run/cinder -fi - -# Create the lock directory for cinder -if [ ! -d /var/lock/cinder ]; then - mkdir -p /var/lock/cinder - chown -R cinder:cinder /var/lock/cinder -fi - -# Create the log directory for cinder -if [ ! -d /var/log/cinder ]; then - mkdir -p /var/log/cinder - chown -R cinder:cinder /var/log/cinder -fi - -# Create the volumes directory for cinder -if [ ! -d /var/lib/cinder/volumes ]; then - mkdir -p /var/lib/cinder/volumes - chown -R cinder:cinder /var/lib/cinder/volumes -fi - -# Setup the cinder database -if ! sudo -u postgres psql -lqt | grep -q cinder; then - # Create posgreSQL user - sudo -u postgres createuser \ - --pwprompt --encrypted \ - --no-adduser --no-createdb \ - --no-password \ - ##CINDER_DB_USER## - - sudo -u postgres createdb \ - --owner=##CINDER_DB_USER## \ - cinder - - sudo -u cinder cinder-manage db sync -fi - -chown -R cinder:cinder /var/lib/cinder - -# This is only for testing purposes and we need to change it for -# something more robust to deploy in production. -# This also assumes that the user will add a second disk to its VM -# and if it does not find sdb or vda it will fail. -if [ $(ls /sys/block | grep -v sda | grep [vs]d | wc -l) -ne 1 ]; then - echo "Error: More than one or none block device found, cinder will not be able to create a VG." - exit 1 -else - device=/dev/$(ls /sys/block | grep -v sda | grep [vs]d) -fi - -# Create a physical volume -pvcreate -ff -y $device - -# Create a volume group named "cinder-volumes" -vgcreate -y cinder-volumes $device - -# Remove the one-shot setup service -rm /etc/systemd/system/multi-user.target.wants/openstack-cinder-setup.service - -# Start cinder services -systemctl start openstack-cinder-api -systemctl start openstack-cinder-scheduler -systemctl start openstack-cinder-volume -systemctl start openstack-cinder-backup - -# Create the links to run nova services when system start next times. -ln -s "/etc/systemd/system/openstack-cinder-api.service" \ - "/etc/systemd/system/multi-user.target.wants/openstack-cinder-api.service" - -ln -s "/etc/systemd/system/openstack-cinder-scheduler.service" \ - "/etc/systemd/system/multi-user.target.wants/openstack-cinder-scheduler.service" - -ln -s "/etc/systemd/system/openstack-cinder-volume.service" \ - "/etc/systemd/system/multi-user.target.wants/openstack-cinder-volume.service" - -ln -s "/etc/systemd/system/openstack-cinder-backup.service" \ - "/etc/systemd/system/multi-user.target.wants/openstack-cinder-backup.service" - -exit 0 -- cgit v1.2.1