Exemple #1
0
func (i *InteractionHandlersImpl) ContainerGetStderrHandler(params interaction.ContainerGetStderrParams) middleware.Responder {
	defer trace.End(trace.Begin(params.ID))

	var ctxDeadline time.Time
	var timeout time.Duration

	// Calculate the timeout for the attach if the caller specified a deadline
	if params.Deadline != nil {
		ctxDeadline = time.Time(*params.Deadline)
		timeout = ctxDeadline.Sub(time.Now())
		log.Printf("Attempting to get ssh session for container %s stderr with deadline %s", params.ID, ctxDeadline.Format(time.UnixDate))
		if timeout < 0 {
			e := &models.Error{Message: fmt.Sprintf("Deadline for stdin already passed for container %s", params.ID)}
			return interaction.NewContainerGetStdoutInternalServerError().WithPayload(e)
		}
	} else {
		log.Printf("Attempting to get ssh session for container %s stderr", params.ID)
		timeout = interactionTimeout
	}

	contConn, err := i.attachServer.Get(context.Background(), params.ID, timeout)
	if err != nil {

		err = fmt.Errorf("No stderr found for %s: %s", params.ID, err.Error())
		log.Errorf("%s", err.Error())

		return interaction.NewContainerGetStderrNotFound()
	}

	detachableErr := NewFlushingReader(contConn.Stderr())

	return NewContainerOutputHandler("stderr").WithPayload(detachableErr, params.ID)
}
Exemple #2
0
// ContainerGetStdoutHandler returns the stdout
func (i *InteractionHandlersImpl) ContainerGetStdoutHandler(params interaction.ContainerGetStdoutParams) middleware.Responder {
	defer trace.End(trace.Begin(params.ID))

	var ctxDeadline time.Time
	var timeout time.Duration

	// Calculate the timeout for the attach if the caller specified a deadline
	if params.Deadline != nil {
		ctxDeadline = time.Time(*params.Deadline)
		timeout = ctxDeadline.Sub(time.Now())
		log.Debugf("Attempting to get ssh session for container %s stdout with deadline %s", params.ID, ctxDeadline.Format(time.UnixDate))
		if timeout < 0 {
			e := &models.Error{Message: fmt.Sprintf("Deadline for stdout already passed for container %s", params.ID)}
			return interaction.NewContainerGetStdoutInternalServerError().WithPayload(e)
		}
	} else {
		log.Debugf("Attempting to get ssh session for container %s stdout", params.ID)
		timeout = interactionTimeout
	}

	session, err := i.attachServer.Get(context.Background(), params.ID, timeout)
	if err != nil {
		log.Errorf("%s", err.Error())

		// FIXME (caglar10ur): Do not return an error here - https://github.com/vmware/vic/issues/2594
		/*
			e := &models.Error{
				Message: fmt.Sprintf("No stdout connection found (id: %s): %s", params.ID, err.Error()),
			}
			return interaction.NewContainerGetStdoutNotFound().WithPayload(e)
		*/
		return interaction.NewContainerGetStdoutNotFound()
	}

	return NewContainerOutputHandler("stdout").WithPayload(
		NewFlushingReader(
			session.Stdout(),
		),
		params.ID,
	)
}