class Opsicle::Questionnaire::EipInquiry

Attributes

cli[RW]
opsworks_adapter[RW]

Public Class Methods

new(options) click to toggle source
# File lib/opsicle/questionnaire/eip_inquiry.rb, line 6
def initialize(options)
  self.opsworks_adapter = options[:opsworks_adapter]
  self.cli = options[:highline_client]
end

Public Instance Methods

which_eip_should_move(eip_information) click to toggle source
# File lib/opsicle/questionnaire/eip_inquiry.rb, line 11
def which_eip_should_move(eip_information)
  puts "\nHere are all of the EIPs for this stack:"
  print_current_eips(eip_information)
  eip_index = ask_eip_question("Which EIP would you like to move?\n", eip_information)
  eip_information[eip_index]
end
which_instance_should_get_eip(moveable_eip) click to toggle source
# File lib/opsicle/questionnaire/eip_inquiry.rb, line 18
def which_instance_should_get_eip(moveable_eip)
  puts "\nHere are all of the instances in the current instance's layer:"
  instances = get_potential_target_instances(moveable_eip)
  check_for_printable_items!(instances)
  print_potential_target_instances(instances)
  instance_index = ask_eip_question("What is your target instance?\n", instances)
  instances[instance_index].instance_id
end

Private Instance Methods

ask_eip_question(prompt, choices) click to toggle source
# File lib/opsicle/questionnaire/eip_inquiry.rb, line 27
def ask_eip_question(prompt, choices)
  @cli.ask(prompt, Integer) { |q| q.in = 1..choices.length.to_i } - 1
end
check_for_printable_items!(instances) click to toggle source
# File lib/opsicle/questionnaire/eip_inquiry.rb, line 52
def check_for_printable_items!(instances)
  if instances.empty? # instances is the list of instances that an eip can be moved to
    raise StandardError, "You cannot move an EIP when there's only one instance running."
  end
end
get_potential_target_instances(moveable_eip) click to toggle source
# File lib/opsicle/questionnaire/eip_inquiry.rb, line 42
def get_potential_target_instances(moveable_eip)
  instances = @opsworks_adapter.instances_by_layer(moveable_eip[:layer_id])
  instances.select do |instance|
    instance.elastic_ip.nil? &&
    instance.auto_scaling_type.nil? &&
    instance.status == "online"
  end
end
print_current_eips(eip_information) click to toggle source
print_potential_target_instances(instances) click to toggle source