-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcommons.sh
More file actions
executable file
·100 lines (91 loc) · 2.6 KB
/
commons.sh
File metadata and controls
executable file
·100 lines (91 loc) · 2.6 KB
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
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2022
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o nounset
set -o pipefail
set -o errexit
if [[ ${OS_DEBUG:-false} == "true" ]]; then
export PKG_DEBUG=true
set -o xtrace
fi
function setup_ansible {
# Setup Mitogen
mitogen_ansible_cfg=""
if pip freeze | grep -q mitogen; then
mitogen_ansible_cfg="
strategy = mitogen_linear
strategy_plugins = $(dirname "$(sudo find / -name mitogen_linear.py | head -n 1)")
"
fi
sudo tee /etc/ansible/ansible.cfg <<EOL
[defaults]
host_key_checking=False
remote_tmp=/tmp/
callbacks_enabled = timer, profile_tasks
$mitogen_ansible_cfg
[ssh_connection]
pipelinig=True
ssh_args = -o ControlMaster=auto -o ControlPersist=30m -o ConnectionAttempts=100 -o UserKnownHostsFile=/dev/null
EOL
if [[ ${OS_DEBUG:-false} == "true" ]]; then
# NOTE: Uses the simplest UTF-8 locale
export LC_ALL=C.UTF-8
# Print out Ansible configuration
ansible-config dump --only-changed
fi
}
function set_values {
for env_var in $(printenv | grep "OS_KOLLA_"); do
sudo --preserve-env="${env_var%=*}" "$(command -v yq)" e -i \
".$(echo "${env_var%=*}" | tr '[:upper:]' '[:lower:]' | sed 's/os_kolla_//g') = strenv(${env_var%=*})" \
/etc/kolla/globals.yml
done
}
function vercmp {
local v1=$1
local op=$2
local v2=$3
local result
# sort the two numbers with sort's "-V" argument. Based on if v2
# swapped places with v1, we can determine ordering.
result=$(echo -e "$v1\n$v2" | sort -V | head -1)
case $op in
"==")
[ "$v1" = "$v2" ]
return
;;
">")
[ "$v1" != "$v2" ] && [ "$result" = "$v2" ]
return
;;
"<")
[ "$v1" != "$v2" ] && [ "$result" = "$v1" ]
return
;;
">=")
[ "$result" = "$v2" ]
return
;;
"<=")
[ "$result" = "$v1" ]
return
;;
*)
echo "unrecognised op: $op"
exit 1
;;
esac
}
function run_kolla_actions {
for action in "$@"; do
./run_kaction.sh "$action" | tee "$HOME/$action.log"
echo "Kolla Action statistics:"
grep ': .* -* .*s$' "$HOME/$action.log" || :
done
}