lib/meroku/infrastructure.rb in meroku-2.0.8 vs lib/meroku/infrastructure.rb in meroku-2.0.9

- old
+ new

@@ -1,26 +1,23 @@ -require "meroku/infrastructure/node" +require 'meroku/infrastructure/server' module Meroku + # Logic related to the infratructure that powers meroku module Infrastructure + extend Meroku::Aws::Ec2 - def spawn(session) - node = Meroku::Infrastructure::Node.new(session.ec2_client) - node.associate_address - node.install_packages - node.tweak_configuration - node.install_frontend_app - puts "spawned #{node.instance.try(:instance_id)}" + def self.servers + ec2_client.describe_instances( + filters: [ + { name: 'tag:Name', values: ['node'] }, + { name: 'instance-state-name', values: %w[running pending] } + ] + ).reservations.map do |xx| + Meroku::Infrastructure::Server.new(xx.instances.first.instance_id) + end end - def despawn - instances = ec2_client.describe_instances(filters:[{ name: "tag:Name", values: ['node'] }, { name: 'instance-state-name', values: ['running','pending'] }]).reservations.map { |xx| xx.instances.first.instance_id } - puts "will despawn #{instances.inspect}" - ec2_client.terminate_instances({ - instance_ids: instances - }) if instances.size > 0 + def self.each_server + servers.each { |s| yield s } end - - end - end