You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
966 B

4 years ago
  1. #!/home/alpcentaur/ProjektA/PrototypeWebApp/venv/bin/python3.5
  2. import sys
  3. from optparse import OptionParser
  4. import boto
  5. from boto.ec2 import regions
  6. def kill_instance(region, ids):
  7. """Kill an instances given it's instance IDs"""
  8. # Connect the region
  9. ec2 = boto.connect_ec2(region=region)
  10. for instance_id in ids:
  11. print("Stopping instance: %s" % instance_id)
  12. ec2.terminate_instances([instance_id])
  13. if __name__ == "__main__":
  14. parser = OptionParser(usage="kill_instance [-r] id [id ...]")
  15. parser.add_option("-r", "--region", help="Region (default us-east-1)", dest="region", default="us-east-1")
  16. (options, args) = parser.parse_args()
  17. if not args:
  18. parser.print_help()
  19. sys.exit(1)
  20. for r in regions():
  21. if r.name == options.region:
  22. region = r
  23. break
  24. else:
  25. print("Region %s not found." % options.region)
  26. sys.exit(1)
  27. kill_instance(region, args)