Fix an error in affinity filters

Fix a call to compute_api.get_all to properly exclude deleted instances.
Add tests to prohibit this error in the future.

After some thought, this can be further optimized to let the instance
query do all the filtering/matching.

Resolves bug 1107156.

Change-Id: I6d6a6ba44d38d363489853d0407ad4cc94046656
(cherry picked from commit 8bc80cab3c134d64953b4f6493cab80b5bdc1b69)
Merge "Fix an error in affinity filters" into stable/folsom
Add quotas for fixed ips.

DocImpact: there is now a default quota of 10 fixed ips per tenant.
This will need to be adjusted by deployers if that number does not
meet their needs.

Resolves bug 1125468 for folsom.

Change-Id: I970d540cfa6a61b7e903703f845a6453ff55f225
libvirt: enable apic setting for Xen or KVM guest.

Bug 1086352

Currently, nova doesn't enable apic setting for Xen or KVM guest
in its libvirt driver. Windows guests would not boot successful in
such case. This patch adds apic setting in libvirt driver for Xen
or KVM guest, which would fix this problem. A check is also added
to libvirt guest config test case for this patch.

(cherry picked from commit d0e930bd9f1bddf6223635fdc463b2176cc39690)

Change-Id: Ie213c9d086f77faf0cdc5a32337c5bf4b828cf5f
Create util for root device path retrieval

blueprint snapshots-for-everyone

Create libvirt.utils.find_disk(virt_dom) function.
This function will retrieve disk path from instance configuration.
Will return path both for file and device backed instance root devices.
Will throw error in case, when device can't be found.

Change-Id: I612a19221c6ff78079ab53a8d77295c555514c77
Integrate nova-network into Piston networking model.
Add util for disk type retrieval

blueprint snapshots-for-everyone

Add libvirt.utils.get_disk_type that retrieves format
for given file. Format can be raw, qcow2, or lvm.

Change-Id: I33898983cfa15db6b2654648ce32f72b6dd920cb
Add util for image conversion

blueprint snapshots-for-everyone

Add nova.virt.images.convert_image(source, dest, format)
that converts image to other format using qemu-img convert

Change-Id: I2c92cb31114c42717d0ddd011645dc7c661c82c6
Fixes bug Snapshotting LXC instance fails

Fixes bug 1058273.

The path of the disk for snapshotting LXC instance is debugged.
Also, virt_dom.managedSave(0) and self._create_domain(domain=virt_dom)
are not called for LXC instance, because they are supported by libvirt.

Change-Id: Idf8275a0222b2eb289e16dd245f7721e17fce21d
(cherry picked from commit b60646965de26974f8a8b81f6e43b72a6c8d44f5)
Implement snapshots for raw backend

blueprint snapshots-for-everyone

Use simple qemu-img convert for raw snapshots.
Polymorphically select snapshot behavior for
raw and qcow2.
Allow images to be constructed from actual device/file path.

Change-Id: I6a57e43c6775c144c41a53382dcc7504ce6d4c43
Simplify libvirt snapshot code path

The "cold" snapshot code path was unnecessarily complex. We were
traversing 3 layers of abstraction to reach 3 lines of code. I've
completely eliminated snapshot.py by moving all "cold" snapshot
functions into imagebackend.py and adjusting the libvirt driver
accordingly. This is the first pass of several I intend to make
against imagebackend.py, as it is far too difficult to read given
how basic the basic level of functionality it is intended to
provide.

Change-Id: Idfacffb7210ae61193ee4f2360d4b38f330a177c
Properly write non-raw LVM images on creation

Fixes bug 1075333

When force_raw_images=False and libvirt_images_type=lvm were set
together, selecting anything other than a RAW image would result in
an unbootable instance. This is because the downloaded image was
being directly dd'd onto the new LVM root, which will obviously not
work for any format other than RAW.

Simple change to use qemu-img to read from the image (letting it
decide the format) and write to the LVM root as raw.

Change-Id: I36494e6d0671c07f7511c10ef886c8cf84c18df7
Libvirt: Implement snapshots for LVM-backed roots

Uses the built-in LVM snapshotting mechanism to create a new
snapshot, use qemu-img to extract the full root into an image file,
then delete the snapshot volume. Although we typically zero deleted
LVM volumes manually, this is not necessary for snapshots, as LVM
handles it for us (per the documentation).

Change-Id: I82f21488671ffa3be3d0feba73ff631fa2a51ec0
Fixes: Bug 1120809
Flags: DocImpact
Libvirt: Add support for live snapshots

blueprint libvirt-live-snapshots

Implements support for live snapshots when QEMU 1.3 and Libvirt
1.0.0 are available. This implementation may function with other
hypervisors, at which point _check_use_live_snapshots can be
adjusted accordingly.

At a high level, the process is as follows. First we create a
destination file for the snapshot. This file uses the same backing
file as the origin disk and is of the same virtual size. We do this
since the combination of blockRebase and "shallow" copies are the
only bug-free method available as of QEMU 1.3 (Vish has submitted
patches upstream). This process ultimately produces a CoW file,
representing only the current delta between the root disk and
backing file. The final step converts the CoW delta to a backless
image matching the format of the origin disk.

Flags: DocImpact
Change-Id: Icba53336556295722c3f8b7345e6cd09d8ccfed9
Folsom uses FLAGS.
Remove lingering update_task_state.
Added fileutils requirement.
Folsom doesn't use instance['name'].
Fix incorrect function call.
Revert to older way of looking up path.