api/node.go
func updateNodeHandler(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var params provision.UpdateNodeOptions
	err = ParseInput(r, &params)
	if err != nil {
		return err
	}
	if params.Disable && params.Enable {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "A node can't be enabled and disabled simultaneously.",
		}
	}
	if params.Address == "" {
		return &tsuruErrors.HTTP{Code: http.StatusBadRequest, Message: "address is required"}
	}
	prov, node, err := node.FindNode(params.Address)
	if err != nil {
		if err == provision.ErrNodeNotFound {
			return &tsuruErrors.HTTP{
				Code:    http.StatusNotFound,
				Message: err.Error(),
			}
		}
		return err
	}
	nodeProv := prov.(provision.NodeProvisioner)
	oldPool := node.Pool()
	allowedOldPool := permission.Check(t, permission.PermNodeUpdate,
		permission.Context(permTypes.CtxPool, oldPool),
	)
	if !allowedOldPool {
		return permission.ErrUnauthorized
	}
	var ok bool
	params.Pool, ok = params.Metadata[provision.PoolMetadataName]
	if ok {
		delete(params.Metadata, provision.PoolMetadataName)
		allowedNewPool := permission.Check(t, permission.PermNodeUpdate,
			permission.Context(permTypes.CtxPool, params.Pool),
		)
		if !allowedNewPool {
			return permission.ErrUnauthorized
		}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeNode, Value: node.Address()},
		Kind:       permission.PermNodeUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed: event.Allowed(permission.PermPoolReadEvents,
			permission.Context(permTypes.CtxPool, oldPool),
			permission.Context(permTypes.CtxPool, params.Pool),
		),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	return nodeProv.UpdateNode(params)
}
func updateNodeHandler(w http.ResponseWriter, r *http.Request, t auth.Token) (err error) {
	var params provision.UpdateNodeOptions
	err = ParseInput(r, &params)
	if err != nil {
		return err
	}
	if params.Disable && params.Enable {
		return &tsuruErrors.HTTP{
			Code:    http.StatusBadRequest,
			Message: "A node can't be enabled and disabled simultaneously.",
		}
	}
	if params.Address == "" {
		return &tsuruErrors.HTTP{Code: http.StatusBadRequest, Message: "address is required"}
	}
	prov, node, err := node.FindNode(params.Address)
	if err != nil {
		if err == provision.ErrNodeNotFound {
			return &tsuruErrors.HTTP{
				Code:    http.StatusNotFound,
				Message: err.Error(),
			}
		}
		return err
	}
	nodeProv := prov.(provision.NodeProvisioner)
	oldPool := node.Pool()
	allowedOldPool := permission.Check(t, permission.PermNodeUpdate,
		permission.Context(permTypes.CtxPool, oldPool),
	)
	if !allowedOldPool {
		return permission.ErrUnauthorized
	}
	var ok bool
	params.Pool, ok = params.Metadata[provision.PoolMetadataName]
	if ok {
		delete(params.Metadata, provision.PoolMetadataName)
		allowedNewPool := permission.Check(t, permission.PermNodeUpdate,
			permission.Context(permTypes.CtxPool, params.Pool),
		)
		if !allowedNewPool {
			return permission.ErrUnauthorized
		}
	}
	evt, err := event.New(&event.Opts{
		Target:     event.Target{Type: event.TargetTypeNode, Value: node.Address()},
		Kind:       permission.PermNodeUpdate,
		Owner:      t,
		CustomData: event.FormToCustomData(InputFields(r)),
		Allowed: event.Allowed(permission.PermPoolReadEvents,
			permission.Context(permTypes.CtxPool, oldPool),
			permission.Context(permTypes.CtxPool, params.Pool),
		),
	})
	if err != nil {
		return err
	}
	defer func() { evt.Done(err) }()
	return nodeProv.UpdateNode(params)
}
// title: update nodes
// path: /{provisioner}/node
// method: PUT
// consume: application/x-www-form-urlencoded
// responses:
//   200: Ok
//   400: Invalid data
//   401: Unauthorized
//   404: Not found