Fix state sync logic related to the PAUSED VM state

A VM may get into the paused state not only because the user request
via API calls, but also due to (temporary) external instrumentations.
Before the virt layer can reliably report the reason, we simply ignore
the state discrepancy. In many cases, the VM state will go back to
running after the external instrumentation is done.

Fix bug 1097806.

Change-Id: I8edef45d60fa79d6ddebf7d0438042a7b3986b55
(cherry picked from commit f7fbdeb5672bae7d3bffd6fa76de1ce81fc132bf)
Add a safe_minidom_parse_string function.

Adds a new utils.safe_minidom_parse_string function and
updates external API facing Nova modules to use it.
This ensures we have safe defaults on our incoming API XML parsing.

Internally safe_minidom_parse_string uses a ProtectedExpatParser
class to disable DTDs and entities from being parsed when using
minidom.

Fixes LP Bug #1100282 for Folsom.

Change-Id: I6a4051b5e66f3ce5a330b2589c42e6e9e5b9268e
Enable libvirt to work with NoopFirewallDriver

Fixes bug 1050433

Change-Id: I49613c7d1e6b14411dcdc342366e163a21673f78
Merge "Add a safe_minidom_parse_string function." into stable/folsom
Merge "Enable libvirt to work with NoopFirewallDriver" into stable/folsom
Merge "Fix state sync logic related to the PAUSED VM state" into stable/folsom
libvirt: Fix nova-compute start when missing ip.

If nova-compute is restarted when an instance has no ip address
the libvirt/vif:_get_configuration method will throw an index
error. Check for existance of an ip before attempting to retrieve
one. Includes failing test.

Fixes bug 1131330

Change-Id: Id383544b44e64205fc3b4f850d0d11ad2ebd5da7
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
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'].