Index: appengine/chrome_infra_mon_proxy/scripts/nat_setup.sh |
diff --git a/appengine/chrome_infra_mon_proxy/scripts/nat_setup.sh b/appengine/chrome_infra_mon_proxy/scripts/nat_setup.sh |
new file mode 100755 |
index 0000000000000000000000000000000000000000..6f4a40fe7501f2bef91f12eccd958bd14e351f7d |
--- /dev/null |
+++ b/appengine/chrome_infra_mon_proxy/scripts/nat_setup.sh |
@@ -0,0 +1,56 @@ |
+#!/bin/bash |
+# Run this script from its directory, to correctly pick up nat_startup.sh: |
ghost stip (do not use)
2015/04/14 00:36:43
this is intended for humans, not some automated th
Sergey Berezin (google)
2015/04/16 04:39:07
Yes. This is how I'd fix a fried NAT box when I ge
|
+# cd scripts |
+# ./nat_setup.sh |
+ |
+PROJECT="chrome-infra-mon-proxy" |
+REGION="us-central1" |
+INSTANCE_TYPE="n1-standard-2" |
+GAE_VM1_TAG="managed-gae-vm1" |
+GAE_VM2_TAG="managed-gae-vm2" |
+GAE_VM3_TAG="managed-gae-vm3" |
+ |
+function delete_instance { |
+ # delete_instance instance-name zone-name |
+ gcloud compute -q --project "$PROJECT" instances delete "$1" --zone "$2" |
+} |
+function create_instance { |
+ # create_instance instance-name zone-name ip-name |
+ gcloud compute -q --project "$PROJECT" instances create $1 --project "$PROJECT" --machine-type $INSTANCE_TYPE --zone $2 --image ubuntu-14-04 --network default --can-ip-forward --tags nat --address $3 --metadata-from-file startup-script=nat_startup.sh |
+} |
+ |
+function create_nat_route { |
+ # create_nat_route route-name tag instance-name instance-zone |
+ echo "Creating new route to hijack traffic from VM tag $2" |
+ gcloud compute --project "$PROJECT" routes create "$1" --network default --destination-range 0.0.0.0/0 --next-hop-instance "$3" --next-hop-instance-zone "$4" --tags "$2" --priority 800 |
+} |
+ |
+function delete_nat_backend { |
+ # Deletes NAT routes. |
+ gcloud compute --project "$PROJECT" routes delete managed-vm1-nat-route |
+ gcloud compute --project "$PROJECT" routes delete managed-vm2-nat-route |
+ gcloud compute --project "$PROJECT" routes delete managed-vm3-nat-route |
+} |
+ |
+function create_nat_backend { |
+ create_nat_route managed-vm1-nat-route "$GAE_VM1_TAG" nat-box1 "$REGION-a" |
+ create_nat_route managed-vm2-nat-route "$GAE_VM2_TAG" nat-box2 "$REGION-b" |
+ create_nat_route managed-vm3-nat-route "$GAE_VM3_TAG" nat-box3 "$REGION-f" |
+} |
+ |
+# Respin the NAT box VMs. Controlled individually, in case only some |
+# of them have problems. |
+if false; then |
+ delete_instance nat-box1 "$REGION-a" |
+ create_instance nat-box1 "$REGION-a" proxy1 |
+fi |
+ |
+if false; then |
+ delete_instance nat-box2 "$REGION-b" |
+ create_instance nat-box2 "$REGION-b" proxy2 |
+fi |
+ |
+if false; then |
+ delete_instance nat-box3 "$REGION-f" |
+ create_instance nat-box3 "$REGION-f" proxy3 |
+fi |