Bug 1108765 - Allow terminate without prompt - r=rail
authorChris Cooper <ccooper@deadsquid.com>
Tue, 09 Dec 2014 13:16:24 -0500
changeset 581 88793244bf39f103cda162513208b3d9f34599e1
parent 580 502e91eb28758339e8a625305f5b24a2b1a5f27b
child 582 8f612e3407dedd8acbef9407a70f381177989f38
push id572
push usercoop@mozilla.com
push dateTue, 09 Dec 2014 18:16:31 +0000
reviewersrail
bugs1108765
Bug 1108765 - Allow terminate without prompt - r=rail
scripts/aws_manage_instances.py
--- a/scripts/aws_manage_instances.py
+++ b/scripts/aws_manage_instances.py
@@ -58,26 +58,29 @@ def disable(i, dry_run, comments=None):
     log.info("Disabling %s, setting moz-state tag to '%s'..." % (name,
                                                                  moz_state))
     if dry_run:
         log.info("Dry run mode, skipping...")
     else:
         i.add_tag("moz-state", moz_state)
 
 
-def terminate(i, dry_run):
+def terminate(i, dry_run, force=None):
     name = i.tags.get('Name', '')
     log.info("Terminating %s..." % name)
 
     if dry_run:
         log.info("Dry run mode, skipping...")
         return
 
-    yesno = raw_input("WARNING: you are about to terminate %s! "
-                      "Are you sure? [y/N] " % name)
+    if force:
+        yesno = "y"
+    else:
+        yesno = raw_input("WARNING: you are about to terminate %s! "
+                          "Are you sure? [y/N] " % name)
     if yesno == "y":
         i.terminate()
         log.info("%s terminated" % name)
     else:
         log.info("%s NOT terminated" % name)
 
 
 def status(i):
@@ -109,16 +112,18 @@ if __name__ == '__main__':
                         help="action to be performed")
     parser.add_argument("-m", "--comments", help="reason to disable")
     parser.add_argument("-n", "--dry-run", action="store_true",
                         help="Dry run mode")
     parser.add_argument("-q", "--quiet", action="store_true",
                         help="Supress logging messages")
     parser.add_argument("hosts", metavar="host", nargs="+",
                         help="hosts to be processed")
+    parser.add_argument("-f", "--force", action="store_true",
+                        help="Force action without prompting")
 
     args = parser.parse_args()
 
     logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s")
     if not args.quiet:
         log.setLevel(logging.INFO)
     else:
         log.setLevel(logging.ERROR)
@@ -146,11 +151,11 @@ if __name__ == '__main__':
                     stop(i, args.dry_run)
                 elif args.action == "restart":
                     restart(i, args.dry_run)
                 elif args.action == "enable":
                     enable(i, args.dry_run)
                 elif args.action == "disable":
                     disable(i, args.dry_run, args.comments)
                 elif args.action == "terminate":
-                    terminate(i, args.dry_run)
+                    terminate(i, args.dry_run, args.force)
                 elif args.action == "status":
                     status(i)