Sha256: aa3b62cf28d54b1e7f00f9963234658acca99068347e6ff3522acf55cc599d14

Contents?: true

Size: 1.72 KB

Versions: 29

Compression:

Stored size: 1.72 KB

Contents

module Ey
  module Core
    module Cli
      module Helpers
        class ServerSieve
          ROLES = [
            :app_servers,
            :db_servers,
            :db_master,
            :utilities
          ]

          attr_reader :servers_api, :options

          def self.filter(servers_api, options = {})
            new(servers_api, options).filtered
          end

          def initialize(servers_api, options = {})
            @servers_api = servers_api
            @options = options
          end

          def filtered
            return all_servers if requested?(:all)

            requested_roles.map {|role|
              role == :utilities ? utils_named(option(:utilities)) : send(role)
            }.flatten.uniq
          end

          private
          def requested_roles
            #self.class::
            ROLES.select {|role| requested?(role)}
          end

          def option(name)
            options[name]
          end

          def requested?(name)
            option(name)
          end

          def all_servers
            servers_api.all.to_a.uniq
          end

          def app_servers
            ['app_master', 'app', 'solo'].
              map {|role| servers_api.all(role: role).to_a}.
              flatten
          end

          def db_servers
            db_master + servers_api.all(role: 'db_slave').to_a
          end

          def db_master
            ['db_master', 'solo'].
              map {|role| servers_api.all(role: role).to_a}.
              flatten
          end

          def utils_named(name)
            filter = {role: 'util'}
            filter[:name] = name unless name.downcase == 'all'

            servers_api.all(filter).to_a
          end
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
ey-core-3.6.0.autoscaling1 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.6.1 lib/ey-core/cli/helpers/server_sieve.rb
groove-ey-core-3.6.3 lib/ey-core/cli/helpers/server_sieve.rb
groove-ey-core-3.6.2 lib/ey-core/cli/helpers/server_sieve.rb
groove-ey-core-3.6.1 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.5.0 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.4.4 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.4.2 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.4.1 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.4.0 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.3.1 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.3.0 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.2.6 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.2.5 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.2.4 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.2.3 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.2.2 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.2.1 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.2.0 lib/ey-core/cli/helpers/server_sieve.rb
ey-core-3.1.11 lib/ey-core/cli/helpers/server_sieve.rb