Example #1
0
func (handler *ScopesHandlersImpl) ScopesBindContainer(params scopes.BindContainerParams) middleware.Responder {
	defer trace.End(trace.Begin(fmt.Sprintf("handle(%s)", params.Handle)))

	h := exec.GetHandle(params.Handle)
	if h == nil {
		return scopes.NewBindContainerNotFound().WithPayload(&models.Error{Message: "container not found"})
	}

	var endpoints []*network.Endpoint
	var err error
	if endpoints, err = handler.netCtx.BindContainer(h); err != nil {
		switch err := err.(type) {
		case network.ResourceNotFoundError:
			return scopes.NewBindContainerNotFound().WithPayload(errorPayload(err))

		default:
			return scopes.NewBindContainerInternalServerError().WithPayload(errorPayload(err))
		}
	}

	res := &models.BindContainerResponse{
		Handle:    h.String(),
		Endpoints: make([]*models.EndpointConfig, len(endpoints)),
	}
	for i, e := range endpoints {
		res.Endpoints[i] = toEndpointConfig(e)
	}

	return scopes.NewBindContainerOK().WithPayload(res)
}
Example #2
0
func (handler *ScopesHandlersImpl) ScopesBindContainer(params scopes.BindContainerParams) middleware.Responder {
	defer trace.End(trace.Begin("ScopesBindContainer"))

	h := exec.GetHandle(params.Handle)
	if h == nil {
		return scopes.NewBindContainerNotFound().WithPayload(&models.Error{Message: "container not found"})
	}

	if _, err := handler.netCtx.BindContainer(h); err != nil {
		return scopes.NewBindContainerInternalServerError().WithPayload(errorPayload(err))
	}

	return scopes.NewBindContainerOK().WithPayload(h.String())
}