File: oci-update-cluster-certs

package info (click to toggle)
openstack-cluster-installer 43.0.22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,544 kB
  • sloc: php: 19,169; sh: 18,137; ruby: 75; makefile: 31; xml: 8
file content (91 lines) | stat: -rwxr-xr-x 3,184 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

set -e
#set -x

unset SSH_AUTH_SOCK
API_ONLY=false

usage (){
	echo "$0 <CLUSTER_NAME> [--api-only]"
}

if [ $# -gt 2 ]; then
	usage
	exit 1
fi

for c in $(seq $#); do
	if [ "$1" = '-h' ] ; then
		usage
		exit 0
	elif [ "$1" = '--api-only' ]; then
		API_ONLY=true
		shift
	else
		CLUSTER_NAME=${1}
		shift
	fi
done

CLUSTER_DOMAIN=$(ocicli -csv cluster-show ${CLUSTER_NAME} | grep "Domain:" | cut -d, -f2)
VIP_FQDN=$(ocicli -csv cluster-show ${CLUSTER_NAME} | grep "VIP Hostname:" | cut -d, -f2)
if [ -z "${VIP_FQDN}" ] ; then
	VIP_FQDN=${CLUSTER_NAME}-api.${CLUSTER_DOMAIN}
fi

CLUSTER_ID=$(ocicli -csv cluster-list | q -H -d, "SELECT id FROM - WHERE name='"${CLUSTER_NAME}"'")

SCP="scp -i /etc/openstack-cluster-installer/id_rsa"
SSH="ssh -i /etc/openstack-cluster-installer/id_rsa"

for res in $(ocicli -csv machine-list --all | q -H -d, "SELECT hostname, role FROM - WHERE status='installed' AND cluster='"${CLUSTER_NAME}"'") ; do
	SRV=$(echo $res | awk -F ',' '{ print $1 }')
	ROLE=$(echo $res | awk -F ',' '{ print $2 }')
	#ROLE=$(echo $SRV | cut -d. -f1 | cut -d- -f2)
	if ! $API_ONLY; then
		echo "===> Updating $SRV"
		echo "-> Machine is a $ROLE"
	fi

	if [ "$ROLE" = "controller" ] || [ "$ROLE" = "swiftproxy" ]; then
		if $API_ONLY; then
			echo "===> Updating $SRV"
			echo "-> Machine is a $ROLE"
		fi
		echo "-> Copying API key and certs"
		${SCP} /var/lib/oci/ssl/slave-nodes/${VIP_FQDN}/${VIP_FQDN}.crt $SRV:/etc/ssl/certs/oci-pki-api.crt
		if [ -e /var/lib/oci/ssl/slave-nodes/${VIP_FQDN}/${VIP_FQDN}.csr ] ; then
			${SCP} /var/lib/oci/ssl/slave-nodes/${VIP_FQDN}/${VIP_FQDN}.csr $SRV:/etc/ssl/certs/oci-pki-api.csr
		fi
		${SCP} /var/lib/oci/ssl/slave-nodes/${VIP_FQDN}/${VIP_FQDN}.pem $SRV:/etc/ssl/private/oci-pki-api.pem
		${SCP} /var/lib/oci/ssl/slave-nodes/${VIP_FQDN}/${VIP_FQDN}.key $SRV:/etc/ssl/private/oci-pki-api.key
	fi
	if [ "$ROLE" = "swiftproxy" ]; then
		${SCP} /var/lib/oci/ssl/slave-nodes/${VIP_FQDN}/${VIP_FQDN}.key $SRV:/etc/ssl/private/oci-pki-swiftproxy.key
		${SCP} /var/lib/oci/ssl/slave-nodes/${VIP_FQDN}/${VIP_FQDN}.pem $SRV:/etc/ssl/private/oci-pki-swiftproxy.pem
	fi

	if ! $API_ONLY; then
		echo "-> Copying root CA"
		${SCP} /var/lib/oci/ssl/ca/oci-pki-oci-ca-chain.pem $SRV:/etc/ssl/certs/oci-pki-oci-ca-chain.pem
		${SCP} /var/lib/oci/ssl/ca/oci-pki-oci-ca.pem       $SRV:/etc/ssl/certs/oci-pki-oci-ca.pem
		${SCP} /var/lib/oci/ssl/ca/oci-pki-root-ca.pem      $SRV:/etc/ssl/certs/oci-pki-root-ca.pem

		echo "-> Copy the node's certs"
		${SCP} /var/lib/oci/ssl/slave-nodes/$SRV/$SRV.key $SRV:/etc/ssl/private/ssl-cert-snakeoil.key
		${SCP} /var/lib/oci/ssl/slave-nodes/$SRV/$SRV.crt $SRV:/etc/ssl/certs/ssl-cert-snakeoil.pem
	fi

	if $API_ONLY; then
		if ([ "$ROLE" = "controller" ] || [ "$ROLE" = "swiftproxy" ]); then
			echo "===> Restarting API services on $SRV"
			${SCP} /usr/bin/oci-update-cluster-certs-restart-services $SRV:/usr/bin
			${SSH} $SRV /usr/bin/oci-update-cluster-certs-restart-services --api-only
		fi
	else
		echo "===> Restarting services on $SRV"
		${SCP} /usr/bin/oci-update-cluster-certs-restart-services $SRV:/usr/bin
		${SSH} $SRV /usr/bin/oci-update-cluster-certs-restart-services
	fi
done