From b2662e7f22f9fad8a4484dd172573c3f4672c031 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 25 Apr 2008 12:07:05 +0000 Subject: [PATCH] IAllocator: simplify node info computation Currently we try to convert the values returned by call_node_info to ints, and if all succeed, we actually do the conversion. Simplify this by doing it in one step. The patch also adds exporting of node memory as 'reserved_memory'. Reviewed-by: imsnah --- lib/cmdlib.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/cmdlib.py b/lib/cmdlib.py index 5abc16fc7..1df5ea512 100644 --- a/lib/cmdlib.py +++ b/lib/cmdlib.py @@ -4861,22 +4861,24 @@ class IAllocator(object): if nname not in node_data or not isinstance(node_data[nname], dict): raise errors.OpExecError("Can't get data for node %s" % nname) remote_info = node_data[nname] - for attr in ['memory_total', 'memory_free', + for attr in ['memory_total', 'memory_free', 'memory_dom0', 'vg_size', 'vg_free']: if attr not in remote_info: raise errors.OpExecError("Node '%s' didn't return attribute '%s'" % (nname, attr)) try: - int(remote_info[attr]) + remote_info[attr] = int(remote_info[attr]) except ValueError, err: raise errors.OpExecError("Node '%s' returned invalid value for '%s':" " %s" % (nname, attr, str(err))) + # compute memory used by instances pnr = { "tags": list(ninfo.GetTags()), - "total_memory": utils.TryConvert(int, remote_info['memory_total']), - "free_memory": utils.TryConvert(int, remote_info['memory_free']), - "total_disk": utils.TryConvert(int, remote_info['vg_size']), - "free_disk": utils.TryConvert(int, remote_info['vg_free']), + "total_memory": remote_info['memory_total'], + "reserved_memory": remote_info['memory_dom0'], + "free_memory": remote_info['memory_free'], + "total_disk": remote_info['vg_size'], + "free_disk": remote_info['vg_free'], "primary_ip": ninfo.primary_ip, "secondary_ip": ninfo.secondary_ip, } -- GitLab