Add support for administrator to control instance mem used libvirt memtune

Registered by lizheming

Problem Description
--------------------————
Libvirt has supportted memtune, by use patameter "memtune", it can
control mem resource for instance which run in physical server.
<domain>
  ...
  <memtune>
    <hard_limit unit='G'>1</hard_limit>
    <soft_limit unit='M'>128</soft_limit>
    <swap_hard_limit unit='G'>2</swap_hard_limit>
    <min_guarantee unit='bytes'>67108864</min_guarantee>
  </memtune>
  ...
</domain>

memtune
The optional memtune element provides details regarding the memory tunable parameters for the domain. If this is omitted, it defaults to the OS provided defaults. For QEMU/KVM, the parameters are applied to the QEMU process as a whole. Thus, when counting them, one needs to add up guest RAM, guest video RAM, and some memory overhead of QEMU itself. The last piece is hard to determine so one needs guess and try. For each tunable, it is possible to designate which unit the number is in on input, using the same values as for <memory>. For backwards compatibility, output is always in KiB. unit since 0.9.11
hard_limit
The optional hard_limit element is the maximum memory the guest can use. The units for this value are kibibytes (i.e. blocks of 1024 bytes).
soft_limit
The optional soft_limit element is the memory limit to enforce during memory contention. The units for this value are kibibytes (i.e. blocks of 1024 bytes).
swap_hard_limit
The optional swap_hard_limit element is the maximum memory plus swap the guest can use. The units for this value are kibibytes (i.e. blocks of 1024 bytes). This has to be more than hard_limit value provided.
min_guarantee
The optional min_guarantee element is the guaranteed minimum memory allocation for the guest. The units for this value are kibibytes (i.e. blocks of 1024 bytes). This element is only supported by VMware ESX and OpenVZ drivers.

For cloud, we also have requirement for control mem resource.
For example, assume there are 2 instance(test1, test2) in same host, test1 use flavor set mem same as test2, the priority of test1 is higher than test2, If memory usage nervous, we must ensure that test1 memory usage. Administor can use memtune to configure mem use for vm.

how is works
--------------------
Nova can use libvirt memtune to set mem limits when a new VM is spawned.

Proposed Change
------------------------
This feature need't change API. Each nova flavor can be assigned extra specs which allow to specify resources quota/limits. Blueprint quota-instance-resource has implemented cpu, diskI/O in havana. So we only need implement mem.

Set hard_limit, soft_limit, swap_hard_limit through nova flavor-set with admin credentials.
example:
nova flavor-key m1.low_mem set quota:mem_hard_limit=20000
the max physical mem the vm can used is 20000k

References
-----------------
[1] http://libvirt.org/formatdomain.html#elementsMemoryTuning
[2] https://wiki.openstack.org/wiki/InstanceResourceQuota

Blueprint information

Status:
Started
Approver:
None
Priority:
Undefined
Drafter:
lizheming
Direction:
Needs approval
Assignee:
lizheming
Definition:
Discussion
Series goal:
None
Implementation:
Started
Milestone target:
None
Started by
lizheming

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.