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)
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
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
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)
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)
Fixes PowerVM spawn failed as missing attr supported_instances

During test in a cross-hypervisor environment (KVM+PowerVM), user will run
into an issue during deploying an instance for Power host by PowerVM driver,
though the property "hypervisor_type" for the PowerVM image have been
configured. Since the _update_host_stats of PowerVM driver missing the
attribute "supported_instances".

Fixes bug: 1155498

Change-Id: I81259d153a7b5ae35747e57c53b14e0075d28d78
(cherry picked from commit ecab528830a294881569aa20a6e07c9bb65ce460)
Merge "Fix double reboot issue during soft reboot" into stable/folsom
Merge "Enable VM DHCP request to reach DHCP agent" into stable/folsom
Handle compute node records with no timestamp.

Commit 94560ab57d9fc23673f42017e6f2a78cb2b66b7a added a fast-path
to avoid work when baremetal compute nodes haven't changed, but if
the compute message has None for its updated-at timestamp (which
can happen during startup) the comparison crashes.

Fixes bug: 1096719
Change-Id: Ib8add431d975eee133deefea62eb53479a97396e
(cherry picked from commit fad69df25ffcea2a44cbf3ef636a68863a2d64d9)
Merge "libvirt: Optimize test_connection and capabilities" into stable/folsom
Merge "populate dnsmasq lease db with valid leases" into stable/folsom
Merge "Fix bad Log statement in nova-manage" into stable/folsom
Merge "Fixes PowerVM spawn failed as missing attr supported_instances" into stable/folsom
Merge "Decouple EC2 API from using instance id" into stable/folsom
Merge "Don't include traceback when wrapping exceptions" into stable/folsom
Fix Wrong syntax for set:tag in dnsmasq startup option

Looks like the introduction of quotes in fix for previous
bug 1012443 was erroneous.

Fixes LP# 1152504

Change-Id: Ic84739e38e3b3567f1617302a33623de03196f85
(cherry picked from commit d8188ef32293659c5a12d99f82ac19b452184967)
Adding netmask to dnsmasq argument --dhcp-range

By default, dnsmasq will try to guess the proper subnet size but
sometimes it will fail. This patch provides the network netmask
to dnsmasq via the --dhcp-range argument.

Fixes: bug #1154929

Change-Id: I74d62c837b5310004b9151851697e3ea3b475f92
(cherry picked from commit fb151b5e3704c9a293f10ba89abc14f83d803c24)
Set default fixed_ip quota to unlimited.

DocImpact: our previous default quota of ten was poorly thought through
and resulted in upgrade problems. Instead, let's have operators opt into
fixed IP quotas. This change should be mentioned in release notes please.

Resolves bug 1161190.

Change-Id: I2f066a0129461899fe330a628cf49ee5273eaba4
(cherry picked from commit 78c7edc52efdf31d844b8bb38c2460add4c864fb)