Package starcluster :: Package commands :: Module terminate
[hide private]
[frames] | no frames]

Source Code for Module starcluster.commands.terminate

 1  from starcluster import exception 
 2  from starcluster.logger import log 
 3   
 4  from completers import ClusterCompleter 
 5   
 6   
7 -class CmdTerminate(ClusterCompleter):
8 """ 9 terminate [options] <cluster_tag> ... 10 11 Terminate a running or stopped cluster 12 13 Example: 14 15 $ starcluster terminate mycluster 16 17 This will terminate a currently running or stopped cluster tagged 18 "mycluster". 19 20 All nodes will be terminated, all spot requests (if any) will be 21 cancelled, and the cluster's security group will be removed. If the 22 cluster uses EBS-backed nodes then each node's root volume will be 23 deleted. If the cluster uses "cluster compute" instance types the 24 cluster's placement group will also be removed. 25 """ 26 names = ['terminate'] 27
28 - def addopts(self, parser):
29 parser.add_option("-c", "--confirm", dest="confirm", 30 action="store_true", default=False, 31 help="Do not prompt for confirmation, " 32 "just terminate the cluster")
33
34 - def terminate_cluster(self, cluster_name):
35 cl = self.cm.get_cluster(cluster_name, require_keys=False) 36 if not self.opts.confirm: 37 action = 'Terminate' 38 if cl.is_ebs_cluster(): 39 action = 'Terminate EBS' 40 resp = raw_input( 41 "%s cluster %s (y/n)? " % (action, cluster_name)) 42 if resp not in ['y', 'Y', 'yes']: 43 log.info("Aborting...") 44 return 45 cl.terminate_cluster()
46
47 - def terminate_manually(self, cluster_name):
48 cl = self.cm.get_cluster(cluster_name, load_receipt=False) 49 if not self.opts.confirm: 50 resp = raw_input("Terminate cluster %s (y/n)? " % cluster_name) 51 if resp not in ['y', 'Y', 'yes']: 52 log.info("Aborting...") 53 return 54 insts = cl.cluster_group.instances() 55 for inst in insts: 56 log.info("Terminating %s" % inst.id) 57 inst.terminate() 58 cl.terminate_cluster()
59
60 - def execute(self, args):
61 if not args: 62 self.parser.error("please specify a cluster") 63 for cluster_name in args: 64 try: 65 self.terminate_cluster(cluster_name) 66 except exception.IncompatibleCluster: 67 self.terminate_manually(cluster_name)
68