Sha256: 76f6ee29d7a44d81e6d54a15901182fc9c78f4e5f97f8a7cfeca52173e8f0c03

Contents?: true

Size: 1.73 KB

Versions: 34

Compression:

Stored size: 1.73 KB

Contents

module Kontena::Cli::Cloud::Master
  class RemoveCommand < Kontena::Command

    include Kontena::Cli::Common

    callback_matcher 'cloud-master', 'delete'

    requires_current_account_token

    parameter "[MASTER_ID]", "Master ID"

    option ['-f', '--force'], :flag, "Don't ask for confirmation"

    def delete_server(id)
      spinner "Deleting server #{id} from Kontena Cloud" do |spin|
        begin
          cloud_client.delete("user/masters/#{id}")
        rescue
          spin.fail
        end
      end
    end

    def run_interactive
      response = nil
      spinner "Retrieving a list of registered masters on Kontena Cloud" do
        response = cloud_client.get('user/masters')
        unless response && response.kind_of?(Hash) && response['data'].kind_of?(Array)
          abort pastel.red('Listing masters failed')
        end
      end

      if response['data'].empty?
        puts "No registered masters"
        return
      end

      servers_to_delete = prompt.multi_select("Select registered master(s) to delete:") do |menu|
        response['data'].each do |server|
          menu.choice "#{server['attributes']['name']} (#{server['attributes']['url'] || "?"})", server['id']
        end
      end

      if servers_to_delete.empty?
        puts "No masters selected"
      else
        puts "About to delete servers from Kontena Cloud:"
        servers_to_delete.each do |id|
          puts " * #{id}"
        end
        confirm unless self.force?
        servers_to_delete.each do |id|
          delete_server(id)
        end
      end
    end

    def execute
      if self.master_id.nil?
        run_interactive
      else
        confirm unless self.force?
        delete_server(self.master_id)
      end
      exit 0
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
krates-1.7.11 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.10 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.9 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.8 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.7 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.6 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.5 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.4 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.3 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.2 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.1 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.7.0 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.9 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.8 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.7 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.6 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.5 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.4 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.3 lib/kontena/cli/cloud/master/remove_command.rb
krates-1.6.2 lib/kontena/cli/cloud/master/remove_command.rb