Class: Ufo::Destroy

Inherits:
Object
  • Object
show all
Includes:
AwsService, Util
Defined in:
lib/ufo/destroy.rb

Instance Method Summary collapse

Methods included from AwsService

#cloudwatchlogs, #ecr, #ecs, #elb

Methods included from Util

#default_cluster, #default_params, #display_params, #execute, #pretty_time, #settings

Constructor Details

#initialize(service, options = {}) ⇒ Destroy

Returns a new instance of Destroy.



6
7
8
9
10
# File 'lib/ufo/destroy.rb', line 6

def initialize(service, options={})
  @service = service
  @options = options
  @cluster = @options[:cluster] || default_cluster
end

Instance Method Details

#are_you_sure?Boolean

Returns:

  • (Boolean)


52
53
54
55
56
57
58
# File 'lib/ufo/destroy.rb', line 52

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."
  print "Are you sure you want to do this? (y/n) "
  answer = $stdin.gets.strip
  answer =~ /^y/
end

#byeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ufo/destroy.rb', line 12

def bye
  unless are_you_sure?
    puts "Phew, that was close"
    exit
  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."
    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]
end