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
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)
Fix config-file overrides for nova-dhcpbridge

nova-dhcpbridge can read in an alternate config file location but wasn't
using it to parse config options.  This fixes a regression introduced in
00786bc554a2dfacb3c6f02fbb7e9c98f35d4262.

This change is motivated by the fact that nova-dhcpbridge is passed to
dnsmasq in restart_dhcp() in nova/network/linux_net.py, and there is
currently no support for overriding config options for nova-dhcpbridge
in that call.  There is support for overriding the FLAGFILE env variable
in that call, but nova-dhcpbridge was ignoring that.  If I start
nova-network with an alternate config this provides a way for me to pass
that config to nova-dhcpbridge as well.

Change-Id: I002ea768500555a089bd1d5b0fea2354b27fba14
(cherry picked from commit ae0a0d54351e71e3d723d7c0c6de8db2cdbab772)
Declare vpn client option in pipelib

Due to some import refactoring, nova.network.manager isn't always
imported when running pipelib commands, so using the cnt_vpn_clients
option fails. A failing test could not be added because our testing
code imports nova.network.manager so the code config option always
exists in testing.

Fixes bug 1069573

Change-Id: I92b702556bfef2610b86a952dd6f9207fbab102a
(cherry picked from commit ae6920fb6b367b5aa75e02c72275e3149d02cd70)
Fix error on invalid delete_on_termination value

1. Fixed 500 error when an invalid value is passed to 'delete_on_termination'
parameter in 'block_device_mapping' of create server API (json request).
Converted the value to 'bool' (similar to XML request workflow) to fix issue.
2. Also added unit test coverage.

Fixes LP: #1060955

Change-Id: Ib35040f17a3712dac45ec1e3c2f32fee17db7c03
(cherry picked from commit 7c9761b3bb52788021b5bf0eb9726af833db4074)
Save exceptions earlier in finish_resize

Fixes bug 1071595

When catching exceptions, _quota_rollback is called before we save an
exception for re-raising later.  Also: we should ignore any possible
exceptions from _quota_rollback so we are sure to set instance to error.

Change-Id: I50cb4879f7dcc13f99fa23a45030b4140dfc326a
(cherry picked from commit 50a0f3efb6cc4ae9c94439eea346828d35080d6c)
Fix typo so setting volume_tmp_dir works

apply the same change that was applied to cinder
https://review.openstack.org/#/c/14863/

Fixes LP bug #1071536

Change-Id: I4cfdb38debfcb4a890c2d7fd7405ac9dc755f0ec
(cherry picked from commit 3f1af292f4771a384230ec80c32f2d253cef8bc1)