opencrowbar/core — pull request #74 by VictorLowther (2014-03-10 11:59:39+00:00)
Title: Node create api rework

Do not merge -- for review and comment for now.
Warning -- will require a Sledgehammer rebuild.

This exposes the internal machinery that Crowbar uses create nodes and
bind their initial noderoles, and fixes a deadlock exposed by the API rework.
Instead of POSTing to /api/v2/nodes and being handed back a fully fledged node, we now need a few different API calls:

* POST to /api/v2/nodes to create a basic Node object. This will not
have any roles bound to it nor will it have any addresses from the
admin network assigned to it. The node will neither be alove nor available.
* (Optional) PUT any node-specific hints that may be needed for the
bootstrap process, including node MAC addresses or your suggested IP
address.
* POST to /api/v2/node_roles to bind default roles to the node. Binding
crowbar-admin-node will result in the node having all the roles needed
for it to act as an admin node, and crowbar-managed-node will bind all
the roles needed for the Sledgehammer discovery process to work.
* (Optional) PUT any node-specific attrib updates to the node.
* PUT to /api/v2/nodes//commit to move all the node's
noderoles from PROPOSED to TODO, and mark the node as available (but
still not alive)

The exposed deadlock was resolved by:

* Rework the Jig exception management stuff to consolidate it even
more. Everything that needs to happen with a noderole to make a Jig
do work now happens inside of delayed_jobs, and any exception will
throw the noderole into ERROR. This also zaps the added boilerplate
that was added in the last jig rework. The bulk of the change deals
with the indentation changes for this work.
* Reworked all the locations that were calling Run.run! to ensure that
Run.run! is never called inside of a transaction. Going forward this
invariant will be enforced by the Run.locked_transaction class method,
which will throw an error if it is called inside another transaction.
* Changed the on_node_* hooks to be called via after_commit. This
makes it easier for hooks that need to call Run.enqueue to schedule
will not inadvertently be inside a transaction.