Fix an error in affinity filters

Fix a call to compute_api.get_all to properly exclude deleted instances.
Add tests to prohibit this error in the future.

After some thought, this can be further optimized to let the instance
query do all the filtering/matching.

Resolves bug 1107156.

Change-Id: I6d6a6ba44d38d363489853d0407ad4cc94046656
(cherry picked from commit 8bc80cab3c134d64953b4f6493cab80b5bdc1b69)
populate dnsmasq lease db with valid leases

At start dnsmasq retrieves its lease db by calling the nova-dhcpbridge
script with the init action.

Previously we were returning all allocated IPs in the network and
calculating the lease exirpation time based upon instances.updated_at
or instances.created_at.

Now we are only returning entries for IPs that are allocated and leased.
Additionally we set the lease expiration time to be i
now + CONF.dhcp_lease_time

Change-Id: Ie3b4fafd38094dc01ceea592ab5229e581193512
Fixes: bug #1103260
(cherry picked from commit e12339def3d9182f5ab23869e6bdc946e8e42825)
Avoid vm instance shutdown when power state is NOSTATE

* nova/compute/manager.py (_sync_power_states): Log the condition
where we can retrieve the state from the hyperviser, rather than
stopping the VM.

Related grizzly commits are 95e77703 and ad101ce5

Fixes bug: 1085771
Change-Id: I5fb9fdc6bcde729c00c4931960ed0de3b8fa189d
VNC Token Validation

Force console auth service to flush all tokens
associated with an instance when it is deleted.
This will fix a bug where the console for the
wrong instance can be connected to via the console
if the correct circumstances occur. This change also
makes a call to veriry vnc console tokens when a
user attempts to connect to a console. This ensures
the user is connecting to the correct console.

bug 1125378
Change-Id: I0d83ec6c4dbfef1af912a200ee15f8052f72da96
Handle compute node not available for live migration

This patch handles exception.ComputeServiceUnavailable by restoring
instance's vm_state and instance's task_state after live migration
failure caused by unavailable source/dest compute node.

Raises detailed HTTPBadRequest explanation for this exception.

Fixes bug 973393 and bug 1051881

Conflicts:
	nova/scheduler/driver.py
	nova/scheduler/manager.py
	nova/tests/api/openstack/compute/contrib/test_admin_actions.py
	nova/tests/scheduler/test_scheduler.py

Change-Id: If825b61fad9c4e3030f2e6c5002907255eaf3661
remove intermediate libvirt downloaded images

* nova/virt/images.py (fetch_to_raw): When converting a downloaded
image to raw, ensure we delete the original download image.
I.E. the .part file.  The regression was introduced in 7c265343.
* nova/tests/test_libvirt.py (test_fetch_raw_image): A new test
for this function which wasn't tested previously.

Conflicts:

	nova/tests/test_libvirt.py
	nova/virt/images.py

Fixes bug: 1125068
Change-Id: Ie6f2cff1a554b8500fd66f0832566ae1b317be40
(cherry picked from commit 1501a4e4f75efb63385a1dadc728c2ef245bf7de)
Ensure we add a new line when appending to rc.local

When we add content to rc.local, if the file already
exists then we need to make sure we add the content
after a new line explicitly

Fixes LP #1089668

Change-Id: I35be1496703b302f732363fa76ce832505eed599
(cherry picked from commit f393a513d7894ddb800e4dfc87da896600fb7421)
Fix double reboot issue during soft reboot

Using the ID of domain in Libvirt to recognize the hard reboot has been
implemented or not, if the ID changed, we believe the domain has been rebooted,
return True and break from soft reboot.

Fixes: bug #1046356

Change-Id: Iec2f9e8225cfe2779f84d2095667f3c0e621e935
(cherry picked from commit 6344bff494758e0d7d7d25f43a3b56d82447441e)
libvirt: Optimize test_connection and capabilities

The getCapabilities call can be very slow so it is not a good choice
for testing the libvirt connection. This patch switches to
getLibVersion and also caches the result of getCapabilities so it
doesn't need to be requested every time. Note that this means that
nova-compute will need to be restarted if the capaabilities of the
host changes. This is an acceptable risk because capabilities
changes should be very rare and nova-compute should be restarted
if libvirt is restarted or reinstalled.

This simple change lowers boot time in my devstack install from
22 seconds down to 8 seconds!

Fixes bug 1100446
(cherry picked from commit ec3d7e4cb882eff42fa8f1e5f8f52723fb909b0e)

Conflicts:
	nova/virt/libvirt/driver.py

Change-Id: I3adbb48a2859a54ed93503f26de684acbd157841
Merge "Handle compute node not available for live migration" into stable/folsom
Merge "remove intermediate libvirt downloaded images" into stable/folsom
Decouple EC2 API from using instance id

Continuation of 0dc32690fe158e4cb11c2c9bcc65acaf73b94a7a

Some code in ec2 api use Instance.id rather than InstanceIdMapping.id
directly while converting ec2 id to an instance object. This is very
dangerous if Instance.id is not equal to InstanceIdMapping.id for the
same instance uuid.

To avoid the id mapping confusion, this patch:

 * uses instance_id_mappings.id instead of instances.id
 * uses instance_uuid in ec2utils.id_to_ec2_inst_id
 * removes ec2utils.ec2_instance_id_to_uuid

Fixes bug 1145490

Change-Id: I22638f667c18eefe542b03e31f1a3aa2ce782db7
(cherry picked from commit 79cc2a21b645138f70c6ca4b54053f69c0dde81d)
Enable VM DHCP request to reach DHCP agent

When using the firewall driver IptablesFirewallDriver and the
default INPUT and FORWARD rules are DISCARD then the DHCP
request from the VM is discarded prior to getting to the dnsmasq.

New rules will be added that enable DHCP requests to pass.

This fixes bug 1131223

Change-Id: I5117458d6a4c0fe2e333f6f3c2f902672e6293e5
Merge "VNC Token Validation" into stable/folsom
Merge "Avoid vm instance shutdown when power state is NOSTATE" into stable/folsom
Merge "Fix an error in affinity filters" into stable/folsom
Add quotas for fixed ips.

DocImpact: there is now a default quota of 10 fixed ips per tenant.
This will need to be adjusted by deployers if that number does not
meet their needs.

Resolves bug 1125468 for folsom.

Change-Id: I970d540cfa6a61b7e903703f845a6453ff55f225
Don't include traceback when wrapping exceptions

The fix in fa52cb09b2270876c9d9a03106f961be6c9db834 strips tracebacks
from exceptions when returning them to the user, but it still spams
the log with a long traceback. We shouldn't be including the traceback
when we wrap the exception in the first place. Instead we just
include the message.

It also updates the error code to 409 for device in use since this
is actually a conflict.

Fix for:

  bug 1155315
  bug 1103324
  bug 1092610

Change-Id: I95019a3022eb52e0335c455009c13fe229475d03
(cherry picked from commit d63bd8d692a9eb16caa818101cdbb3358f6b4681)
libvirt: enable apic setting for Xen or KVM guest.

Bug 1086352

Currently, nova doesn't enable apic setting for Xen or KVM guest
in its libvirt driver. Windows guests would not boot successful in
such case. This patch adds apic setting in libvirt driver for Xen
or KVM guest, which would fix this problem. A check is also added
to libvirt guest config test case for this patch.

(cherry picked from commit d0e930bd9f1bddf6223635fdc463b2176cc39690)

Change-Id: Ie213c9d086f77faf0cdc5a32337c5bf4b828cf5f
Fix bad Log statement in nova-manage

Remove the log statement per discussion in the bug report
https://bugs.launchpad.net/nova/+bug/1018431/comments/3

Fixes bug 1018431

Change-Id: Ia6fe511ae23155de8b78689639b53a0d9ed1d051
(cherry picked from commit 6b137d8bec08a170e06fc011637c620fe76cf90d)