Network: replace neutron check with decorator

Commit a581823ecee286c5c6329c9c373f0fea0b6b729f added in a
validator that would check if neutron was enabled.

It is much cleaner to do this as a decorator. The decorator
here needs to preserve the function signature.

Change-Id: I355e4bcee5e93a7f1459672e10ad7793d2bf8a49
Enforce query order for getting VIFs by instance

When spawn VM with multiple nics, during the phase of VM network allocations
using nova-network, the networks pass into driver layer will get reordered
by vifs queried by instance. We have to enforce the query order with vif
creation order rather than rely on the database backend's order.

Change-Id: I51333cc82c03e20d89d3ea548ff164fe71b5ba26
Remove spaces from SSH public key comment

An SSH key generated by Nova contains the comment 'Generated by Nova'. Older
versions (prior to 0.7.2) of cloud-init trip over the spaces in the comment
and as a result of that the key injected into the root account is not disabled
by cloud-init. Yes, it's a cloud-init bug but it's also a regression in the
sense that older OpenStack installations (Essex and older) don't contain
spaces in Nova generated key comments and thus older cloud-init's are not
affected in these environments.

This patch replaces the spaces with dashes, i.e., 'Generated-by-Nova'.

Spaces were introduced by commit: 114109dbf4094ae6b6333d41c84bebf6f85c4e48
Ubuntu cloud images with cloud-init < 0.7.2: 10.04 LTS and 12.04 LTS
cloud-init bug report: https://bugs.launchpad.net/ubuntu/+source/cloud-init/+bug/1220273

Closes-Bug: #1297685
Change-Id: I1761f61dfbba58be98351ae4a51884b03268cf09
XenAPI: Add logging information for cache/download duration

We would like more explicit information on when images are cached.
This commit logs information on whether we are attempting to cache,
whether we downloaded, and how long it took to download.  This
log information can then be used for further processing elsewhere.

Change-Id: Ia971008fabec06c4ba8fc1db4b67474f52604b17
Cells: Pass instance objects to build_instances

When the cells scheduler creates instance records in its local db it
should keep the instance objects created.  build_instances expects a
list of instance objects so to keep parity between cells and non-cells
the cells scheduler needs to call build_instances with its list of
instance objects.

Part of bp remove-cast-to-schedule-run-instance

Change-Id: I4a1a96693f9c3cb92ffdccfebaeb2432584d4105
Add refresh=True to get_available_nodes call in build_and_run_instance

The run_instance code path passes refresh=True to get_available_nodes in
order to get fresh data from that call.  The build_and_run_instance
patch doesn't pass that argument and therefore may not get the latest
data.  This ports the argument over to that path to prepare for using
build_and_run_instance.

Part of bp remove-cast-to-schedule-run-instance

Change-Id: If857fdb4125d4af656f86de3e963987dd32c208b
Register objects in more services

We should be making sure we're registering objects in the services that
use them. In patches that follow, we'll stop importing the specific
object modules under nova/objects/. Also, we should register objects
after the config has been parsed, logging setup, and things monkey
patched. Also, also, also: let's import all objects and put the imports
in alphabetical order.

Change-Id: I07f4584c43bd88960d543962a162cd1dd8dea09a
Address issues with objects of same name

There are at least a couple of cases where we may (in the future) introduce
multiple objects that have the same name:

1) When we subclass an object to override internal behavior, presenting
the same version of the object.

2) When we want to introduce multiple versions of objects either via
subclassing or completely separate classes if differences are large
enough to warrant that.

There was a rough plan to support this, however we're currently very
broken. The code before this patch would happily track every one of the
objects with the same name. However, in the case where we see the same
version during 'object registration', we should actually always take the
newest one that we see, replacing the old one.

Also, throughout nova, we have code such as:

from nova.objects import instance as instance_obj

inst = instance_obj.Instance.<....>

This means we're always using the base object, which may or may not be
the correct ('newest') one.

This patch fixes the object registration and adds an attribute to the
'nova.objects' module for every object that is registered, setting the
attribute to the newest version we see.

This will allow us to drop a number of object module imports in favor
of simply importing nova.objects. The example above would become:

from nova import objects

inst = objects.Instance.<....>

Because the object registration ensures objects.Instance is the newest
version, we'll be golden.

Partial-Blueprint: object-subclassing

Change-Id: I04694ecd40e0d4ec40a87d319f2e689060b11651
Fix nova/compute direct use of instance module objects

This switches the nova/compute code to use nova.objects.Instance* vs
nova.objects.instance.Instance* so that subclassing of objects will work
properly.

Partial-Blueprint: object-subclassing

Change-Id: I941ebb14caeb29fe55bb93bccaf95fd158024d34
Handle situation when key not memcached

LOG a warning message if the key not memcached successful. This will
happen if memcached module is used but the memcached servers are not
reachable.

Change-Id: Ia3c51fe8fc82060586a014f5cb1083d5695ab455
Closes-bug: 1213660
Payload meta_data is empty when remove metadata

When update metadata for a host aggregation, all of the values will
be in the variable of "updates", if remove metadata, the format would
be {"foo": None, "bar": None}; If adding metadata, the format would
be {"foo": "foo1", "bar": "bar1"}.

The current logic of update_metadata() is as following:
1) Get all metadata from variable "updates".
2) Traverse updates to see which values are new added and which needs
to be removed. For the new added values, put the metadata to
variable "to_add"; for the values which need to be removed, just
remove them from metadata.
3) Set the values of variable "to_add" as payload metadata.

The above logic will make the values which was removed from metadata
cannot be in payload, this caused the third party receiver cannot know
which metadata was removed.

The fix was always using the values from variable "updates" as the
metadata for payload as it include values removed and new added.

Change-Id: I7b78795e325f52cfb9c24eabd9ef42990666c02d
Closes-Bug: #1269684
Remove all mostly untranslated PO files

We now only import PO files that are at least 75 % translated,
so we can delete now all other PO files. The patch only
removes the mostly untranslated files. Once a file becomes mostly
translated, the bot will import it again.

This patch leaves the mostly translated language Spanish as
well as US English in.

Change-Id: I1c45fb62bd2bd25fc2b0188be8f9d6903e743851
Closes-Bug: #1317794
Do not wait for neutron event if not powering on libvirt domain

When resizing/migrating a stopped instance, the power_on flag is False
in _create_domain_and_network so virtual interfaces are not plugged and
we are waiting for an event callback from Neutron that won't happen.
This leads to an eventlet timeout and subsequent attempt to destroy the
non-running domain, which results in a libvirtError.

This change just adds the power_on flag to the list of conditions for
determining if we should wait for an event callback from Neutron.

Closes-Bug: #1321872

Change-Id: Id87ed125db8b1e807b7fa0d99180d0820edbed3e
Merge "Handle situation when key not memcached"
Merge "Network: replace neutron check with decorator"
Merge "Cells: Pass instance objects to build_instances"
Merge "Enforce query order for getting VIFs by instance"
Merge "Payload meta_data is empty when remove metadata"
Merge "Add refresh=True to get_available_nodes call in build_and_run_instance"
Merge "Do not wait for neutron event if not powering on libvirt domain"