This repository has been archived by the owner on Dec 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
functions.rc
executable file
·197 lines (182 loc) · 5.77 KB
/
functions.rc
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/usr/bin/env bash
# Copyright [2016] [Kevin Carter]
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function mkdir_check () {
if [ ! -d "$1" ];then
mkdir -p "$1"
fi
}
function ssh_agent_reset () {
# If you were running ssh-agent with forwarding this will clear out the keys
# in your cache which can cause confusion.
if pgrep ssh-agent; then
killall ssh-agent; eval `ssh-agent`
fi
}
function iptables_general_rule_add () {
if ! iptables -w -C $1;then
iptables -w -I $1
fi
}
function iptables_filter_rule_add () {
if ! iptables -w -t $1 -C $2;then
iptables -w -t $1 -I $2
fi
}
function get_host_type () {
python <<EOL
import json
with open('hosts.json') as f:
x = json.loads(f.read())
for k, v in x.get("$1").items():
print('%s:%s' % (k, v))
EOL
}
function get_all_hosts () {
python <<EOL
import json
with open('hosts.json') as f:
x = json.loads(f.read())
for i in x.values():
for k, v in i.items():
print('%s:%s' % (k, v))
EOL
}
function get_all_types () {
python <<EOL
import json
with open('hosts.json') as f:
x = json.loads(f.read())
for i in x.keys():
print(i)
EOL
}
function wait_ssh () {
echo "Waiting for all nodes to become available. This can take around ${1:-10} min"
for node in $(get_all_hosts); do
echo "Waiting for node: ${node%%":"*} on 10.0.0.${node#*":"}"
until ssh -q -o StrictHostKeyChecking=no -o BatchMode=yes -o ConnectTimeout=10 10.0.0.${node#*':'} exit > /dev/null; do
sleep 15
done
done
}
function rekick_vms () {
# If you pass the short name of the host to the function it will only force rekick just the ONE host.
# Set the VM disk size in gigabytes
VM_DISK_SIZE="${VM_DISK_SIZE:-252}"
for node in ${1:-$(get_all_hosts)}; do
for node_name in $(virsh list --all --name | grep "${node%%":"*}"); do
virsh destroy "${node_name}" || true
done
# Instruct the system to run the image create.
# If you have the option ``VM_IMAGE_CREATE=true`` the system will reformat the disk image
# destroying anything that was it image previously.
VM_IMAGE_CREATE=${VM_IMAGE_CREATE:-true}
if [[ "${VM_IMAGE_CREATE}" = true ]]; then
qemu-img create -f qcow2 \
-o preallocation=metadata,compat=1.1,lazy_refcounts=on \
/var/lib/libvirt/images/${node%%":"*}.openstackci.local.img \
"${VM_DISK_SIZE}G"
fi
VM_NAME=$(virsh list --all --name | grep "${node%%":"*}" || echo "")
if [[ -z "${VM_NAME}" ]]; then
virsh define /etc/libvirt/qemu/${node%%":"*}.openstackci.local.xml || true
virsh create /etc/libvirt/qemu/${node%%":"*}.openstackci.local.xml || true
else
virsh start "${VM_NAME}"
fi
done
}
function write_osa_general_confd () {
CONFD_FILE="/etc/openstack_deploy/conf.d/${1}.yml"
echo "## DO NOT WRITE TO THIS FILE, CHANGES WILL BE LOST!" > ${CONFD_FILE}
echo "---" >> ${CONFD_FILE}
echo "$1:" >> ${CONFD_FILE}
for node in $(get_host_type ${2}); do
echo " ${node%%':'*}:" >> ${CONFD_FILE}
echo " ip: 172.29.236.${node#*":"}" >> ${CONFD_FILE}
done
}
function write_osa_cinder_confd () {
CONFD_FILE="/etc/openstack_deploy/conf.d/${1}.yml"
echo "## DO NOT WRITE TO THIS FILE, CHANGES WILL BE LOST!" > ${CONFD_FILE}
echo "---" >> ${CONFD_FILE}
echo "$1:" >> ${CONFD_FILE}
for node in $(get_host_type ${2}); do
echo " ${node%%':'*}:" >> ${CONFD_FILE}
echo " ip: 172.29.236.${node#*":"}" >> ${CONFD_FILE}
cat >> ${CONFD_FILE} <<EOF
container_vars:
cinder_backends:
limit_container_types: cinder_volume
lvm:
volume_group: cinder-volumes
volume_driver: cinder.volume.drivers.lvm.LVMVolumeDriver
volume_backend_name: LVM_iSCSI
iscsi_ip_address: "172.29.236.${node#*":"}"
EOF
done
}
function write_osa_swift_proxy_confd () {
CONFD_FILE="/etc/openstack_deploy/conf.d/${1}.yml"
echo "## DO NOT WRITE TO THIS FILE, CHANGES WILL BE LOST!" > ${CONFD_FILE}
echo "---" >> ${CONFD_FILE}
echo "$1:" >> ${CONFD_FILE}
for node in $(get_host_type ${2}); do
echo " ${node%%':'*}:" >> ${CONFD_FILE}
echo " ip: 172.29.236.${node#*":"}" >> ${CONFD_FILE}
cat >> ${CONFD_FILE} <<EOF
container_vars:
swift_proxy_vars:
limit_container_types: swift_proxy
read_affinity: "r1=100"
write_affinity: "r1"
write_affinity_node_count: "1 * replicas"
EOF
done
}
function write_osa_swift_storage_confd () {
CONFD_FILE="/etc/openstack_deploy/conf.d/${1}.yml"
echo "## DO NOT WRITE TO THIS FILE, CHANGES WILL BE LOST!" > ${CONFD_FILE}
echo "---" >> ${CONFD_FILE}
echo "$1:" >> ${CONFD_FILE}
for node in $(get_host_type ${2}); do
echo " ${node%%':'*}:" >> ${CONFD_FILE}
echo " ip: 172.29.236.${node#*":"}" >> ${CONFD_FILE}
cat >> ${CONFD_FILE} <<EOF
container_vars:
swift_vars:
limit_container_types: swift
zone: 0
region: 1
EOF
done
}
function osa_user_var_add () {
if ! grep -q "^$1" /etc/openstack_deploy/user_variables.yml; then
echo "$2" | tee -a /etc/openstack_deploy/user_variables.yml
else
sed -i "s|$1.*|$2|g" /etc/openstack_deploy/user_variables.yml
fi
}
function ansible_static_inventory () {
CONFD_FILE="$1"
echo "## DO NOT WRITE TO THIS FILE, CHANGES WILL BE LOST!" > ${CONFD_FILE}
for node_type in $(get_all_types); do
echo "[${node_type}]" >> ${CONFD_FILE}
for node in $(get_host_type ${node_type}); do
echo "10.0.0.${node#*":"}" >> ${CONFD_FILE}
done
done
}