Sha256: 66e259a4af7e6b71877be63c3a3ff45f6f5a1481a3569969d48e8ff8b5ddf3a2

Contents?: true

Size: 1.65 KB

Versions: 14

Compression:

Stored size: 1.65 KB

Contents

module Ufo
  class Destroy
    include Defaults
    include AwsServices

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

    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

    def are_you_sure?
      return true if @options[:sure]
      puts "You are about to destroy #{@service} service on #{@cluster} cluster."
      print "Are you sure you want to do this? (y/n) "
      answer = $stdin.gets.strip
      answer =~ /^y/
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ufo-2.2.2 lib/ufo/destroy.rb
ufo-2.2.1 lib/ufo/destroy.rb
ufo-2.2.0 lib/ufo/destroy.rb
ufo-2.1.0 lib/ufo/destroy.rb
ufo-2.0.3 lib/ufo/destroy.rb
ufo-2.0.2 lib/ufo/destroy.rb
ufo-2.0.1 lib/ufo/destroy.rb
ufo-2.0.0 lib/ufo/destroy.rb
ufo-1.7.1 lib/ufo/destroy.rb
ufo-1.7.0 lib/ufo/destroy.rb
ufo-1.6.2 lib/ufo/destroy.rb
ufo-1.6.1 lib/ufo/destroy.rb
ufo-1.6.0 lib/ufo/destroy.rb
ufo-1.5.0 lib/ufo/destroy.rb