summaryrefslogtreecommitdiffstats
path: root/meta-openstack/recipes-devtools/python/python-swift
diff options
context:
space:
mode:
authorVu Tran <vu.tran@windriver.com>2014-04-09 19:59:09 -0400
committerBruce Ashfield <bruce.ashfield@windriver.com>2014-04-11 14:15:28 -0400
commit322d51de8417142c6ffbf024b198b26069a53f46 (patch)
tree7dc20eedcd969ecff64b57061a5263387fe1b424 /meta-openstack/recipes-devtools/python/python-swift
parentc173214e9c25409944144c9b4bd9892949a834ba (diff)
downloadmeta-cloud-services-322d51de8417142c6ffbf024b198b26069a53f46.tar.gz
swift: add setup package
Introduce swift setup package. At boot time, this package setups a simple swift cluster including: * 3 zones * each zone has 1 storage device which are based on loopback devices which the backing files size is controlled by variable SWIFT_BACKING_FILE_SIZE The script /etc/swift/swift_setup.sh is also provided to ease the task of setting up a complicated Swift cluster. It reads a cluster config file, which describes what storage devices are included in what rings, and constructs the cluster. For details of how to use swift_setup.sh and the format of Swift cluster config file please refer to the script's help: $ swift_setup.sh Signed-off-by: Vu Tran <vu.tran@windriver.com>
Diffstat (limited to 'meta-openstack/recipes-devtools/python/python-swift')
-rw-r--r--meta-openstack/recipes-devtools/python/python-swift/cluster.conf32
-rw-r--r--meta-openstack/recipes-devtools/python/python-swift/swift.init74
-rw-r--r--meta-openstack/recipes-devtools/python/python-swift/swift_setup.sh270
3 files changed, 376 insertions, 0 deletions
diff --git a/meta-openstack/recipes-devtools/python/python-swift/cluster.conf b/meta-openstack/recipes-devtools/python/python-swift/cluster.conf
new file mode 100644
index 0000000..3cab8bd
--- /dev/null
+++ b/meta-openstack/recipes-devtools/python/python-swift/cluster.conf
@@ -0,0 +1,32 @@
1# Swift cluster config file
2#
3# Each line specifies one storage device with the following format:
4#
5# <dev file>, <dev format>, <zone>, <ring names>, <weight>
6#
7# <dev file>: full path to a block device or full path to regular
8# file which is used for backing up a loopback device.
9# If <dev file> is empty string then this device is
10# backed up by a directory in local filesystem.
11# <dev format>: the disk format type, e.g. ext4, xfs...
12# <zone>: the zone id which this block device belongs to
13# <ring names>: a list (separated by space) ring name ("account", "container",
14# or "object") which this device is added to
15# <weight>: weight of this device in Swift zone
16#
17# Examples:
18#
19# /dev/sda1, ext4, 1, account, 1
20# /dev/sda2, ext4, 1, container, 1
21# /dev/sda3, ext4, 1, object, 1
22# /dev/sdb1, ext4, 2, account container object, 1
23# /dev/sdb2, ext4, 2, account container object, 1
24# /dev/sdb3, ext4, 2, account container object, 1
25# , ext4, 1, account container object, 1
26# , ext4, 2, account container object, 1
27# , ext4, 3, account container object, 1
28
29
30%SWIFT_BACKING_FILE_1%, ext4, 1, account container object, 1
31%SWIFT_BACKING_FILE_2%, ext4, 2, account container object, 1
32%SWIFT_BACKING_FILE_3%, ext4, 3, account container object, 1
diff --git a/meta-openstack/recipes-devtools/python/python-swift/swift.init b/meta-openstack/recipes-devtools/python/python-swift/swift.init
new file mode 100644
index 0000000..cf12066
--- /dev/null
+++ b/meta-openstack/recipes-devtools/python/python-swift/swift.init
@@ -0,0 +1,74 @@
1#!/bin/sh
2
3# chkconfig: 2345 20 20
4
5### BEGIN INIT INFO
6# Provides: swift-openstack
7# Required-Start: $remote_fs $syslog
8# Required-Stop: $remote_fs $syslog
9# Default-Start: 3 5
10# Default-Stop: 0 1 2 6
11# Short-Description: OpenStack Swift
12# Description: OpenStack Swift
13### END INIT INFO
14
15
16DESC="Swift Cluster"
17SWIFT_HOME=/etc/swift
18SWIFT_INIT=/usr/bin/swift-init
19
20start ()
21{
22 echo -n "Starting $DESC..."
23 if [ ! -e $SWIFT_HOME/account.builder -a ! -e $SWIFT_HOME/container.builder -a ! -e $SWIFT_HOME/object.builder ]; then
24 echo "no Swift cluster has been setup, failed."
25 exit 1
26 fi
27 /etc/swift/swift_setup.sh mountdevs
28 $SWIFT_INIT proxy-server start
29 $SWIFT_INIT account-server start
30 $SWIFT_INIT container-server start
31 $SWIFT_INIT object-server start
32 echo "done."
33}
34
35
36stop ()
37{
38 echo -n "Stopping $DESC..."
39 $SWIFT_INIT all stop
40 /etc/swift/swift_setup.sh unmountdevs
41 echo "done."
42}
43
44
45status ()
46{
47 $SWIFT_INIT proxy-server status
48 $SWIFT_INIT account-server status
49 $SWIFT_INIT container-server status
50 $SWIFT_INIT object-server status
51}
52
53
54case "$1" in
55 start)
56 start
57 ;;
58 stop)
59 stop
60 ;;
61 restart|force-reload)
62 stop
63 start
64 ;;
65 status)
66 status
67 ;;
68 *)
69 echo "Usage: swift {start|stop|force-reload|restart|status}"
70 exit 1
71 ;;
72esac
73
74exit 0
diff --git a/meta-openstack/recipes-devtools/python/python-swift/swift_setup.sh b/meta-openstack/recipes-devtools/python/python-swift/swift_setup.sh
new file mode 100644
index 0000000..c1d02ed
--- /dev/null
+++ b/meta-openstack/recipes-devtools/python/python-swift/swift_setup.sh
@@ -0,0 +1,270 @@
1#!/bin/bash
2
3#set -x
4
5SWIFT_RING_BUILDER=/usr/bin/swift-ring-builder
6
7
8for_each_dev_in_cluster ()
9{
10 local cmd=$1
11
12 dev_id=0
13 while read line; do
14 line=`echo $line | sed -e 's/^ *//g' -e 's/ *$//g'`
15 [ -z "$line" ] && continue
16
17 dev=`echo $line | cut -d ',' -f 1 | sed -e 's/^ *//g' -e 's/ *$//g'`
18 dev_format=`echo $line | cut -d ',' -f 2 | sed -e 's/^ *//g' -e 's/ *$//g'`
19 zone=`echo $line | cut -d ',' -f 3 | sed -e 's/^ *//g' -e 's/ *$//g'`
20 ring_names=`echo $line | cut -d ',' -f 4 | sed -e 's/^ *//g' -e 's/ *$//g'`
21 weight=`echo $line | cut -d ',' -f 5 | sed -e 's/^ *//g' -e 's/ *$//g'`
22
23 [[ "${dev:0:1}" == "#" ]] && continue
24 if [ ! -z $dev ] && [ ! -e $dev ]; then
25 continue
26 fi
27 dev_id=$((dev_id+1))
28 $cmd "$dev" "$dev_format" "$dev_id" "$zone" "$ring_names" "$weight" $2 $3 $4
29 done < $cluster_conf
30}
31
32
33mount_dev ()
34{
35 local dev=$1
36 local dev_id=$3
37 local zone=$4
38
39 mkdir -p $swift_home/node/z${zone}d${dev_id}
40 [ -z "$dev" ] && return 1
41 if [ -b $dev ]; then
42 mount $dev $swift_home/node/z${zone}d${dev_id}
43 else
44 loopdev=`losetup --show -f $dev`
45 mount $loopdev $swift_home/node/z${zone}d${dev_id}
46 fi
47}
48
49
50unmount_dev ()
51{
52 local dev=$1
53
54 [ -z "$dev" ] && return 1
55 if [ -b $dev ]; then
56 umount $dev
57 else
58 loopdev=`losetup -j $dev | cut -d ":" -f 1 | tail -1`
59 if [ ! -z $loopdev ]; then
60 umount $loopdev
61 losetup -d $loopdev
62 fi
63 fi
64}
65
66
67format_dev ()
68{
69 local dev=$1
70 local dev_format=$2
71
72 [ -z "$dev" ] && return 1
73 if [ -b $dev ]; then
74 mkfs.${dev_format} $dev
75 else
76 loopdev=`losetup --show -f $dev`
77 mkfs.${dev_format} $loopdev
78 sleep 2
79 losetup -d $loopdev
80 fi
81}
82
83
84add_dev ()
85{
86 local dev_id=$3
87 local zone=$4
88 local ring_names=$5
89 local weight=$6
90
91 account_port=6002
92 container_port=6001
93 object_port=6000
94
95 for ring in $ring_names; do
96 eval builder_port=\$${ring}_port
97 [ -z $builder_port ] && continue
98 $SWIFT_RING_BUILDER $swift_home/${ring}.builder add -r 1 -z $zone -i $host_ip -p $builder_port -d z${zone}d${dev_id} -w $weight
99 done
100}
101
102
103cluster_create_rings ()
104{
105 if [ ! -f $SWIFT_RING_BUILDER ]; then
106 echo "ERROR: Swift packages are not installed on this machine"
107 return 1
108 fi
109
110 if [ -e $swift_home/account.builder -o -e $swift_home/container.builder -o -e $swift_home/object.builder ]; then
111 echo "ERROR: Swift cluster has been created"
112 return 1
113 fi
114
115 sed "s/^swift_hash_path_suffix =.*/swift_hash_path_suffix = `uuidgen`/" -i $swift_home/swift.conf
116
117 # Create 3 ring builders: each ring has 2^12 partition
118 $SWIFT_RING_BUILDER $swift_home/account.builder create 12 $cluster_replica 1
119 $SWIFT_RING_BUILDER $swift_home/container.builder create 12 $cluster_replica 1
120 $SWIFT_RING_BUILDER $swift_home/object.builder create 12 $cluster_replica 1
121}
122
123
124cluster_add_devs ()
125{
126 for_each_dev_in_cluster add_dev
127
128 $SWIFT_RING_BUILDER $swift_home/account.builder rebalance
129 $SWIFT_RING_BUILDER $swift_home/container.builder rebalance
130 $SWIFT_RING_BUILDER $swift_home/object.builder rebalance
131}
132
133
134cluster_delete_all ()
135{
136 for_each_dev_in_cluster unmount_dev
137 rm -rf $swift_home/*.ring.gz
138 rm -rf $swift_home/*.builder
139 rm -rf $swift_home/node
140}
141
142
143help ()
144{
145 cat << EOF
146usage: swift_setup.sh [-hcirk] <command>
147
148 -h : View this help
149 -c : Swift cluster config file, default is /etc/swift/cluster.conf
150 -i : IP address of this machine, default is 127.0.0.1
151 -r : The number of Swift replications
152 -k : Location where Swift builder and ring files stay, default is /etc/swift
153
154<command> can be one of the followings:
155
156 createrings : Create Swift account, container, and object builder
157 clean : Delete all Swift build and ring files
158 mountdevs : Mount all devices specified in cluster config file
159 unmountdevs : Un-mount all devices specified in cluster config file
160 formatdevs : Format all devices specified in cluster config file
161 adddevs : Add all devices specified in cluster config file into
162 Swift rings
163
164swift_setup.sh script helps to create or expand Swift cluster with
165storage devices in this machine.
166
167The Swift cluster config file (default is /etc/swift/cluster.conf) describes
168how storage devices in this machine can be added into Swift cluster.
169
170Each line of cluster config file specifies how one storage device can be
171added into Swift cluster with the following format:
172
173 <dev file>, <dev format>, <zone>, <ring names>, <weight>
174
175 <dev file>: full path to a block device or full path to regular
176 file which is used for backing up a loopback device.
177 If <dev file> is empty string then this device is
178 backed up by a directory in local filesystem.
179 <dev format>: the disk format type, e.g. ext4, xfs...
180 <zone>: the zone id which this block device belongs to
181 <ring names>: a list (separated by space) ring name ("account", "container",
182 or "object") which this device is added to
183 <weight>: weight of this device in Swift zone
184
185
186Example 1: To add storage devices in this machine into an existing
187Swift Cluster:
188
189 $ /etc/init.d/swift stop
190 $ Sync the Swift builders and rings files into this machine
191 $ Modify /etc/cluster.conf to specify what storage devices
192 are added into cluster
193 $ swift_setup.sh formatdevs
194 $ swift_setup.sh mountdevs
195 $ swift_setup.sh -i <IP of this machine> adddevs
196 $ swift_setup.sh unmountdevs
197 $ /etc/init.d/swift start
198
199Example 2: To create an new Swift cluster:
200
201 $ /etc/init.d/swift stop
202 $ Modify /etc/cluster.conf to reflect the desired cluster
203 $ swift_setup.sh clean
204 $ swift_setup.sh createrings
205 $ swift_setup.sh formatdevs
206 $ swift_setup.sh mountdevs
207 $ swift_setup.sh -i <IP of this machine> adddevs
208 $ swift_setup.sh unmountdevs
209 $ /etc/init.d/swift start
210EOF
211}
212
213
214cluster_conf="/etc/swift/cluster.conf"
215swift_home="/etc/swift"
216host_ip="127.0.0.1"
217cluster_replica="2"
218
219while getopts "?hc:r:i:k:" opt; do
220 case $opt in
221 c)
222 cluster_conf=$OPTARG
223 ;;
224 r)
225 cluster_replica=$OPTARG
226 ;;
227 i)
228 host_ip=$OPTARG
229 ;;
230 k)
231 swift_home=$OPTARG
232 ;;
233 ?|h)
234 help
235 exit 0
236 ;;
237 esac
238done
239
240# Move aside the optional arguments
241shift $(( $OPTIND - 1 ))
242
243
244case "$1" in
245 createrings)
246 cluster_create_rings
247 ;;
248 clean)
249 for_each_dev_in_cluster unmount_dev
250 cluster_delete_all
251 ;;
252 mountdevs)
253 for_each_dev_in_cluster mount_dev
254 ;;
255 unmountdevs)
256 for_each_dev_in_cluster unmount_dev
257 ;;
258 formatdevs)
259 for_each_dev_in_cluster format_dev
260 ;;
261 adddevs)
262 cluster_add_devs
263 ;;
264 *)
265 help
266 exit 0
267 ;;
268esac
269
270exit 0