Class: Ec2spec::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ec2spec/client.rb

Constant Summary collapse

META_DATA_URL_BASE =
'http://169.254.169.254/latest/meta-data/'
META_DATA_INSTANCE_TYPE_PATH =
'/instance-type'
META_DATA_INSTANCE_ID_PATH =
'/instance-id'
DEFAULT_REGION =
'ap-northeast-1'
OUTPUT_FORMATTERS =
{
  plain_text: Formatter::PlainTextFormatter,
  json:       Formatter::JsonFormatter,
  hash:       Formatter::HashFormatter,
  slack:      Formatter::SlackFormatter,
  markdown:   Formatter::MarkdownFormatter,
}
CONNECTION_ERROR_WITH_MESSAGES =
{
  Errno::ECONNREFUSED         => 'Connection refused: %{host}',
  Net::SSH::ConnectionTimeout => 'Connection timeout: %{host}',
  StandardError               => 'Unknown error: %{host}',
}

Instance Method Summary collapse

Constructor Details

#initialize(hosts, days, format, region = DEFAULT_REGION) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
32
33
34
35
36
# File 'lib/ec2spec/client.rb', line 27

def initialize(hosts, days, format, region = DEFAULT_REGION)
  @hosts = hosts
  @days = days
  @format = format
  @region = region

  Initializer.instance.do(region)

  extend_formatter
end

Instance Method Details

#prepare_price_calculator(unit, rate, calc_type, app_id = nil) ⇒ Object



38
39
40
# File 'lib/ec2spec/client.rb', line 38

def prepare_price_calculator(unit, rate, calc_type, app_id = nil)
  PriceCalculator.instance.prepare(unit, rate, calc_type, app_id)
end

#runObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/ec2spec/client.rb', line 42

def run
  hosts = @hosts.map { |host| target(host) }
  threads = hosts.map do |host|
    Thread.start(host.backend) do |backend|
      exec_host_result(host, backend)
    end
  end
  results = threads.each(&:join).map(&:value)
  output(results, @hosts)
end