Class: Ec2spec::Client
- Inherits:
-
Object
- Object
- Ec2spec::Client
- 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
-
#initialize(hosts, days, format, region = DEFAULT_REGION) ⇒ Client
constructor
A new instance of Client.
- #prepare_price_calculator(unit, rate, calc_type, app_id = nil) ⇒ Object
- #run ⇒ Object
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 |
#run ⇒ Object
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 |