@task
def destroy_instance(nodetype, instance_id):
 env.nodetype = nodetype
 instance = ec2_utils.GetInstance(env.region, instance_id)
 assert instance, ('Instance %s not found' % instance_id)
 with settings(host_string=instance.public_dns_name):
  if (instance.state == 'running'):
   check_min_healthy_instances(3)
   drain()
   stop()
 fprint(('Terminating instance %s' % instance_id))
 ec2_utils.TerminateInstance(env.region, instance_id)

@ task def destroy_instance ( nodetype , instance_id ) : env . nodetype = nodetype instance = ec2_utils . GetInstance ( env . region , instance_id ) assert instance , ( 'Instance %s not found' % instance_id ) with settings ( host_string = instance . public_dns_name ) : if ( instance . state == 'running' ) : check_min_healthy_instances ( 3 ) drain ( ) stop ( ) fprint ( ( 'Terminating instance %s' % instance_id ) ) ec2_utils . TerminateInstance ( env . region , instance_id )
stop and terminate an instance .