lib/ufo/destroy.rb in ufo-3.5.7 vs lib/ufo/destroy.rb in ufo-4.0.0
- old
+ new
@@ -1,58 +1,27 @@
module Ufo
- class Destroy
- include Util
- include AwsService
-
- def initialize(service, options={})
- @service = service
- @options = options
- @cluster = @options[:cluster] || default_cluster
- end
-
+ class Destroy < Base
def bye
unless are_you_sure?
puts "Phew, that was close"
- exit
+ return
end
- clusters = ecs.describe_clusters(clusters: [@cluster]).clusters
- if clusters.size < 1
- puts "The #{@cluster} cluster does not exist so there can be no service on that cluster to delete."
+ stack = find_stack(@stack_name)
+ unless stack
+ puts "Stack #{@stack_name} does not exit"
exit
end
- services = ecs.describe_services(cluster: @cluster, services: [@service]).services
- service = services.first
- if service.nil?
- puts "Unable to find #{@service} service to delete it."
- exit
- end
- if service.status != "ACTIVE"
- puts "The #{@service} service is not ACTIVE so no need to delete it."
- exit
- end
-
- # changes desired size to 0
- ecs.update_service(
- desired_count: 0,
- cluster: @cluster,
- service: @service
- )
- # Cannot find all tasks scoped to a service. Only scoped to a cluster.
- # So will not try to stop the tasks.
- # ask to stop them
- #
- resp = ecs.delete_service(
- cluster: @cluster,
- service: @service
- )
- puts "#{@service} service has been scaled down to 0 and destroyed." unless @options[:mute]
+ cloudformation.delete_stack(stack_name: @stack_name)
+ puts "Deleting CloudFormation stack with ECS resources: #{@stack_name}."
+ return unless @options[:wait]
+ status.wait
end
def are_you_sure?
return true if @options[:sure]
- puts "You are about to destroy #{@service.colorize(:green)} service on the #{@cluster.colorize(:green)} cluster."
+ puts "You are about to destroy #{@pretty_service_name.colorize(:green)} service on the #{@cluster.colorize(:green)} cluster."
print "Are you sure you want to do this? (y/n) "
answer = $stdin.gets.strip
answer =~ /^y/
end
end