Move volume_clear option to where it's used

The `volume_clear` and `volume_clear_size` option are used in `lvm.py` so we
should move the definition there.

Change-Id: Ic619c2db0bb1b5ccc7dcbec1a500c3dcb1110b26
Correct a maybe-typo in pci_manager

the variable 'dev' in set_hvdevs are only used for list comprehension,
it does not make sense to use 'dev' again for updating self.stale.

Change-Id: I03f31bfcfc56a43e43eb88845e1d562f19a3a09e
Adjust audit logs to avoid negative disk info

When requesting more disk than is available, the audit
logs will report negative values. This may confuse the
user or make him/her think the tracking is innaccurate.

This patch seeks to remove any confusion. It is in the
same vein as https://review.openstack.org/#/c/93261/
which addresses the same issue in regards to cpu and
memory audit logs.

Change-Id: I184985573b20144717ac40f1f3c26709030d5a03
Closes-bug: #1350542
baremetal: Remove depenency on libvirt's fetch_image method

It's messy for virt-drivers to depend on each other, so this patch alters
baremetal to use the cross-driver fetch function, instead of the libvirt
version.

Change-Id: I910c621452fa7eb9add417a8738e5757aeb1a48c
libvirt: Fix kwargs for _create_image

Rescue uses the `suffix` and `disk_images` kwargs of `_create_image`, but
passes them in as positional args. We should use explicit kwargs here to be
clear that rescue depends on both of those parameters being present.

In addition, disk mapping was being passed in as kwarg, but is actually a
positional arg, so we should pass it in as a positional arg to be clear that
it's required.

Change-Id: Iaa990729b4bb3569f4c71ceaf1adabed58f73026
Remove libvirt legacy LVM code

The Change-Id Ib36b962971fd1f66ea9a0818e91fec59e118e686 fixed an
issue which could have caused volumes no longer being able to be
cleaned up due to it's reliance on the instance_name_template
configuration option.

There was code in place to handle both disk formats which are
the legacy format (volume name prefixed by instance name) and
the new one (volume name prefixed by instance uuid).

This commit removes the legacy format which was due to be
removed from the code.

UpgradeImpact - this removes support for really old lvm names that
could have been created in Havana clouds. That means there is a
possible failure to cleanup of lvm volumes that existed uniterupted
since Havana.

Change-Id: I28497a650fbd012643080951f7d86ab8780fd59c
Fix swap_volumes

The attach and detach calls to cinder are better handled by cinder this
patch removes them. There is another patch against this bug to modify
cinder.

The attach call is being made against the new volume after the
migrate_volume_completion request. This means it may be done after the
new volume ID in the db has been deleted.

The detach call is being run at the end on the old ID and so may end up
detaching the migrated volume from cinder's perspective.

Change-Id: I3f2d98e9e473905a3de2f02e00c92ae3065e6ae7
Partial-Bug: 1316079
Add warning to periodic_task with interval 0

In Ia227f4c4e69ecf361ab02d1d17a3010303650104, warnings were
added for several options but instance_delete_interval was
left out by mistake.

Closes-Bug: #1188226
Change-Id: I20b396d664e40252743cac4f2a49f4f34882b32f
Ironic: save DB calls for getting flavor

The commit bceb6342994fc9d38a51a19e5b07652a5fdfd503 would read
the flavor a number of times instead of passing a flavor as a
a parameter.

This save an unnecesary DB access.

Change-Id: I4dc8739129a694d6ddae1ed9f1998663a2204d89
Xen: Attempt to find and cleanup orphaned SR during delete

Before some patches merged to better handle failures to boot an instance
from a volume it was possible to have an attached volume with an SR and
plugged PBD but no VM.  And the destroy method in xenapi short circuits
if no VM is present because everything is looked up from there in order
to be cleaned up.

This adds a check to see if a volume is supposed to be attached during
destroy if no VM is present and attempts to look it up via the SR uuid
and clean it up.

I would like to say that this patch is unnecessary, as it's sort of
hackish, but it's possible that some deployments have instances in this
state and this will allow them to cleanup without manually running
commands on the hypervisor.

Closes-bug: #1367918
Change-Id: I7745af7e22164a96af800ae796bda077e49bf291
Remove unused elevated context param from quota helper methods

The elevated context being passed to the _quota_usage_create and
_reservation_create methods is not used, so remove it from the formal
parameter list of those methods and related usage.

This is part of a larger series to refactor the quota_reserve method.

Partial-Bug: #1369605

Change-Id: I50749402177eda29ae006ec4fd11a9a8125765ec
Libvirt: Always teardown lxc container on destroy

This fixes a bug where shutting down a libvirt-lxc based instance
would leak its underlying nbd device. This was happening because
_teardown_container would only get called if the domain was
present. After this fix, _teardown_container will always get called
on a destroy, which ensures the nbd device gets disconnected.

Change-Id: I8d0044fd038fef80568c6c86e34719ef679aa890
Closes-Bug: #1367363
Fix KeyError for euca-describe-images

EC2 describe images crashes on volume backed instance snapshot which has
several volumes.

Change-Id: Ibe278688b118db01c9c3ae1763954adf19c7ee0d
Closes-bug: #1370265
move dict copy in prep for object-ify flavors

This change is to help split up the patches for object-ifying flavors.
It moves a dict copy of instance_type from the tests to
get_flavor_by_flavor_id().

Change-Id: I0082a56aa637169fd6e1db3aad56877c9f745bc5
refactor flavor db fakes in prep for object-ify flavors

This change is to help split up the patches for object-ifying flavors.
It refactors db fakes to provide default values for fields that are
not nullable in flavor objects.

Change-Id: I18575703cd5c52d4f446c9bca1edd7baf33b416f
refactor flavor manage tests in prep for object-ify flavors

This change is to help split up the patches for object-ifying flavors.
It refactors flavor manage tests to provide default values for fields
that are not nullable in flavor objects.

Change-Id: I59f0254269379ace2186ed90810c5d1a9f09fed7
Update InstanceInvalidState output

Update InstanceInvalidState output because the original format
is not valid and will lead to none readable output.

Change-Id: I8481facd8100ce9a6f87ea208c06d99016a89534
Fixes Hyper-V dynamic memory issue with vNUMA

vNUMA and dynamic memory are mutually exclusive, so the former
needs to be disabled for instances where dynamic memory is enabled.

Change-Id: Ic730c294ffc89925076688a44adf2594c7f6712b
Closes-Bug: #1305897
Change test function from snapshot to backup

According to test function name 'test_backup_invalid_state',
the usage of functions should be backup instead of snapshot.

Change-Id: Ic07766d06875983a3ca59fccc272c708ebefdbba
Making nova.compute.api to return Aggregate Objects

nova.compute.api should return Objects and they should be
converted into the REST API expected result in the API extensions

Change-Id: I4bfd83ab92c719b1776da6445e6a4ea78d2ddfd6
Closes-Bug: #1292644