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
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
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
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 "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"
Merge "Register objects in more services"
Merge "Address issues with objects of same name"
Merge "Fix nova/compute direct use of instance module objects"