class Chef::Knife::BmcsServerDelete

Server Delete Command: Delete a BMCS instance.

Public Instance Methods

confirm_deletion() click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 90
def confirm_deletion
  return if confirm('Delete server? (y/n)')
  error_and_exit 'Server delete canceled.'
end
end_progress_indicator() click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 100
def end_progress_indicator
  print ui.color("done\n", :magenta)
end
get_wait_options(wait_for) click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 82
def get_wait_options(wait_for)
  opts = {
    max_interval_seconds: MAX_INTERVAL_SECONDS
  }
  opts[:max_wait_seconds] = wait_for if wait_for > 0
  opts
end
run() click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 32
def run
  $stdout.sync = true
  validate_required_params(%i[instance_id], config)
  wait_for = validate_wait

  confirm_deletion

  check_can_access_instance(config[:instance_id])

  terminate_instance(config[:instance_id])

  wait_for_instance_terminated(config[:instance_id], wait_for) if wait_for
end
show_progress() click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 95
def show_progress
  print ui.color('.', :magenta)
  $stdout.flush
end
terminate_instance(instance_id) click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 46
def terminate_instance(instance_id)
  compute_client.terminate_instance(instance_id)

  ui.msg "Initiated delete of instance #{instance_id}"
end
validate_wait() click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 73
def validate_wait
  wait_for = nil
  if config[:wait]
    wait_for = Integer(config[:wait])
    error_and_exit 'Wait value must be 0 or greater' if wait_for < 0
  end
  wait_for
end
wait_for_instance_terminated(instance_id, wait_for) click to toggle source
# File lib/chef/knife/bmcs_server_delete.rb, line 52
def wait_for_instance_terminated(instance_id, wait_for)
  print ui.color('Waiting for instance to terminate...', :magenta)
  begin
    begin
      compute_client.get_instance(instance_id).wait_until(:lifecycle_state,
                                                          OracleBMC::Core::Models::Instance::LIFECYCLE_STATE_TERMINATED,
                                                          get_wait_options(wait_for)) do
        show_progress
      end
    ensure
      end_progress_indicator
    end
  rescue OracleBMC::Waiter::Errors::MaximumWaitTimeExceededError
    error_and_exit 'Timeout exceeded while waiting for instance to terminate'
  rescue OracleBMC::Errors::ServiceError => service_error
    raise unless service_error.serviceCode == 'NotAuthorizedOrNotFound'
    # we'll soak this exception since the terminate may have completed before we started waiting for it.
    ui.warn 'Instance not authorized or not found'
  end
end