Class: Elastip::Elastip
- Inherits:
-
Object
- Object
- Elastip::Elastip
- Defined in:
- lib/elastip.rb
Instance Method Summary collapse
- #inactive_instances(terminate: false) ⇒ Object
-
#initialize(project, env, all: false) ⇒ Elastip
constructor
A new instance of Elastip.
- #ip ⇒ Object
Constructor Details
#initialize(project, env, all: false) ⇒ Elastip
Returns a new instance of Elastip.
8 9 10 11 12 13 |
# File 'lib/elastip.rb', line 8 def initialize(project, env, all: false) abort "You need to specify a project and an environnement (e.g staging,production)" if !project or !env @project_re = Regexp.new(project) @env = env @all = all end |
Instance Method Details
#inactive_instances(terminate: false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/elastip.rb', line 34 def inactive_instances(terminate: false) inactive_envs = environments.map do |env| if @project_re =~ env[:application_name].downcase && env[:environment_name].include?(@env) if env[:cname] =~ /inactive/ && env[:status] == 'Ready' env end end end.compact if terminate inactive_envs.each do |env| STDERR.puts "terminate: #{env[:environment_name]}" ebs.terminate_environment(environment_name: env[:environment_name]) end end inactive_envs end |
#ip ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/elastip.rb', line 15 def ip active_envs = environments.map do |env| if @project_re =~ env[:application_name].downcase && env[:environment_name].include?(@env) if @all || (env[:health] == 'Green' && env[:status] == 'Ready') env[:environment_name] end end end.compact instances = ec2_instances target_instances = active_envs.map do |active| instance = instances.find{|x| x[:tags].any?{|y| active == y[:value] } && x[:state][:name] != 'terminated'} {instance: active, ip: instance[:private_ip_address]} if instance end.compact STDERR.puts target_instances.inspect target_instances.map{|x| x[:ip]} end |