Skip to content

Instantly share code, notes, and snippets.

@gowatana
Last active November 24, 2021 15:55
Show Gist options
  • Save gowatana/f2487e88f6f0daeeacd00362cc64532c to your computer and use it in GitHub Desktop.
Save gowatana/f2487e88f6f0daeeacd00362cc64532c to your computer and use it in GitHub Desktop.
VMUG vExpert が語る HOL。のサンプル | https://www.youtube.com/watch?v=vsuMcBxZ6-g

HoL を使ったデモ(NSX-T タグによる仮想マシン通信の遮断)

録画

2021/11/22(月)
おすすめ HOL と、HOL を使ったデモ NSX-T タグによる仮想マシン通信の遮断 - Go Watanabe
https://www.youtube.com/watch?v=vsuMcBxZ6-g&list=PLo45fa-pfArtFRVRpxMZAXfAyspIv3fFP&index=4

vExpertが語る会についてはこちら。
https://github.com/gowatana/japan-vmug-vexpert-talks

使用する HoL、API リファレンス

NSX Distributed Firewall Lightning Lab (HOL-2226-91-SEC)
https://labs.hol.vmware.com/HOL/catalogs/lab/10959

上記のHOLを利用して、デモ対象 VM は web-01a、IP は 172.16.10.11
API は、Linux(VCSA vcsa-01a)から curl で実行。

NSX-T Data Center REST API 3.1.2
https://developer.vmware.com/apis/1163/nsx-t

準備

  • Chrome は Languages を Japanese に変更。(NSX Manager 日本語化のため)
  • DFW ポリシーを作成しておく(policy-vmug-01)
  • DFW ルールを作成しておく(rule-tag-isolation)
    • 宛先(Destination)または 適用先(Apply to)で isolation-tag がメンバーのグループ作成・指定しておく。
    • Action は Reject(拒否)

NSX Manager で、手作業で VM にタグを付与

  • コンソールから、VM(web-01a)に Ping
  • 手動でVM(web-01a)にタグ付与 → 遮断遮断される
    • 手動でVM(web-01a)からタグ削除 → 通信可能になる

VCSA にログインして、そこから curl 実行。

ログインアカウントと NSX Manager のアドレスを変数代入。
※キーボードはEnglish(US)のまま。

USER=nsx-admin@corp.local
PASS='VMware1!'
MGR=nsxmgr-01a

VM の名前 → UUID の確認。

curl -ks -u "$USER:$PASS" https://$MGR/api/v1/fabric/virtual-machines | egrep 'external_id|"display_name'

web-01a の UUID を変数に代入しておく。

VMUUID=$(curl -ks -u "$USER:$PASS" https://$MGR/api/v1/fabric/virtual-machines | egrep 'external_id|"display_name' | grep web-01a -B1 | head -1 | cut -d \" -f 4)
echo $VMUUID

ヒアドキュメントでJSONファイル作成しておく。(isolation-tag.json)

cat << EOF > ./isolation-tag.json
{
  "external_id": "$VMUUID",
  "tags": [
    {"tag": "isolation-tag"}
  ]
}
EOF

VM に、タグを付与する。→ 通信遮断される

curl -ks -u "$USER:$PASS" -H "Content-Type: application/json" -X POST -d @./isolation-tag.json "https://$MGR/api/v1/fabric/virtual-machines?action=add_tags"

VM から、タグを解除する。→ 通信可能になる

curl -ks -u "$USER:$PASS" -H "Content-Type: application/json" -X POST -d @./isolation-tag.json "https://$MGR/api/v1/fabric/virtual-machines?action=remove_tags"

EOF

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment