Exemplo n.º 1
0
def _add_instance(elb, elb_zones, unregistered_instances):
  """Prompts the user for an instance to add, then adds that instance
  to an ELB."""
  _pretty_print_elb_zones(elb, elb_zones)
  _pretty_print_elb_instances(elb, unregistered_instances, False)

  unreg_instances = [(inst.name, inst) for inst in unregistered_instances]
  instance_to_add = common.prompt_choice("Add", unreg_instances)
  if common.prompt_confirmation("Are you sure you want to add {}".format(
    instance_to_add.name)):
    elb.register_instances([instance_to_add.id])
    print("Instance added to ELB.")
  else:
    print("Instance was NOT added to ELB.")
Exemplo n.º 2
0
def _remove_instance(elb, registered_instances):
  """Prompts the user for an instance to remove from the ELB, then removes
  it. Asks for a confirmation before actually removing it."""
  _pretty_print_elb_instances(elb, registered_instances, True)

  reg_instances = [(inst.name, inst) for inst in registered_instances]
  if len(reg_instances) == 0:
    print("Cannot remove an instance since none are registered to this ELB.")
    return

  instance_to_remove = common.prompt_choice("Remove", reg_instances)
  if common.prompt_confirmation("Are you sure you want to remove {}".format(
    instance_to_remove.name)):
    elb.deregister_instances([instance_to_remove.id])
    print("Instance removed from ELB.")
  else:
    print("Instance was NOT removed from ELB.")