Volumes API now uses underscores for attrs

* Fixes bug 943053

Change-Id: I7066e963b4377a4a1f8a3c259e6273e6a0ca073f
Fix launching of guests where instances_path is on GlusterFS

The FUSE module does not (currentl) support O_DIRECT on files.
This prevents QEMU from starting guests using 'cache=none' for
their disks located on a GlusterFS filesystem. The same also
applies for a handful of other filesystems (notably tmpfs, or
any other FUSE filesystem).

This patch introduces a startup check in Nova compute service
which tries to create a file $instances_path/.direct_io.test
using the O_DIRECT flag. If this succeeds, then cache=none
will be used for all disks, otherwise it will fallback to
using cache=writethrough. While the latter does not have
performance which is as consistent as cache=none, it is still
host-crash safe and preserves data integrity with migration,
if the filesystem is cache coherant (cluster filesystems like
GlusterFS are, NFS by constrast is not).

By doing the dynamic check for O_DIRECT, we ensure that if
future FUSE modules gain O_DIRECT support, Nova will automatically
do the right thing.

* nova/tests/test_libvirt.py: Stub out os.open in
  the _check_xml_and_disk_driver() to enable testing of
  both O_DIRECT and non-O_DIRECT code paths
* nova/tests/test_virt_drivers.py: Set instances_path to
  the current directory
* nova/virt/libvirt.xml.template: Replace hardcoded 'none'
  string with the '$cachemode' variable for all disks.
  Add missing 'cache' attribute for the config disk
* nova/virt/libvirt/connection.py: Check whether O_DIRECT
  is supported on the "FLAGS.instances_path" directory
  and use 'none' for cachemode if it is, 'writethrough'
  otherwise

Bug: 959637
Change-Id: I60cbff1c3ad8299fe2aa37099390f9235f6724d0
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Use key in locals() that actually exists

Fixes bug 963263

Also, fix whitespace so we don't end up with two almost identical
strings to internationalize

Change-Id: I4c4faa0c335bdafca9426e2056113bb6f87abc3a
Send a more appropriate error response for 403 in osapi

 * Don't use resizeNotAllowed for 403
 * Fixes bug 949444

Change-Id: Ib2b5acba291a04e0c0296fa5e8438019983dda20
Merge "Remove unused certificate SQL calls."
Merge "Volumes API now uses underscores for attrs"
Merge "Send a more appropriate error response for 403 in osapi"
Merge "Fix launching of guests where instances_path is on GlusterFS"
Introduce a set of classes for storing libvirt guest configuration

With the current Cheetah template based approach to XML
generation, there is never any canonical representation
of the guest configuration. When generating XML, a hash
is filled in with parameters to be used to generate XML,
an even some pre-built XML snippets. When reading XML,
typically XPath is used, but sometimes manual DOM traversal
is used.

This change introduces a set of classes for explicitly
representing the guest configuration. They are intended
to allow the guest config to be read/written using normal
programatic APIs, avoiding the need for any code to know
about XML.

This first impl though, only supports writing of XML.
The code to parse an existing XML doc is not yet written.
The class hierarchy is as follows

  LibvirtConfigObject
   |
   + LibvirtConfigGuest
   + LibvirtConfigGuestDevice
      |
      +- LibvirtConfigGuestDisk
      +- LibvirtConfigGuestFilesys
      +- LibvirtConfigGuestInterface
      +- LibvirtConfigGuestInput
      +- LibvirtConfigGuestGraphics
      +- LibvirtConfigGuestChar
          |
          +- LibvirtConfigGuestSerial
          +- LibvirtConfigGuestConsole

The base LibvirtConfigObject class provides some generic
boilerplate code. Subclasses need to override the "format_dom"
method for generating XML DOMS, and "parse_dom" for reading XML
DOMs. The conversion from DOM <-> XML String is handled by
the base class. The DOMs are based on the lxml.etree.Element
class.

 * nova/tests/test_libvirt_config.py: Test cases for XML formatting
   of all config object classes
 * nova/virt/libvirt/config.py: Config object classes for libvirt
   guest XML schema

blueprint libvirt-xml-config-apis
Change-Id: I0474b6640b47ad0e5bb74503a5ff99a8a41bcdc4
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Delete the test_preparing_xml_info libvirt test

The test_preparing_xml_info test case is about to be intentionally
broken by refactoring in following patches. It will be replaced
by a new test at the end

blueprint libvirt-xml-config-apis
Change-Id: I2c5f19a071983e581ed5ed3bc8a84e14fbb6897b
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Convert libvirt volume classes over to use config API

The classes in the libvirt/volume.py file build up XML
strings using printf style substitutions. Convert this
over to use the LibvirtConfigGuestDisk config class
instead

blueprint libvirt-xml-config-apis
Change-Id: Ied1fad47db6fb23b74edc4405015768c764a4d10
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>