Sha256: af784b3a6de3459b2cce28bec42ebaa47c4c72531c207e76174ea3a80b7c0885

Contents?: true

Size: 1.68 KB

Versions: 13

Compression:

Stored size: 1.68 KB

Contents

module Ufo
  class Destroy
    include Util
    include AwsService

    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.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
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ufo-3.5.7 lib/ufo/destroy.rb
ufo-3.5.6 lib/ufo/destroy.rb
ufo-3.5.5 lib/ufo/destroy.rb
ufo-3.5.4 lib/ufo/destroy.rb
ufo-3.5.3 lib/ufo/destroy.rb
ufo-3.5.2 lib/ufo/destroy.rb
ufo-3.5.1 lib/ufo/destroy.rb
ufo-3.5.0 lib/ufo/destroy.rb
ufo-3.4.4 lib/ufo/destroy.rb
ufo-3.4.3 lib/ufo/destroy.rb
ufo-3.4.2 lib/ufo/destroy.rb
ufo-3.4.1 lib/ufo/destroy.rb
ufo-3.4.0 lib/ufo/destroy.rb