Google Compute Engine provides an Infrastructure-as-a-Service offering similar to Amazon Web Services. We support it natively in AppScale, and one of the very nice perks with GCE is that you pay for instances on a per-minute basis (after a minimum of ten minutes), as opposed to AWS, which charges you on a per-hour basis. That means if you use ten minutes of machine time in GCE, you pay for ten minutes, but with AWS, you pay for a full hour.
So we do quite a bit of hacking on both GCE and AWS, which means we create a lot of extra resources that sometimes accidentally get left around. With that, I wrote a quick script to clean some of that stuff up in GCE – let’s take a look!
To run AppScale in GCE, we automatically create a network for you, make a firewall in it, and then run instances in that firewall. That means when we tear down AppScale, we have to:
- Terminate any running instances, resembling the
- Get rid of the firewall we create, resembling
- Get rid of the network we create, resembling
We already do that for you automatically. However, when I develop AppScale on GCE, I sometimes mess things up (who knew?) and I leave networks, firewalls, and instances around. So here’s a quick script to clean all that crap up that you may find handy for your own GCE purposes. It requires
gcutil to be installed and in your
$PATH, and since I cache my project ID, you should either (1) run
--cache_flag_values on a
gcutil command to do the same, or add in
--project=<project-id> to each
gcutil command. Without further adieu, here it is!
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 38 39 40 41 42 43
Of course, it’s got a bit more copy-pasta than I would like, but it’s quick and dirty and gets the job done, so what more can you ask of a throwaway script? Hope you find it as handy as I do!