[Kimchi-devel] [PATCH] Fix template default memory in hosts with few memory

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Sun Sep 27 14:57:03 UTC 2015


On Sat, 2015-09-26 at 04:00 -0300, Rodrigo Trujillo wrote:
> This patch changes the template default memory in hosts that have
> less
> than 1024 MB or less than 2048 in non x86 hosts. If this is the case,
> the template memory becomes the host total memory.
> 
> Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
> ---
>  src/kimchi/osinfo.py | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/src/kimchi/osinfo.py b/src/kimchi/osinfo.py
> index 6a6af8c..9445f61 100644
> --- a/src/kimchi/osinfo.py
> +++ b/src/kimchi/osinfo.py
> @@ -94,7 +94,16 @@ def _get_arch():
> 
> 
>  def _get_default_template_mem():
> -    return 1024 if _get_arch() == 'x86' else 2048
> +    if hasattr(psutil, 'virtual_memory'):
> +        mem = psutil.virtual_memory().total >> 10 >> 10
> +    else:
> +        mem = psutil.TOTAL_PHYMEM >> 10 >> 10

Looks good, but here:

> +    if mem < 2048 and _get_arch() != 'x86':
> +        return mem
> +    elif mem < 1024:
> +        return mem
> +    else:
> +        return 1024 if _get_arch() == 'x86' else 2048
> 

I got a little confused with too many values and archs :-D 
What do think about something like the following?

if _get_arch() == 'x86':
    return 1024 if mem > 1024 else mem
else:
    return 2048 if mem > 2048 else mem


> 
>  def _get_tmpl_defaults():




More information about the Kimchi-devel mailing list