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

Source Code for Module starcluster.commands.terminate

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