Hoist base Slice class into ProjectRazor::Slice

All the common slice functionality was held in the `ProjectRazor::Slice::Base`
class, which was quite confusing when you consider that every implementation
is-a slice, and they are used in compliance with the Liskov substitution
principal by the rest of the system.

This rewrites the code to implement all the functionality in a base class,
with subclasses nested below it.  There is no change to the capability of the
system, just less surprising code structure.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Pass arguments rather than using global member variables

The main razor script used member variables at global scope where a simple
function argument would do.  This eliminates one of those variables.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
More arguments rather than global variables

This eliminates another global (member of Object) variable from Razor.
There should be no functional changes, just cleaner code.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Perform file to constant translation the Ruby way

The slice definition used some simple meta-programming to transform a slice
name into a Ruby constant, associated with the appropriate class, as well as
to identify the set of available slices by mapping through files on disk.

It didn't quite match the Ruby model for file to constant translation, though,
which made for some surprising class names - it assumed that `.capitalize` was
sufficient, while really you need to split on `_` and rejoin the components
after mapping leading caps across them.

There should be no functional changes from this, just cleaner code.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Simplify condition handling around missing slices

Now, rather than doing a whole lot of pre-testing of slices to determine if
they are valid we just go right ahead and try and use them.  When they are
found missing we report that nicely, and otherwise carry on.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Remove "slices loaded" and associated global state

The code around "loaded" slices was a bit of a mess: it actually looked to see
what was available on disk, not just loaded.  It also used global state to
pass data between methods that were separated in time, but not
actually decoupled.

With the rework of condition handling for missing slices we can eliminate most
of that, then inline the "discover available slices" facility into the method
that prints available slices.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Move CLI handling into a class, not a script

This moves the command line handling and dispatch out of the `bin/razor`
script and into a class.  There is no current functional change, but rather a
cleaner separation of objects.

This opens the door to better testing of the command line dispatch related
code, to ensure that it behaves correctly, than the script permitted.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Refactor the CLI handling to be a little cleaner

This is part of a series of refactorings that should have no externally
visible effect, but which make the CLI handling substantially
cleaner internally.

This replaces an init method with object initialization.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Include errors in logs, rather than printing them

In a handful of places Razor would print an exception object to the console
rather than including it in the error log string.  This led to failures being
lost from the logs, even though they went to the console.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Merge pull request #233 from daniel-pittman/bug/master/actually-include-ssh-error-in-logs

Include errors in logs, rather than printing them
Implement Puppet Labs best-practice version handling

Instead of a configuration, or source, file containing a hard-coded version
Puppet Labs uses a pair of methods to determine the version of software:

In the case of pre-release software, software installed from git, or nightly
builds we strongly prefer to use the results of `git describe` to identify a
robust and reproducible version number.

In the case of release software we burn the release version string into the
final product, typically by modifying a `lib/${project}/version.rb` file that
defines a `Project::VERSION` constant that third parties can use.

As with our standards, `require "project/version"` doesn't cause the entire
suite to be loaded, so you can use that to make version-specific decisions
about interacting with the rest of the software suite.

Many of those capabilities are not presently used, or usable, with Project
Razor, but following standards ensures we can do that as we export more usable
code-level APIs.

It does improve reporting of the version that happens for current git
installations of the software.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>
Merge pull request #232 from daniel-pittman/maint/master/cleaner-code-for-a-cleaner-life

Cleaner code for a cleaner life!
Initial PostgreSQL based persistence implementation
Adds interface describing the API and an in-memory persist plug-in

The commit also renames the postgresplugin and mongoplugin to
postgres_plugin and mongo_plugin respectively. Seems more consistent
given the camel casing used in their names
- Removed the `pt.add_p_item` from get_line_number
- Added policy_table_clean for running a fetch_all_objects on policy_table
-- This will automatically clean stale versions and is low impact as this collection only is supposed to store one copy.
-- This will fix existing installs immediately with stale entries.
Merge pull request #236 from lynxbat/master

Fix for issue #235 - removes incorrect policy_table insert and implements cleanup method to repair existing installs.
Added two new parameters to the Razor configuration (mk_gem_mirror_uri and mk_gemlist_uri) to support installation of gems within Microkernel instances from an external gem mirror.  Also added code to supplement the existing Razor configuration (as is taken from an existing Razor configuration file) with default values for any parameters that are not defined in that Razor configuration file.  This will ensure that these new parameters are available on any system, even systems with an existing Razor configuration file that does not include them.  This will also have the effect of providing a potential fix for the issues raised in the discussion of (Issue #183)[https://github.com/puppetlabs/Razor/pull/183] around how best to deal with a "partial" configuration file.
Merge pull request #240 from tjmcs/tb/add_external_gem_mirror_for_mk

Adds support for use of a gem mirror (internal or external) by the Microkernel
Added OracleLinux 6 support for #241.
Set HOME to current user homedir to help out Net::SSH

If HOME is not set in the environment, the Ruby Net::SSH gem ends up causing
problems by setting it to `.` - which leads to other parts of Ruby failing in
horrible ways.

Since `ENV['HOME']` isn't actually *required* to be set, and various places
like Puppet starting a service, or other launchers, and Ruby does explode in
exciting ways if it isn't ... we set it to something useful.

By "useful" I mean: if we are on Win32, and have their HOMEPATH and possibly
HOMEDRIVE set, use those to point to the home directory.  That is going to
point to a fairly sensible location by default.

On Unix, where that isn't set, we grab the pwent for the current process EUID,
and set the HOME value to the home directory of that user.  That is the
closest to "right" I can identify, since it pretty directly mirrors what
login(1) would do in the same circumstance.

This closes #239, by ensuring that we have a more sensible (and absolute) path
available at all times.

Signed-off-by: Daniel Pittman <daniel@rimspace.net>