Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added -r (region) option to kill_instance command
- Loading branch information
1 parent
3c0787e
commit 1f78b4b
Showing
1 changed file
with
31 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
#!/usr/bin/env python | ||
def kill_instance(instance_id): | ||
"""Kill an instance given it's instance ID""" | ||
import boto | ||
ec2 = boto.connect_ec2() | ||
print "Stopping instance: %s" % instance_id | ||
ec2.terminate_instances([instance_id]) | ||
|
||
import sys | ||
from optparse import OptionParser | ||
|
||
import boto | ||
from boto.ec2 import regions | ||
|
||
|
||
|
||
def kill_instance(region, ids): | ||
"""Kill an instances given it's instance IDs""" | ||
# Connect the region | ||
ec2 = boto.connect_ec2(region=region) | ||
for instance_id in ids: | ||
print "Stopping instance: %s" % instance_id | ||
ec2.terminate_instances([instance_id]) | ||
|
||
|
||
if __name__ == "__main__": | ||
import sys | ||
kill_instance(sys.argv[1]) | ||
parser = OptionParser(usage="kill_instance [-r] id [id ...]") | ||
parser.add_option("-r", "--region", help="Region (default us-east-1)", dest="region", default="us-east-1") | ||
(options, args) = parser.parse_args() | ||
if not args: | ||
parser.print_help() | ||
sys.exit(1) | ||
for r in regions(): | ||
if r.name == options.region: | ||
region = r | ||
break | ||
else: | ||
print "Region %s not found." % options.region | ||
sys.exit(1) | ||
|
||
kill_instance(region, args) |