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>
Convert libvirt vif classes over to use config API

The classes in the libvirt/vif.py file build up dictionaries
and partial XML snippets, which are then passed onto Cheetah
templating for XML generation. Instead of building up
dictionaries of parameters, return LibvirtConfigGuestInterface
object instances instead

blueprint libvirt-xml-config-apis
Change-Id: I4e977225e21219f408dd729ac280dcbfc6b8ba8f
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Convert libvirt connection class to use config APIs for graphics

Remove the <graphics> element from the Cheetah XML template and
make the libvirt connection class use the LibvirtConfigGuestGraphics
class for it instead

blueprint libvirt-xml-config-apis
Change-Id: Ifa18cab2aa6983c9439c6230a9109e40a6a0bbe3
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Convert libvirt connection class to use config APIs for serial/console devices

Remove the <serial> and <console> elements from the Cheetah XML template
and make the libvirt connection class use the LibvirtConfigGuestConsole
and LibvirtConfigGuestSerial classes for them instead

blueprint libvirt-xml-config-apis
Change-Id: I67031dad2969c9b36e2fe9230689c1b7bfbecfce
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Convert libvirt connection class to use config APIs for input devices

Remove the <input> elements form the Cheetah XML template
and make the libvirt connection class use the LibvirtConfigGuestInput
class for it instead

blueprint libvirt-xml-config-apis
Change-Id: I4fba2ddae2d32b0ff49685245fd905651885b61b
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Convert libvirt connection class to use config APIs for disk devices

Remove all the <disk> elements from the Cheetah XML template
and make the libvirt connection class use the LibvirtConfigGuestDisk
class for them instead

blueprint libvirt-xml-config-apis
Change-Id: I0f09a86e72e5e34bbd780b31177a65eb40fb5419
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Move NIC devices back after disk devices

Originally the NIC devices were listed in the XML after the
disk devices. Restore that order, simply for consistency.
No functional change.

blueprint libvirt-xml-config-apis
Change-Id: If62446292850d58e133b0c4cc42ca83018e1fca1
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Introduce a class for storing libvirt snapshot configuration

Extend the libvirt config APIs to include a new class
LibvirtConfigGuestSnapshot for storing information about
guest snapshots

blueprint libvirt-xml-config-apis
Change-Id: Icc54f6f5cf41b05d904659e0a337bddb4bef5733
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Convert libvirt connection class to use config APIs for filesystem devices

Remove the <filesystem> element from the Cheetah XML template
and make the libvirt connection class use the LibvirtConfigGuestFilesys
class for it instead

blueprint libvirt-xml-config-apis
Change-Id: I9dad031703161d1dff86af03eff7b1ebf657fc0c
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Convert libvirt connection class to use config APIs for guests

Remove the entire Cheetah XML template for libvirt guests
and make the libvirt connection class use LibvirtConfingGuest
classes instead

The nova 'libvirt_xml_template' config parameter is now obsolete
and removed.

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