setup-storage.sh 5.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/bin/sh

##
## Setup a OpenStack compute node for Nova.
##

set -x

# Gotta know the rules!
if [ $EUID -ne 0 ] ; then
    echo "This script must be run as root" 1>&2
    exit 1
fi

# Grab our libs
. "`dirname $0`/setup-lib.sh"

if [ "$HOSTNAME" != "$STORAGEHOST" ]; then
    exit 0;
fi

if [ -f $OURDIR/setup-storage-host-done ]; then
    exit 0
fi

26 27
logtstart "storage"

28 29 30
if [ -f $SETTINGS ]; then
    . $SETTINGS
fi
31 32 33
if [ -f $LOCALSETTINGS ]; then
    . $LOCALSETTINGS
fi
34

35
ARCH=`uname -m`
36

37
maybe_install_packages lvm2
38 39 40
if [ $OSVERSION -ge $OSOCATA ]; then
    maybe_install_packages thin-provisioning-tools
fi
41

42 43 44 45
#
# First try to make LVM volumes; fall back to loop device in /storage.  We use
# /storage for swift later, so we make the dir either way.
#
46 47

mkdir -p /storage
48 49 50
if [ -z "$LVM" ] ; then
    LVM=1
    VGNAME="openstack-volumes"
51
    MKEXTRAFS_ARGS="-l -v ${VGNAME} -m util -z 1024"
52
    # On Cloudlab ARM machines, there is no second disk nor extra disk space
53
    # Well, now there's a new partition layout; try it.
54
    if [ "$ARCH" = "aarch64" ]; then
55
	maybe_install_packages gdisk
56 57 58
	sgdisk -i 1 /dev/sda
	if [ $? -eq 0 ] ; then
	    sgdisk -N 2 /dev/sda
59
	    partprobe /dev/sda
60
	    if [ $? -eq 0 ] ; then
61
		partprobe /dev/sda
62 63 64 65 66 67 68 69 70 71
		# Add the second partition specifically
		MKEXTRAFS_ARGS="${MKEXTRAFS_ARGS} -s 2"
	    else
		MKEXTRAFS_ARGS=""
		LVM=0
	    fi
	else
	    MKEXTRAFS_ARGS=""
	    LVM=0
	fi
72 73 74 75 76 77 78 79 80 81 82
    fi

    /usr/local/etc/emulab/mkextrafs.pl ${MKEXTRAFS_ARGS}
    if [ $? -ne 0 ]; then
	/usr/local/etc/emulab/mkextrafs.pl ${MKEXTRAFS_ARGS} -f
	if [ $? -ne 0 ]; then
	    /usr/local/etc/emulab/mkextrafs.pl -f /storage
	    LVM=0
	fi
    fi
fi
83

84 85 86 87 88 89 90 91
if [ $LVM -eq 0 ] ; then
    dd if=/dev/zero of=/storage/pvloop.1 bs=32768 count=131072
    LDEV=`losetup -f`
    losetup $LDEV /storage/pvloop.1

    pvcreate /dev/loop0
    vgcreate $VGNAME /dev/loop0
fi
92

93
maybe_install_packages cinder-volume $DBDPACKAGE
94

95
crudini --set /etc/cinder/cinder.conf \
96
    database connection "${DBDSTRING}://cinder:$CINDER_DBPASS@$CONTROLLER/cinder"
97 98 99 100 101 102 103 104 105

crudini --del /etc/cinder/cinder.conf keystone_authtoken auth_host
crudini --del /etc/cinder/cinder.conf keystone_authtoken auth_port
crudini --del /etc/cinder/cinder.conf keystone_authtoken auth_protocol

crudini --set /etc/cinder/cinder.conf DEFAULT auth_strategy keystone
crudini --set /etc/cinder/cinder.conf DEFAULT verbose ${VERBOSE_LOGGING}
crudini --set /etc/cinder/cinder.conf DEFAULT debug ${DEBUG_LOGGING}
crudini --set /etc/cinder/cinder.conf DEFAULT my_ip ${MGMTIP}
106 107 108 109 110
if [ $OSVERSION -ge $OSPIKE ]; then
    crudini --set /etc/cinder/cinder.conf backend_defaults iscsi_ip_address ${MYIP}
elif [ $OSVERSION -ge $OSOCATA ]; then
    crudini --set /etc/cinder/cinder.conf DEFAULT iscsi_ip_address ${MYIP}
fi
111 112

if [ $OSVERSION -lt $OSKILO ]; then
113
    crudini --set /etc/cinder/cinder.conf DEFAULT rpc_backend rabbit
114 115 116
    crudini --set /etc/cinder/cinder.conf DEFAULT rabbit_host $CONTROLLER
    crudini --set /etc/cinder/cinder.conf DEFAULT rabbit_userid ${RABBIT_USER}
    crudini --set /etc/cinder/cinder.conf DEFAULT rabbit_password "${RABBIT_PASS}"
117 118 119 120 121 122 123 124 125 126 127
elif [ $OSVERSION -lt $OSNEWTON ]; then
    crudini --set /etc/cinder/cinder.conf DEFAULT rpc_backend rabbit
    crudini --set /etc/cinder/cinder.conf oslo_messaging_rabbit \
	rabbit_host $CONTROLLER
    crudini --set /etc/cinder/cinder.conf oslo_messaging_rabbit \
	rabbit_userid ${RABBIT_USER}
    crudini --set /etc/cinder/cinder.conf oslo_messaging_rabbit \
	rabbit_password "${RABBIT_PASS}"
else
    crudini --set /etc/cinder/cinder.conf DEFAULT transport_url $RABBIT_URL
fi
128

129
if [ $OSVERSION -lt $OSKILO ]; then
130 131 132
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	auth_uri http://${CONTROLLER}:5000/${KAPISTR}
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
133
	identity_uri http://${CONTROLLER}:${KADMINPORT}
134 135 136 137 138 139 140 141 142 143
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	admin_tenant_name service
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	admin_user cinder
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	admin_password "${CINDER_PASS}"
else
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	auth_uri http://${CONTROLLER}:5000
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
144
	auth_url http://${CONTROLLER}:${KADMINPORT}
145
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
146
	${AUTH_TYPE_PARAM} password
147
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
148
	${PROJECT_DOMAIN_PARAM} default
149
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
150
	${USER_DOMAIN_PARAM} default
151 152 153 154 155 156
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	project_name service
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	username cinder
    crudini --set /etc/cinder/cinder.conf keystone_authtoken \
	password "${CINDER_PASS}"
157 158
fi

159
crudini --set /etc/cinder/cinder.conf DEFAULT glance_host ${CONTROLLER}
160 161 162 163
if [ $OSVERSION -ge $OSMITAKA ]; then
    crudini --set /etc/cinder/cinder.conf \
	glance api_servers http://${CONTROLLER}:9292
fi
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185

if [ $OSVERSION -eq $OSKILO ]; then
    crudini --set /etc/cinder/cinder.conf oslo_concurrency \
	lock_path /var/lock/cinder
elif [ $OSVERSION -ge $OSLIBERTY ]; then
    crudini --set /etc/cinder/cinder.conf oslo_concurrency \
	lock_path /var/lib/cinder/tmp
fi

if [ $OSVERSION -eq $OSJUNO ]; then
    crudini --set /etc/cinder/cinder.conf DEFAULT volume_group openstack-volumes
else
    crudini --set /etc/cinder/cinder.conf lvm \
	volume_driver cinder.volume.drivers.lvm.LVMVolumeDriver
    crudini --set /etc/cinder/cinder.conf lvm volume_group openstack-volumes
    crudini --set /etc/cinder/cinder.conf lvm iscsi_protocol iscsi
    crudini --set /etc/cinder/cinder.conf lvm iscsi_helper tgtadm
    crudini --set /etc/cinder/cinder.conf DEFAULT enabled_backends lvm
fi

service_restart tgt
service_enable tgt
186 187
service_restart cinder-volume
service_enable cinder-volume
188 189
rm -f /var/lib/cinder/cinder.sqlite

190 191 192
echo "LVM=$LVM" >> $LOCALSETTINGS
echo "VGNAME=${VGNAME}" >> $LOCALSETTINGS

193 194
touch $OURDIR/setup-storage-host-done

195 196
logtend "storage"

197
exit 0