-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjumphost.sh
221 lines (189 loc) · 6.75 KB
/
jumphost.sh
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/bash
# On jumphost
# these functions are tightly coupled with jumphost environment
get_uuid() {
clustername=${1:?}
pks cluster ${clustername} | awk '/UUID/{print $2}'
}
delete_nat_rule() {
clustername=${1:?}
uuid=$(get_uuid ${clustername})
pushd /home/kubo 2>&1 >/dev/null
source gw_scripts/nsx_env.sh
source nsx-helper-pkg/utils.sh
id=$(pks::nsx::client get "logical-routers/${NSX_T0_ROUTER_ID}/nat/rules" | jq -cr ".results[] | select ( .display_name == \"pks-${uuid}-nat-rule\")| .id")
if [ ! -z "${id}" ]; then
pks::nsx::client delete "logical-routers/${NSX_T0_ROUTER_ID}/nat/rules/${id}"
fi
popd 2>&1 >/dev/null
}
replace_release_version() {
release=${1:?}
value=${2:?}
deployment=$(bosh deployments | awk '{print $1}' | grep pivotal-container-service)
bosh -d ${deployment} manifest > ${deployment}.manifest
cat > ops.yml <<EOF
- type: replace
path: /instance_groups/name=pivotal-container-service/properties/service_deployment/releases/name=${release}/version
value: ${value}
- type: replace
path: /releases/name=${release}/version
value: ${value}
EOF
bosh int -o ops.yml ${deployment}.manifest > ${deployment}.newm
bosh -d ${deployment} deploy ${deployment}.newm
}
print_help() {
type $1
}
get_ncp_process_id() {
clustername=${1:?}
uuid=$(get_uuid ${clustername})
target=${2:?}
bosh -d service-instance_${uuid} ssh ${target} 'ps -ef | grep ncp' | awk '/start_ncp/{print $5}'
}
kill_ncp_process() {
clustername=${1:?}
uuid=$(get_uuid ${clustername})
target=${2:?}
id=$(get_ncp_process_id ${uuid} ${target})
kill_procee_by_id_on_machine "${id}"
}
kill_procee_by_id_on_machine() {
clustername=${1}
uuid=$(get_uuid ${clustername})
target=$2
id=$3
bosh -d service-instance_${uuid} ssh ${target} "sudo su -c \"pkill -P ${id}\""
}
check_ncp_master_status() {
clustername=${1}
uuid=$(get_uuid ${clustername})
target=$2
bosh -d service-instance_${uuid} ssh ${target} "sudo su -c '/var/vcap/jobs/ncp/bin/nsxcli -c get ncp-master status'"
}
list_machines() {
clustername=${1}
uuid=$(get_uuid ${clustername})
bosh -d service-instance_${uuid} vms |awk '/vm-/{print $1}'
}
find_ncp_master_machine() {
clustername=${1}
for m in $(list_machines ${clustername} | grep 'master'); do
if check_ncp_master_status ${clustername} ${m} | grep 'This instance is the NCP master' 2>&1 >/dev/null; then
echo ${m}
fi
done
}
check_vmk50() {
host_paths=$(govc ls /kubo-dc/host/* | grep -v Resources)
readarray -t hosts <<<"$host_paths"
for host in "${hosts[@]}"
do
host_ip=$(echo $host| rev | cut -d'/' -f 1 | rev)
echo "$host_ip"
sshpass -p 'Ponies!23' ssh -o StrictHostKeyChecking=no root@$host_ip "esxcfg-vmknic -l | grep vmk50"
echo "###"
done
}
get_pks_guid() {
# TODO: $PKS_TILE_NAME is hardcoded here
guid=$(${omcli} curl -s -p '/api/v0/staged/products' | jq -cr '.[] | select( .type=="pivotal-container-service" ) | .guid')
echo $guid
}
get_pks_info() {
export PKS_GUID="$(get_pks_guid)"
echo "PKS GUID: ${PKS_GUID}"
export PKS_IP=$(${omcli} curl -s -p "/api/v0/deployed/products/${PKS_GUID}/status" | jq -cr '.status[].ips[0]')
echo "PKS IP: ${PKS_IP}"
echo "get pks certificate"
${omcli} curl -s -p "/api/v0/deployed/products/${PKS_GUID}/credentials/.pivotal-container-service.pks_tls" | jq -c -r .credential.value.cert_pem > /home/kubo/pks.crt
}
pks_login() {
uaa_hostname=$(get_pks_property_value pks_api_hostname)
username=${PKS_USERNAME:-alana} # use PKS_USERNAME here
password=${PKS_PASSWORD:-password} # use PKS_PASSWORD here
pks login -a ${uaa_hostname} -u ${username} -p ${password} -k
}
pks_setup_login() {
echo "set target"
uaa_hostname=$(get_pks_property_value pks_api_hostname)
add_dns "30.0.0.12" ${uaa_hostname}
uaac target https://${uaa_hostname}:8443 --skip-ssl-validation
echo "Fetching uaa admin secret"
guid=$(get_pks_guid)
secret=$(${omcli} curl -s --path "/api/v0/deployed/products/${guid}/credentials/.properties.pks_uaa_management_admin_client" | jq -c -r '.credential.value.secret')
echo "uaac login"
uaac token client get admin -s ${secret}
username=${PKS_USERNAME:-alana} # use PKS_USERNAME here
password=${PKS_PASSWORD:-password} # use PKS_PASSWORD here
echo "uaac create user ${username}"
uaac user add ${username} --given_name ${username} --family_name pks --emails ${username}@pks.com -p ${password}
echo "uaac add user ${username} to pks.clusters.admin"
uaac member add pks.clusters.admin ${username}
echo "get pks certificate"
${omcli} curl -s -p "/api/v0/deployed/products/${guid}/credentials/.pivotal-container-service.pks_tls" | jq -c -r .credential.value.cert_pem > /home/kubo/pks.crt
echo "pks login"
pks login -a ${uaa_hostname} -u ${username} -p ${password} --ca-cert /home/kubo/pks.crt
}
list_product_properties() {
guid=$1
${omcli} curl -s -p "/api/v0/staged/products/${guid}/properties" | jq -cr '.properties | keys[]' | sed 's/.properties.//g'
}
list_pks_properties() {
guid=$(get_pks_guid)
${omcli} curl -s -p "/api/v0/staged/products/${guid}/properties" | jq -cr '.properties | keys[]' | sed 's/.properties.//g'
}
get_pks_property_value() {
guid=$(get_pks_guid)
key=$1
${omcli} curl -s -p "/api/v0/staged/products/${guid}/properties" | jq -cr ".properties[\".properties.${key}\"].value"
}
add_dns() {
echo "${1} ${2}" | sudo tee -a /etc/hosts > /dev/null
}
list_pks_utils() {
echo "get_uuid"
echo "delete_nat_rule"
echo "replace_release_version"
echo "get_ncp_process_id"
echo "kill_ncp_process"
echo "kill_procee_by_id_on_machine"
echo "check_ncp_master_status"
echo "list_machines"
echo "find_ncp_master_machine"
echo "check_vmk50"
echo "get_pks_guid"
echo "get_pks_info"
echo "pks_login"
echo "pks_setup_login"
echo "list_product_properties"
echo "list_pks_properties"
echo "get_pks_property_value"
echo "add_dns"
echo "list_pks_utils"
echo "disable_resurrector"
}
pks_utils_help() {
func=${1:?pks_utils_help [funcname]}
type ${func}
}
disable_resurrector() {
${omcli} configure-director --director-configuration '{"resurrector_enabled": false}'
}
watch_deployment() {
source gw_scripts/bosh_env.sh
bosh -d service-instance_$(get_uuid ${1}) task
}
install_gsutil_on_ubuntu() {
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)"
echo "deb http://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-get update && sudo apt-get install google-cloud-sdk
}
check_ncp_ini_field() {
clustername=$1
var=$2
master=${3:-master}
bosh -d service-instance_$(pks cluster ${clustername} --json | jq -cr '.uuid') ssh ${master} "sudo su -c 'cat /var/vcap/jobs/ncp/config/ncp.ini'" | grep "${var}"
}