Add basic statistics support

This introduces basic statistics support in NIPAP for prefixes and adds
preparatory changes for pools and VRFs.  Do note how there is no time dimension
to this just yet, there's only statistics for number of used addresses and so
forth, adding a time dimension would come as a second step.

New columns in db for VRFs (ip_net_vrf), pools (ip_net_pool) and
prefixes (ip_net_plan) containing statistics. Most statistics values are
stored as numeric(40) which allows for very large numbers (like 2^128
for IPv6).  The values for VRFs are;
 - total number of IPv4 prefixes in VRF
 - total number of IPv6 prefixes in VRF
 - total number of IPv4 addresses in VRF
 - total number of IPv6 addresses in VRF
 - number of used IPv4 addresses in VRF
 - number of used IPv6 addresses in VRF
 - number of free IPv4 addresses in VRF
 - number of free IPv6 addresses in VRF

For pools:
 - total number of member IPv4 prefixes in pool
 - total number of member IPv6 prefixes in pool
 - number of IPv4 prefixes assigned from pool
 - number of IPv6 prefixes assigned from pool
 - total number of IPv4 addresses in pool
 - total number of IPv6 addresses in pool
 - number of used IPv4 addresses in pool
 - number of used IPv6 addresses in pool
 - number of free IPv4 addresses in pool
 - number of free IPv6 addresses in pool

For prefixes we have;
 - total number of addresses
 - number of used addresses
 - number of free addresses

All statistics for prefixes are for direct children, ie we will not show
if there are free addresses further down a hierarchy of prefixes.

Database triggers automatically update statistics for prefixes on
INSERT/UPDATE/DELETE operations so that statistics are always kept up to date.

There's quite a few different triggers associated with our tables, in
particular ip_net_plan, to perform various checks and calculations of
things like indent, inherited tags, number of children and now
statistics. It's a bit of a mess. The idea behind having lots of
different triggers and trigger functions was that they would each be
kept simple and thus easily maintanable. The issue is that there are
dependencies between the functions, so now we have to assure they are
being run in the right order. For this reason I'm now trying a different
approach of joining more features into fewer trigger functions but still
keeping each feature as a separate section within the function,
hopefully making it still rather easy to maintain.

This change moves indent and children calculation from its own trigger
function into a shared function where the new statistics are handled as well.

Naturally, there's a new comprehensive test suite for statistics.

nipapd will serve these new values and the CLI can display them.

NOTE: Most statistics values are sent over XML-RPC as strings as the XML-RPC
standard doesn't specify a datatype for anything larger than an integer.
Internally in the backend module, we still deal with it as a long - the
actual conversion is done in xmlrpc.py so if we ever add a second API
(JSON-RPC anyone?) then we could still pass it as a number, if that API
would support it. Pynipap will convert it back into a long on the client side
so clients using pynipap will not have to deal with this peculiarity.

Part of #248.
Trigger restructure for tag handling and indent calc

The before trigger for tags has been merged with our large before
trigger.

It now also handles DELETEs which is a prerequisite to correctly handle
inherited tags. The trigger is also set for a few more actions, like
when tags are changed. This means that we might do more computations
more often.. not sure of performance impact.

Now that we have a larger trigger function shared by lot of different
stuff, we need to think about when the function is triggered and not act
on all updates. This adds a check for indent calc so that the prefix
actually has been update before we run calc indent.

Part of #248.
Add basic pool statistics

Triggers in the database will update total number of addreses in a pool.

CLI includes statistics on total number of addresses in a pool as well
as number of used and free addresses.

There's a new test suite to check that used / free addresses are updated
when adding new child prefixes, which is essentially when the parent
prefix is part of a pool as well as updating the total, free and number
of child prefixes when adding and removing members to a pool. We also
mangle pool results in xmlrpc.py since we don't care about return values
there - all statistics testing is done in nipaptest.py

Includes the fugly hack to send large numbers as strings due to lack of
support for large numbers in the XML-RPC standard. Pynipap converts back
to numbers on the client side.

Part of #248.
Add columns for total / free prefixes in pools

We already have counters for keeping track of how many used/free/total
addresses we have in a pool but in the majority of cases pools are used
to assign larger prefixes and not individual addresses so it is more
interesting to know the number of free prefixes (based on default
assignment size). These new columns are for precisely that purpose.

The total number of prefixes (used + free) is an interesting value as it
will change depending on the size of the prefixes in the pool.

Part of #248.
Add option for disabling pynipap object cache

Pynipap caches objects per default to lower the amount of requests for
objects that occur a lot, typically VRFs. This can cause problems
sometimes, especially as there is no expiration of old entries in the
cache.

To temporarily solve some problems, this implements the option to
disable the cache. The cache is still kept up to date for deletes,
updates and so forth, the only difference is that we don't use it when
getting objects. This potentially creates some flexibility in using the
cache selectively (ie, disabling temporarily)
Add VRF statistics

This adds logic to our mega trigger function to calculate and store
prefix statistics per VRF. There's also a few tests to make sure we do
the right thing.

Part of #248.
Add VRF, pool and prefix statistics to web-UI

This displays a nice Chart.JS doughnut chart over the free vs used
addresses in a VRF, pool or prefix together with a text description of
the number of prefixes.

Adds Chart.JS.

Part of #248.
SQL schema upgrade to version 4 for statistics

This adds all columns relevant to statistics to our existing tables as
well as populate those columns with the correct values.
Since it is the first db schema change in a while this is added to a new
upgrade file with the future version 4.

Part of #248.
Add statistics test to upgrade test suite

The recently introduced upgrade test suite allows the testing of data
over the NIPAP upgrade process from the stable version to the latest git
version. Since we have introduced SQL schema changes with the addition
of statistics, we use this test suite to make sure that data entered
before the upgrade comes out correct after the upgrade. That includes
having the new statistics columns / attributes as well as having the
correct values! :)

Part of #248.
Add log messages to Debian upgrade process

Should help keep users calm in case the upgrade takes a while.
Align statistics output in CLI

Output for viewing a VRF was different that pool and prefix so it has
now be modified to align all output of statistics data and make it more
compact. Further the actual "columns" are now aligned on the terminal
screen.

Part of #248.
Use exponent format for IPv6 statistics

Makes IPv6 statistics output a bit more compact, showing just how many
addresses are available becomes a next to incomprehensible long number.

Part of #248.
Rename child_prefixes_vX to used_addresses_vX

To conform with the naming of other columns / attributes for prefixes
and VRF.

Part of #248.
Add test and fix corner case of stats calc

Statistics were incorrectly calculated when a prefix was enlarged /
shrunk by more than one indentation level, e.g. enlarging a prefix so
that it becomes larger and covers its old parent prefix.

This adds a test for that as well as actually fixing the code.

Also clarify some code by using explicit conditions rather than relying
on not matching stuff with the WHERE-clause of an UPDATE.

Part of #248.
Merge pull request #544 from plajjan/248-add-statistics

Add statistics to prefixes, pools and VRFs