Updated code to update attach_time of a volume while detaching

While detaching volume from an instance, attach_time of the
volume is not updated. This task updates volume['attach_time']
to NONE at detach_volume.

Also modified the default value of XML attribute
volume['attach_time'] '-' to ''(a 0 length string) to
maintain consistency with existing code.

Fixes bug: 1056122

Change-Id: If56ceda6caab80fb803fcf194ed1dfb18808ec3a
(cherry picked from commit ee2dd66c9c2350d9c4aa4ae535daed7e8d72dfb3)
Use disk image path to setup lxc and uml container

fix bug 1079113

Change-Id: I9b9b10e77728d4d7863f49efc048c8a37b06953b
make QuantumV2 support requested nic ordering

fixes bug 1064524

The QuantumV2 did not honor nic ordering, so nics were attached in
Quantum's db natural order.  This patch sorts the networks honor requested nic
ordering when Nova calls the V2Quantum API.  Unit tests have been updated to
confirm ordering is honored.

Change-Id: I44a6a4736c78e86e83b6e682e63f93a5b47652da
don't explode if a 413 didn't set Retry-After

We use 413 error code not only for temporary out of memory
conditions but also for over quota issues. These kinds of
requests don't set a Retry-After header, but the code assumed
that was a valid key, thus exploding on a KeyError. Issue
caught in looking at tempest traces.

Fixes bug #1079387

Change-Id: Id406ab0799a35220b189b2e5292be092eb821ec5
add port support when QuantumV2 subclass is used

fixes bug 1070045

Fix the current implementation by checking if FLAGS.network_api_class is a
subclass of nova.network.quantumv2.api.API.  Previously, the API would
not accept port references unless the network_api_class string was
anything other than the QuantumV2 class.  This limitation prevented
subclassing.

This changeset includes additional API unit tests focused on QuantumV2
and requested networks.

Change-Id: I6b7b7389e127ff8b084ac379cb9aebccc102620c
Eliminates simultaneous schedule race.

Keeps host state in memory so multiple schedule attempts use the
up-to-date values that may have been modified by another greenthread.

Fixes bug 1073956

Change-Id: I69fdd9b46bde6b7408c501c42a6ef3b6dd92bbc2
(cherry picked from commit 94560ab57d9fc23673f42017e6f2a78cb2b66b7a)
Stop network.api import on network import

The nova.network.__init__.py was importing the network.api
automatically at import time. This was leading to some silly
workarounds (for example in nova/virt/firewall.py) involving
late importing nova.network to stop circular imports.

It is also causing issues with https://review.openstack.org/#/c/13007/
because quantum api needs to import a flag from network manager
which is causing a circular import.

This fixes the issue by moving to use the code from volume_api
which only imports the api class when the method is called. It cleans
up the tests that were stubbing out network.API and also removes
the unneeded workarounds.

Change-Id: I4c9b372d078ab4398e797335a8de5e9e1077e31f
XenAPI should only snapshot root disk

Change ID I3e2973 broke XenAPI migrations (resizes) as it caused snapshots
of all disks (including swap and ephemeral disks, if enabled) to be sent
over to the destination host.  The destination only expects vhds for the
root disk, named by sequence numbers.  swap and ephemeral disks ended up
with sequence numbers, also, messing up the re-building of the chain on
the destination.

Fixes bug 1064083

Change ID I3e2973 also didn't change the stub of VM.snapshot to
VDI.snapshot, but tests still passed due to the new code ignoring all
exceptions while snapshotting.  Potential issues in
snapshot_attached_here() would also be ignored due to excessive stubbing
in the xenapi migration testing.  This is also addressed here.

Change-Id: I145030f92a75615d056a30cabcb6ca97e34a8b6c
(cherry picked from commit fb101685cc14ed9b0396ce966e571d3fb457c32f)
Dis-associate an auto-assigned floating IP should return proper warning

Added new exception class CannotDissociateAutoAssignedFloatingIP and raised
exception instead of return.

Fixes bug 1061499

Change-Id: I348573a235c6b81653837267072b5c48fa15b8af
(cherry picked from commit ce04b13f26169e2d71b7d3122d3a769cb4348bf7)
Handle instances not being found in EC2 API responses.

Resolves bug 1080406 where InstanceNotFound was raised with None
as the instance id.

Change-Id: I805a9c8893f51ab22426e606ce260a04113f26e5
(cherry picked from commit c3639847011566f39a7bd08e29bab4a72847a333)
libvirt: ignore deleted domain while get block dev

The get_all_block_devices could raise libvirtError if domain was deleted
while listing instances. This will cause LibvirtISCSIVolumeDriver to fail
disconnect_volume. This patch ignores the domain that could not be found
to avoid this issue.

Fixes bug 1060836

Change-Id: I9dc994d8ca7fc084830adb4f6f9d3ca10e0fe577
(cherry picked from commit 5a16b8f3e230cad0fb8d1278b42e6754069e8501)
Fix XML response for return_reservation_id.

The XML serializer for create uses the server template for it's response.
However, when return_reservation_id is set, only a reservation_id is
going to be returned.

To enable the XML response to be serialized the reservation id is now
returned in a server tag/object.

This commit fixes bug 1061124

Change-Id: Ic74071b1d527c3f3752e296d3fd46a28a99beb76
Signed-off-by: Matthew Treinish <treinish@linux.vnet.ibm.com>
(cherry picked from commit 903b51e148c2f9e858b5ea0ca5b230ac308d76c5)
nova-manage doesn't validate key to update the quota

nova-manage doesn't validate the key value supplied to
update the quota, as a result unnecessary records will be
created in db and user will be under the impression that
quota value got updated.
This patch validates the input value given to the key.

fixes bug 1064359
Change-Id: I9928f30881aa2780a23005b5f69aa67a44f314c5
(cherry picked from commit 82d8ffec5b5220039e57685fe4359950d1209b14)
libvirt: continue detach if instance not found

Currently the libvirt code will always logout of the iscsi target
during detach error, but the exception will cause the volume to
remain in an attached state. This needs to be more consistent, so
This patch checks specifically for not found and logs a warning
and explicitly detaches. Any other exception will leave iscsi
logged in and leave the volume in the attached state.

Fixes bug 1057756

Change-Id: I23bb7f27e8a9b20fdbf62b0629ca8cc448f427c5
(cherry picked from commit cc02f6a5604892fb776158dab06b06f24a25cbfb)
Set instance host field after resource claim

Set the 'host' field on the instance after the resource tracker
on the compute node has accepted the build.

The field is set after resources are confirmed to be available while the
COMPUTE_RESOURCES_SEMAPHORE is held.  The semaphore ensures the
resources usage values will be consistent even if the
update_available_resource periodic task audit runs.

bug 1060255

(cherry picked from commit 5fd7a9dba127bae812333196a5fa48a933212aeb)

Also includes the following bugfix to the original patch:

Set host prior to allocating network information.

Make sure 'host' field on the instance is set before allocating
network information.

bug 1065004

(cherry picked from commit 2649f14673f8ef5ca257583f1cdf5fe57d4734b9)
Change-Id: I92105ec14924960ac8ef7ca8c810783085314e10
Update db entry before upate the DHCP host file.

Update fixed IP db entry before upated the DHCP host file.

Fixes LP Bug #1078718

Change-Id: I75504acfc1c571219938d25a7c3b1a452d3f1cb9
(cherry picked from commit 51490807bd4dddaa01ba56620ba3a6b9b8ad75a3)
'BackupCreate' rotation parameter >= 0

In the extension 'admin-actions' of OpenStack Compute API, the action
create backups should only accept rotation parameter greater than or
equal to zero.

If the 'rotation' parameter is negative, OS API returns a badRequest
400 HTTP error.

Fixes LP bug #1071168

Change-Id: I6ef08fbecb0f88942cdb16193e9d2c3831866fe9
(cherry picked from commit 6eac65a8e13d3040c0c6561709f59b3d9bab5435)
Deallocate network if instance is deleted in spawn

If the instance is deleted while the virt driver is spawning, an
InstanceNotFound exception is raised and caught in compute to prevent it
from being rescheduled. This also deallocates the network to prevent
leaking interfaces/mac/ips.

* Fixes LP1068716

Change-Id: I991f5956facf7b105faea137d4a5b48897e68ae6
(cherry picked from commit c27558518800322bd13de5d6bd58bffba4e1a92f)
Update kernel_id and ramdisk_id while rebuilding instance

While rebuilding an instances if kernel_id and ramdisk_id associated
with new image_ref then update instances table for instance_id
with the new kernel and ramdisk.

Fixes bug 1060925

Change-Id: I07dfdbed8580411adea14fd6c5be1a9569a7a021
(cherry picked from commit c781e90929a6b3c39c0528a864cf560a5a8999e2)
Fix Incorrect Exception when metadata is over 255 characters

Need to be in sync with Essex. Throw a new exception in api.py when key or value
is over 255 chars. Catch this exception end return back HTTP error 413.

add extra lines in exception.py to make pep8 happy

Fixes bug 1004007

Change-Id: I67694e3a9600b7dd0b80c519327327568751c2a4
(cherry picked from commit db7798a973bb05af5d4668a9f9b20ce62e8a47af)