0
0

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 address prefixの切り替えスクリプト・サンプル

Last updated at Posted at 2020-11-26

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

#スクリプトサンプル

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

vpcprefixswitch.sh
#!/bin/sh
#Usage example: ./vpcrouteswitch.sh jp-tok-1
export LANG=C

VPC_ID=r022-85621b2c-a349-4ae6-87e3-767ddeac7298
PREFIX_CIDR=192.168.10.0/28
PREFIX_NAME=cidr-192-168-10-0-28
ZONE_NAME=$1

#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
PREFIX_IDS=$(ibmcloud is vpc-address-prefixes ${VPC_ID} | grep ${PREFIX_CIDR} | awk '{print $1}')
echo ${PREFIX_IDS}

#DELETE ROUTES
ibmcloud is vpc-address-prefix-delete ${VPC_ID} $(echo ${PREFIX_IDS}) -f


#CREATE NEW ROUTES
ibmcloud is vpc-address-prefix-create ${PREFIX_NAME} ${VPC_ID} ${ZONE_NAME} ${PREFIX_CIDR}

#実行例

# ./vpcprefixswitch.sh jp-tok-2
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?