Add "friendly_name" to all Razor::Data classes

This adds a method to all Razor::Data classes to return a friendly name for
the type.  This can be used to talk about the object in, for example, error
messages elsewhere.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Improve reporting of validation errors

This extends the validation framework to pass the context of the current
attribute through the system, and report using it.  This means that we will
see messages like "broker.name must refer to an ..." rather than "name must
refer to an ..." emitted.

That should help much more effectively understand where the problem was
located, rather than guessing at one of the many identically named attributes
it could possibly match.

https://tickets.puppetlabs.com/browse/RAZOR-191

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Implement a 'size' validation check for attributes

This implement a check to validate the size of an attribute; it only makes
sense for string, object/map, and array types.  It uses a range to verify the
minimum and maximum size of the object in characters, or contained entities.

This, in turn, supports verification that inappropriate length entities are
not passed in our data.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Apply a size check to tag names, rejecting zero-length names

This applies the size validation check to tag names, to ensure that they are a
legal length matching our definition in the database.  That is, between one
and infinity characters long.

https://tickets.puppetlabs.com/browse/RAZOR-137
Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Apply size checks to all other commands, where relevant

This commit whips through all the other commands and applies a size check to
string arguments -- matching our database constraints.  This kind of shows how
incoherent those constraints are, varying wildly between infinite and
constrained, but they are our current constraints.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Add user help to all commands

This adds user-facing help to all commands, based on the existing
documentation.  This will be automatically exposed to the client through the
new command metadata API, and will permit this information to be shared with
the client automatically -- as well as future updates to help about the
commands as we improve the software.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Detect and report out-of-sync migrations via the API

When the Razor code and database migrations are out of sync, significant
problems can occur.  This adds code to detect when this situation has shown
up, report it, and refuse service to all callers.

For the client this will result in an error message to the user, including
instructions on how to fix the problem.

For MK images, etc, it will result in an error that they will observe and
retry in the near future; this is the best we can do, since we can't be sure
that the changes have not altered the behaviour they should undertake.

https://tickets.puppetlabs.com/browse/RAZOR-158
Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Add `locales` data and template to packages

The locales directory will be shipped, with both the PO file template, and any
PO files that we have included that support translations.  This supports our
translation efforts.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Fixing `create-repo` documentation
Allow `conform!` in commands

In order to change the client=>server API, there needs to be some backwards-compatibility in effect. This `conform!` capability will allow a command to decide which data mutations it can perform on its data before running its validation.
Fixing invalid JSON returned on some errors

Invalid JSON was being returned whenever certain errors (TypeError, ArgumentError, etc.) were raised.
Add `element` and `references` to array validation

In order to facilitate some shorthand syntax (`["abc"] => [ {"name": "abc"} ]`), arrays will need to hold datatypes besides just objects and also assure relational integrity. The type `element` (aliased as `elements`) will be used to denote a basic datatype in an array. `references` will work like it does for hash. This includes a change to hash attribute default behavior, where now if no reference name is provided, it defaults to 'name', rather than the property's name. This was done to establish a clearer convention.

Part of this change is also moving incorrectly located tests for array attributes, which were previously in the array schema spec file.
Allow shorthand in `create-policy` command

Create Policy is a representative example of the shorthand involved. This converts create-policy attributes `repo`, `task`, `broker`, and `tags` to no longer need an object/hash with just the "name" property defined. In order to preserve backward-compatibility, this command now overrides `conform!`. The method upgrades commands written in the old syntax to the new syntax.

There was a previous regression where create-policy would not create tags that specified a `rule` array. This has been added back.
Shorthand references in other commands

`create-repo` and `move-policy` need the same updates for references from just a string rather than the string in an object's `name` property.

This was a good opportunity to fix up and refine the spec tests for both commands.

Fixes https://tickets.puppetlabs.com/browse/RAZOR-192
Allow marking newly discovered nodes as 'installed'

This adds a configuration option, `protect_new_nodes`, which if set to a true
value causes all newly discovered nodes to be marked installed at the exact
same moment.

This will result in the default behaviour of Razor changing from "install
based on policy" to "install based on policy once a node reinstall is
explicitly requested", a much safer default for users.

By default Razor will continue to assume that it controls everything on your
network, and treat any newly discovered node as a candidate for immediate
installation according to policy.

https://tickets.puppetlabs.com/browse/RAZOR-152

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Automatically type-check array and object entities in validation

When an `object` or `array` helper is used for an attribute, we already know
what type the entity is -- so we can automatically set that check in the
attribute code.

This allows things like `size` checks to be applied more naturally to
`object` or `array` attributes, too, without having to manually add the
`type` check.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Automatically maintain `installed_at` field of nodes

Previously every location in the code that set the `installed` field on a node
also hand-maintained the `installed_at` field.  This replaces that with an
extension to the setter that automatically updates the value, codifying this
behaviour for all external callers.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Add `register-node` command to pre-register nodes with Razor

In order to make brownfield deployments of Razor easier we allow users to
register nodes explicitly.  This command allows you to perform the same
registration that would happen when a new node checked in, ahead of time.

In order for this to be effective the hw_info must contain enough information
that the node can successfully be matched during the iPXE boot phase.

If the node matches an existing node, in keeping with the overall policy
of commands declaring desired state, the node installed field will be
updated to match the value in this command.

The final state is that a node with the supplied hardware information,
and the desired installed state, will be present in the database,
regardless of it existing before hand or not.

https://tickets.puppetlabs.com/browse/RAZOR-151

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Fixing validation for `create-policy`

The command validation for `create-policy` was not allowing the properties `enabled` and `max_count` to be included, even though the documentation includes them.

Fixes https://tickets.puppetlabs.com/browse/RAZOR-203
Delete unpacked iso on repo deletion

When issuing the `delete-repo` command, the unpacked repo was being left on the filesystem. This change cleans up this folder, if it exists.

Fixes https://tickets.puppetlabs.com/browse/RAZOR-202