Fixes unexpected exception message in PciConfigInvalidWhitelist

When an exception PciConfigInvalidWhitelist occurs, the message "An
unknown exception occurred." was obtained. This is due to the content
of the variable not being overriden correctly. The same typo applies
to PciTrackerInvalidNodeId.

Closes-Bug: #1221493
Change-Id: I589cb8d0a1426eb84bbbc4a819b5585e4e746843
Ensure get_all_flavors returns deleted items

When a flavor is deleted a new one may be created with the same name.
However when calling flavors.get_all_flavors(inactive=True) only the
latest flavor with the same name is returned. When inactive=True all
flavors should be returned regardless of their name or replacement
state.

Change the key used in the returned dictionary from
flavors.get_all_flavors() to the flavorid rather than the name. This
allows multiple flavors with the same name to be returned.

Fixes bug 1215295
Change-Id: I1b0c93b3e12714a5c0798aa87c9e3fe9bc14519a
Add filter for soft-deleted instances to periodic cleanup task

The periodic cleanup task added recently does a db query to get
instances in need of cleanup. The filters applied to the query
must have a filter to not include soft-deleted instances.

This fix adds the required filter and adds a test to verify the
correct behavior.

Change-Id: I0c5d7e317d1fdd4e1e618c1c38870e775a715eab
Closes-Bug: #1223345
Don't lose exception info

Using eventlet introduces some extra fun into exception handling.  After
catching an exception, it is required to save off the exception details
if you want to be able to re-raise it later after doing other operations
which may do a greenthread switch.  That's what this patch does.  It
saves off the original exception that we intend to re-raise later and
ensures that nothing stomps on it in the meantime.

A test case was also added to exercise this code path to make sure the
exception saving and re-raising worked as expected.

Change-Id: Ibf5f06a30839b93ece500ce7dbb714f6509f85af
Closes-bug: #1202177
Adds V3 API samples for remote consoles, deferred delete

Adds V3 API samples for remote consoles, deferred delete
extensions. Bundling them together to save on review load

Partially implements blueprint v3-api-unittests
Partially implements blueprint v3-api-specification

Change-Id: I595532d9e1b8eed80336c0258be3e9d07ec7461e
Libvirt: volume driver set correct device type

Due to a typo, libvirt volume driver was assigning the device type
passed to the connect_volume method to the wrong attribute of the
LibvirtConfigGuestDisk class (non existing device_type which is
completely disregarded, instead of the expected source_device), which
caused the rendered XML to always have the device set to 'disk'. This
patch fixes that issue.

Also adds the 'lun' type to the list of supported device_types since it
is supported by libvirt but was missed in the previous refactoring.

Tests are added to prevent future regressions.

Closes-bug: #1223890

Change-Id: Iee160afcc23f762a752df1ca20372944d5100291
Fixes misuse of assertTrue in virt test scripts

Misuse of assertTrue in places where assertEqual should be used.

If assertTrue is used, the test will always pass
if the first argument's boolean cast is True.
The second argument passed to assertTrue() will be regarded
as the error message when the assertion fails.

Fixes bug #1220541

Change-Id: I63ec4f35ee1a2430a5f6b54e40108b2c4ce3d480
xenapi: fix where root_gb=0 causes problems

Auto_config disk and resize up should be able to correctly handle when
the flavor specifies root_gb=0.

When you try to resize down to root_gb=0, it doesn't really make sense,
so throw a reasonable error message, instead of failing in the middle of
the resize calculations.

Fixes bug 1152268
Change-Id: Ib26170d7d563cc8fd664c3680fecc4ac04e57b04
Ensure anti affinity scheduling works

The query for the group in the system_metadata would not correctly
filter the instances with the groups.

In addition to this change 4a03071db23196c4ac1ec0d8ea163c46887d3b08
ensured that the scheduling filter was only run once.
In cases when provisioning fails and rescheduling
takes place the filter must be invoked (if it is in the filter tool
chain).

Fixes bug: 1218878
Fixes bug: 1206502

Change-Id: I623c73635c36ffa038ae01476a25ba0c0863e536
Don't use ModelBase.save() inside of transaction

We using block 'with session.begin()' to organize some operations in
one transaction. session.begin() returns a transaction instance, then
does some operations, and will commit or rollback automatically
before leaving the block. ModelBase.save() always submit a commit,
and that is not expected.
When we get a persistent object from database, we just modify the
object inside of block 'with session.begin()' and sqlalchemy will
update it,don't need method session.add() or ModelBase.save()

Fixes bug #1224429

Change-Id: I8af3fd4b62a915833bf303b6892d432043fb57a9
VMware: Fix ensure_vlan_bridge to work properly with existing DVS

With Nova Flat Network, if the DVS exists, we should not try to
worry about virtual switches or port groups. We should just return
the network_ref

ensure_vlan_bridge was also missing the return of network_ref at
tne end of the method, added that as well since that return value
is needed/used in virt/vmwareapi/vmops.py#L191

Fixes LP# 1194018

Change-Id: I78c71e4c15f1aa87378ae2eb0448c047c6a2a666
xenapi: fix pep8 violations in nova plugins

Removed plugins/xenserver from tox.ini excludes list, ran tox -e pep8, and
fixed violations.

Fixes: bug 1197893
Change-Id: I8e0116304b07d54c49a01202b3ce6d3426097bb4
Object cleanups

1) Fix uses of hasattr(self, base.get_attrname()) to use self.obj_attr_is_set().
2) Remove an unused variable created by recent fix.
3) Use functools.wraps() on decorators so we get correct function names
in tracebacks.

Change-Id: I07aac43742894dad22231771083a94248d300711
Allow for nested object fields that cannot be None

Used in a follow up patch to fix a bug.

Change-Id: Ib1e44232643ad57e1bd21fb3bdbe7c4d1e0307f2
Don't allow pci_devices/security_groups to be None

These should never be able to be None in the Instance object.  They are
lists and can be empty, however.

Fixes bug 1228402

Change-Id: Id250f8921926f906e858a09759bdab888bd597b0
Instance object incorrectly handles None info_cache

1) When getting records from the DB, it's possible for info_cache to be
None, but this case was ignored.
2) When de-serializing Instance with a None info_cache, a traceback
would occur.

Fixes bug 1228426

Change-Id: I60e610aeafc9dea8d832adec10baaaecbae75215
Imported Translations from Transifex

Change-Id: I096c3cbc6be21fe12d0f8b9ecbe7c0226df98fa6
Fix Instance object assumptions about joins

The Instance object was assuming that security_groups and info_cache
were always joined for single instance_get() type queries.  This is a poor
assumption to make.  The object should explicitly ask for info_cache and
security_groups to be included in the DB object when necessary.

Also, we should actually fix sqlalchemy api to not join these always, but
that's probably too large of a change right now.  Instead, make sure we
don't ask to join them twice in the same query.

Fixes bug 1227251

Change-Id: Ib39a3d041904fb5ecebbe152f2fede135a0cdb6f
xenapi: Cleanup pluginlib_nova

* Removes dead code
* Prefixes internal functions with underscore
* Removes a few one-off functions in favor of inlining

Change-Id: Ic2f8c2e512df270f3b1b0e35ded98832a5152c72
Only update PCI stats if they are reported from the host

Not all drivers and hosts may report PCI stats. These should only
be updated if they are actually reported. This will save valuable cycles
and not have any unnecessary database access.

Fixes bug: 1228872

Change-Id: I3e0170638f3820422dbdea5dfb9e02b2de2ceacd