Make metadata content match the requested version of the metadata API.

Currently the same metadata is returned no matter what metadata
version is requested. Metadata is currently implemented to version
2009-04-04 (apart from existing TODOs) as defined here:
http://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/instancedata-data-categories.html

This change adds version checking conditionals throughout
get_ec2_metadata and only includes the metadata if the requested version
should contain it.

When there is a difference between Amazon API implementation and documentation
I've gone with replicating the implementation. So far differences include:
- undocumented hostname introduced in 1.0, deprecated in favour of
  local-hostname
- kernel-id and ramdisk-id seem have to been implemented in 2007-12-15,
  not 2008-02-01 as documented

get_ec2_metadata has also been reordered so that data is added oldest to
newest by API version. In a future change I may attempt to add
unimplemented API versions (2011-01-01, 2012-06-01).

Change-Id: Ibf6e6e3b9807f29dccd31006515df550bf9bf57b
Distinguish over-quota for volume size and number.

Fixes LP 1020634

Ensure that exceeding the allowed number of volumes is not
mis-represented in log messages and exception handling as
excessive space usage.

Change-Id: I71ec995c77bc447bfc9221084b057bd8d69a4513
Janitorial:  Catch rpc up with a change in common

Common rpc now uses jsonutils instead of json; this
patch moves that change into nova.

Change-Id: Iba45e473ae875b0973dbe6f752602b58c7980578
Properly name openstack.common.exception.

Now it's 'nova.openstack.common.exception', thanks to a more modern
update.py in common.

Change-Id: I4b3caf9014f866da3a5bbf07ab194fc9910159b0
Propagate setup.py change from common.

This pulls in the following patch:

commit 8a967b16dc2ffd60bc19bee09f45e665ddcc9a81
Author: Monty Taylor <mordred@inaugust.com>
Date:   Mon Jul 2 17:19:06 2012 -0400

    Fix up openstack-common build.

    Ironically enough, even though the code to manage this is in
    openstack-common, openstack-common wasn't using it. This patch fixes doc
    generation, as well as setuptools-git integration and versioning.

Change-Id: Ibb2041b131c67aba963e2dd81dcdfd105e1f9b33
Fix snapshots tests failing
bug 1022670

When running snapshot test, FLAGS.instances_path is defined as '',
with snapshot_directory='/snapshots' which will fail to to permissions errors.

Modified class LibvirtConnTestCase to use libvirt_snapshots_directory=''

Change-Id: I930e4f30ddffcf66c58312e92f0ae368e770e438
Expose over-quota exceptions via native API.

Fixes bug LP 1021373.

Previously an over-quota condition would be exposed via the EC2 API,
but hidden in the corresponding call via the native API (in the sense
of the exception detail being replaced with a generic 500 Server Error
response).

We now report any NovaException declared to be safe. In this patch,
the set of safe exception types includes any subclass of QuotaError,
but in subsequent patches the net should be widened to include
exceptions that do not expose senstive information.

Change-Id: I3cc36337c7e67cf487ca49de646c437c217ae538
When deleting an instance, avoid freakout if iscsi device is gone

It's fairly easy to get into a state where an instance is not running,
the iscsi infrastructure has been torn down, and the instance cannot
be deleted because the iscsi device cannot be successfully removed.
This patch ignores the associated return value for that scenario and
marches forward in the teardown process.

Fixes bug 1022520

Change-Id: Ib28790892eebe341ac10a92250cf872605fefe9b
associate_floating_ip an ip already in use

Fixes bug 10014860 to be compliant w/ AWS EC2 spec
instead of return exception.FloatingIpAssociated,
disassociate from old fixed_ip and associate to
new fixed_ip.

Change-Id: I54ab3492092940dbb01f2787cc329a0162698568
Adds diagnostics command for the libvirt driver.

This code provides an implementation of the get_diagnostics
API for the libvirt driver. This API is invoked by the
'nova diagnostic' command.

There is no existing formal specification for what data items
to expose from the 'get_diagnostics' API, so the XenAPI driver
is used as an informal guide. The Xen implementation currently
produces the following output:

+----------------+-----------------+
|    Property    |      Value      |
+----------------+-----------------+
| cpu0           | 4.3627          |
| memory         | 1171088064.0000 |
| memory_target  | 1171088064.0000 |
| vbd_xvda_read  | 0.0             |
| vbd_xvda_write | 0.0             |
| vif_0_rx       | 3223.6870       |
| vif_0_tx       | 0.0             |
| vif_1_rx       | 104.4955        |
| vif_1_tx       | 0.0             |
+----------------+-----------------+

The new libvirt implementation will return a similar set of stats
for guest CPUs, memory, disks and network interfaces, resulting
in the following output:

+------------------+------------+
| Property         | Value      |
+------------------+------------+
| cpu0_time        | 2870000000 |
| memory           | 524288     |
| vda_errors       | -1         |
| vda_read         | 262144     |
| vda_read_req     | 112        |
| vda_write        | 5606400    |
| vda_write_req    | 376        |
| vnet0_rx         | 63343      |
| vnet0_rx_drop    | 0          |
| vnet0_rx_errors  | 0          |
| vnet0_rx_packets | 431        |
| vnet0_tx         | 4905       |
| vnet0_tx_drop    | 0          |
| vnet0_tx_errors  | 0          |
| vnet0_tx_packets | 45         |
+------------------+------------+

The implementation has only been tested with the libvirt KVM
driver.

In a future a formal specification for the required data
format should be written and all virt drivers made to comply.

Finally, the fakelibvirt driver has been updated in order to
support the methods required by the get_diagnostics method.

For those interested, below is the formula to extract the
CPU usage based on the CPU time. I've added it here for reference
since it's not used at the moment and it took quite a while
to locate it in the libvirt documentation.

  usage = 100 * (current_cpu_time - last_cpu_time) /
          (measurement_interval * (10 ** 9))

Fixes bug 986200.
Change-Id: I92da392f43d0840ed31cfd88f54570ea5830bb4a
Don't block instance delete on missing block device volume

It's easy to create an undeletable instance by specifying an invalid
volume id in the block device mapping. The instance errors, but
subsequent delete fails because the volume is missing. We already
ignore the DiskNotFound case during delete, so this adds a case for
VolumeNotFound.

Change-Id: Ibc516ee4452d088cddf10bbeb315697ce900e5c5
Refactor instance_usage_audit. Add audit tasklog.

The instance usage audit cronjob that generates periodic
compute.instance.exists notifications is not particularly scalable.
It is run on one server and takes longer as the number of instances grows.

This change moves the generation of those events to a periodic task in
the compute manager. It also adds an api extension that can be used
by administrators to check for errors generating these events.

Change-Id: I856d3d0c73c34e570112f1345d306308ef20a9ae
Clarifying which vm_utils functions are private.

This clarification should aid in future refactorings by giving a hint of
which methods are not referenced outside of the file (except for test
stubs).

Change-Id: I574b2caa25d54969a1627fa69f101b2480152b08
Refactors more snapshot code into vm_utils.

Simplifies vmops a bit while moving logic into vmutils where it better
matches how we've seperated concerns.

Change-Id: Ic6d7559903d0f809f4c90577f4a8c4a0857cae90
only mount guest image once when injecting files

Previously we could incur the costly guest mount operation twice,
if injecting files with any of net, ssh keys, password, metadata.
Instead now inject files in the same operation.

Also cleanup the internal injection functions a little
by removing the unused 'execute' parameter.

Partly mitigates the impact of bug 1013689.
Change-Id: Ib66d327e745593cf1e5897470750d609b2a58980
Adds network labels to the fixed ips in usages

Change-Id: Ib5990a7f5d7869c862ec3dd3299772e421574ae6
Merge "Refactor instance_usage_audit. Add audit tasklog."
Merge "Adds network labels to the fixed ips in usages"
Always attempt to delete entire floating IP range.

Fix bug 1021222.

This patch tweaks nova-manage to always attempt to delete all addresses
in the specified IP range, even if an error is encountered.  This is an
easy way to handle a case where a range was created, but then a subset
of that range was deleted.  Otherwise, deleting the rest of the range is
a pain.

An example of this would be:

  # nova-manage floating create --ip_range=1.1.1.0/24
  # nova-manage floating delete 1.1.1.1
  # nova-manage floating delete 1.1.1.0/24

Previously this would fail.  Now it works.

Change-Id: Ia01c04dee5383f597976c6a79d9a0d9e19985898
Merge "Clarifying which vm_utils functions are private."