예제 #1
0
func (handler *ScopesHandlersImpl) ScopesUnbindContainer(params scopes.UnbindContainerParams) middleware.Responder {
	defer trace.End(trace.Begin(fmt.Sprintf("handle(%s)", params.Handle)))

	h := exec.GetHandle(params.Handle)
	if h == nil {
		return scopes.NewUnbindContainerNotFound()
	}

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

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

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

	return scopes.NewUnbindContainerOK().WithPayload(res)
}
예제 #2
0
func (handler *ScopesHandlersImpl) ScopesUnbindContainer(params scopes.UnbindContainerParams) middleware.Responder {
	defer trace.End(trace.Begin("ScopesUnbindContainer"))

	h := exec.GetHandle(params.Handle)
	if h == nil {
		return scopes.NewUnbindContainerNotFound()
	}

	if err := handler.netCtx.UnbindContainer(h); err != nil {
		return scopes.NewUnbindContainerInternalServerError().WithPayload(errorPayload(err))
	}

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