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
Properly track VBD and VDI connections in xenapi fake

The fake xenapi module correctly destroys VBDs when destroying a VM
but it won't destroy VBDs when destroying a VDI. If an exception
occurs during a spawn when running test_xenapi, then another exception
can occur which obscures the original (and likely more important)
exception. This can make troubleshooting test suite failures more
difficult.

Change-Id: I19aad7f39b0707893a04784faef90815f7b0effb
Fallback to fakelibvirt in test_libvirt.py test suite

If the native 'libvirt' module is not available on the host,
currently test_libvirt.py stubs it out to ''. While this
has sort-of worked for some test cases, others have had to
be configured to skip. As the complexity of the libvirt driver
increases, ever more tests will need to be skipped.

There is, however, the fakelibvirt.py module which provides
a dummy impl of the libvirt APIs for use in test_virt_drivers.py
With a few enhancements this fake impl is good enough to use
with test_libvirt.py too.

The constructor of libvirtError is changed to accept the
'msg' as first arg to match the regular libvirt module.
A few missing constants are added. The migrateToURI
method is stubbed out

All the previously skipped tests can now be enabled as
normal.

Change-Id: I15efbef8c676cc0e263a9c9bdd7b14dfb3771105
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Set the default CPU mode to 'host-model' for Libvirt KVM/QEMU guests

Historically Nova has not set any CPU model for guests started with
the libvirt driver. This means they are all using the per-hyervisor
default settings for CPU model. With KVM/QEMU guests the model was
traditionally a very conserative choice which exposed minimal features.
This is significantly limits the performance of applications. Further
the model has changed over time, so the exact default model is
unpredictable. Switching Nova to use the host CPU model by default
should improve the out of the box performance & give a known
setup.

This does not impact migration compatibility, since the migration
code is already doing comparison checks against the source and
destination host CPU model, regardless of the actual model used
in the guest. In the future the migration code should be tweaked
so that it actually compares the current guest CPU model, against
the target host CPU model, which would potentially broaden the
migration compatibility pool.

With this patch there is a new libvirt_cpu_mode="none" which
can be used to explicitly prevent any CPU model setting in the
instance XML. The default value None, will now default to
"none" for LXC/UML/etc, and "host-model" for QEMU/KVM

Fixes: bug #1003373
Implements: blueprint libvirt-xml-cpu-model
Change-Id: I5b96e4532b6a960e1608dd6e19ae9d194379fb6a
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This patch stops metadata from being deleted when an instance is deleted.

This patch makes it so that instance metadata, system metadata, and block
device mappings are no longer set to deleted when an instance is deleted.
It doesn't make sense to delete them just because the instance they describe
has been deleted.

This patch DOES NOT MIGRATE currently deleted metadata or block
device mappings for currently deleted instances, that means that usage
notifications for deleted instances that were deleted before this patch will
show image_meta as empty.

Fixes bug 1021830

Change-Id: I33ee402b859834e09535c7925957bee0a1d91207
Fix rpc import path in nova-novncproxy

 * Fixes bug 1021836

Change-Id: Ia50224d653e172311ec9ef86ea2809ad1dafff3d
Merge "Fix rpc import path in nova-novncproxy"
Implements updating complete bw usage data

the DB query is not filtering by the mac address.
Hence, only one of them was being updated and
with mismatched bw usage info.

fixes bug 1021961

Change-Id: I792493a6e0817d62bbf6955df9cd5bc0e4af9dbb
Switch to common notifiers.

- Added notifier files to openstack-common.conf, merged from common.
- Import notifiers from common rather than nova.
- Removed nova-specific notifier code.
- Update some driver paths to refer to the new location within nova.

Should be a no-op, as the common notification code is freshly copied from Nova.

Change-Id: Icdf892bc3826b683fc74f22ead00939beda2859f
fix metadata file injection with xen

The metadata parameter was misordered in commit 1463839f

Fixes Bug: 1022036
Change-Id: Ica0e2f51b6852c8572bdc3c995cc8c2588b9a25c
Update common setup code to latest.

This gets us up to date with common/setup.py and replaces custom nova
autodoc generation with the port of that code found in common.

Change-Id: I2a1c5d2c0fdcf40dbea50cc123b537adb068cdc2
Removed a bunch of cruft files.

Ohai. We dont't uses any of theses anymores. Let's just make buh-bye.

Change-Id: Ib81c92ab9196552150d81d158befb0747966965d
Make reboot work for halted xenapi instances

Fixes bug 1022199

This also will catch exceptions and make sure to reset the task_state,
while still generating an instance fault.

Change-Id: I122a1422b8e5731bc484414736ab44e60d4c9830
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 KeyError 'key_name' when KeyPairExists raised.

Updates the Nova compute API to pass a key_name arg to the
KeyPairExists constructor. This fixes an issue where a KeyError
exception would get logged to Nova's api.log file if a KeyPairExists
exception was thrown.

Also removes the un-needed exception explanation argument from the
KeyPairExists constructor.

Fixes LP Bug #1022611

Change-Id: I83ecf3d392fef97649b298d1b732e1ff51145ae4
Fix 'instance %s: snapshotting' log message.

Update the Nova compute manage to remove the '%s:' string from the
log message. Nova already logs teh instance UUID for this log message
because we pass instance_uuid=instance_uuid to the logger so this
extra string isn't required.

Change-Id: I3fa276347d246e440917ac12d4fc5f88d90d7468
Boot from volume for Xen

Implements bp xenapi-boot-from-volume

Ensure boot from volume works for XenAPI (tested using XenServer).
1. Add strip_prefix to block_device to make the command mountpoint
agnostic.
2. Pass block device and delete on terminate information to driver
layer.
3. Add ability to recognize and boot from the specified nova volume.

Change-Id: If117087086eab809217d2b173f921bf9319a52c7