-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathvpc-maintenance.sh
More file actions
executable file
·37 lines (28 loc) · 945 Bytes
/
vpc-maintenance.sh
File metadata and controls
executable file
·37 lines (28 loc) · 945 Bytes
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
#!/bin/bash
# Script related to an IBM Cloud solution tutorial
# Enable / disable the maintenance security group
#
# (C) 2019 IBM
#
# Written by Henrik Loeser, hloeser@de.ibm.com
# Exit on errors
set -e
set -o pipefail
if [ -z "$3" ]; then
echo "usage: $0 vpc-name instance-name (on | off)"
exit
fi
ACTION=$3
INSTANCE=$2
VPCNAME=$1
# Obtain NIC ID for instance
export NICID=$(ibmcloud is instances --output json |\
jq -c -r '.[] | select (.vpc.name=="'${VPCNAME}'" and .name=="'${INSTANCE}'") | .primary_network_interface.id')
export SGMAINT=$(ibmcloud is security-groups --output json |\
jq -c -r '.[] | select (.vpc.name=="'${VPCNAME}'" and .name=="'${VPCNAME}'-maintenance-sg") | .id')
if [ $ACTION = "on" ]; then
ibmcloud is security-group-network-interface-add $SGMAINT $NICID
fi
if [ $ACTION = "off" ]; then
ibmcloud is security-group-network-interface-remove $SGMAINT $NICID
fi