0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IBM Cloud: VPC Custom Routesの切り替えスクリプト・サンプル

Last updated at Posted at 2020-11-24

#はじめに
IBM Cloud: VPC Custom Routesを利用したAZまたぎのHA環境の構成例(VPC内部からのアクセス)という記事を書いたが、この経路変更を障害時に手動で行うわけにはいかないので、自動実行できるように切り替えのスクリプトを書いてみた。

#スクリプトサンプル

ibmcloud_apikeyというファイルにAPI Keyを記載しておく。

vpcrouteswitch.sh
#!/bin/sh
#Usage example: ./vpcrouteswitch.sh 10.1.0.7

#Environment
export LANG=C
VPC_ID=r022-85621b2c-a349-4ae6-87e3-767ddeac7298
ROUTING_TABLE_ID=r022-904f9ad6-86b7-42fc-959a-c17a80c60577
ZONE1=jp-tok-1
ZONE2=jp-tok-2
ZONE3=jp-tok-3
DELETE_NEXT_HOP1=10.0.0.7
DELETE_NEXT_HOP2=10.1.0.7
NEXT_HOP=$1
DESTINATION_CIDR=192.168.10.10/32

#Variables Check
if [ $# -ne 1 ]; then
  echo "Sorry, we had a problem there!"
  exit 1
fi

#Login
ibmcloud login -a cloud.ibm.com --apikey @ibmcloud_apikey -r jp-tok

#LIST EXISTING ROUTE
ROUTE_IDS=$(ibmcloud is vpc-routing-table-routes ${VPC_ID} ${ROUTING_TABLE_ID} | grep -e ${DELETE_NEXT_HOP1} -e ${DELETE_NEXT_HOP2} | awk '{print $1}')
echo ${ROUTE_IDS}

#DELETE ROUTES
ibmcloud is vpc-routing-table-route-delete ${VPC_ID} ${ROUTING_TABLE_ID} $(echo ${ROUTE_IDS}) -f


#CREATE NEW ROUTES
ibmcloud is vpc-routing-table-route-create ${VPC_ID} ${ROUTING_TABLE_ID} --zone ${ZONE1} --destination ${DESTINATION_CIDR} --next-hop ${NEXT_HOP} --action deliver
ibmcloud is vpc-routing-table-route-create ${VPC_ID} ${ROUTING_TABLE_ID} --zone ${ZONE2} --destination ${DESTINATION_CIDR} --next-hop ${NEXT_HOP} --action deliver
ibmcloud is vpc-routing-table-route-create ${VPC_ID} ${ROUTING_TABLE_ID} --zone ${ZONE3} --destination ${DESTINATION_CIDR} --next-hop ${NEXT_HOP} --action deliver

実行例

10.1.0.7に切り替えたい時。
# ./vpcrouteswitch.sh 10.1.0.7

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?