Commit e8a4c138 authored by Iustin Pop's avatar Iustin Pop

Add node cpu count to gnt-node list

This patch adds the backend and frontend changes needed for being able
to list the cpu count.

Reviewed-by: ultrotter
parent 9ff994da
...@@ -1492,9 +1492,12 @@ class LUQueryNodes(NoHooksLU): ...@@ -1492,9 +1492,12 @@ class LUQueryNodes(NoHooksLU):
This checks that the fields required are valid output fields. This checks that the fields required are valid output fields.
""" """
self.dynamic_fields = frozenset(["dtotal", "dfree", self.dynamic_fields = frozenset([
"mtotal", "mnode", "mfree", "dtotal", "dfree",
"bootid"]) "mtotal", "mnode", "mfree",
"bootid",
"ctotal",
])
_CheckOutputFields(static=["name", "pinst_cnt", "sinst_cnt", _CheckOutputFields(static=["name", "pinst_cnt", "sinst_cnt",
"pinst_list", "sinst_list", "pinst_list", "sinst_list",
...@@ -1525,6 +1528,7 @@ class LUQueryNodes(NoHooksLU): ...@@ -1525,6 +1528,7 @@ class LUQueryNodes(NoHooksLU):
"mfree": utils.TryConvert(int, nodeinfo['memory_free']), "mfree": utils.TryConvert(int, nodeinfo['memory_free']),
"dtotal": utils.TryConvert(int, nodeinfo['vg_size']), "dtotal": utils.TryConvert(int, nodeinfo['vg_size']),
"dfree": utils.TryConvert(int, nodeinfo['vg_free']), "dfree": utils.TryConvert(int, nodeinfo['vg_free']),
"ctotal": utils.TryConvert(int, nodeinfo['cpu_total']),
"bootid": nodeinfo['bootid'], "bootid": nodeinfo['bootid'],
} }
else: else:
......
...@@ -25,7 +25,7 @@ from ganeti import _autoconf ...@@ -25,7 +25,7 @@ from ganeti import _autoconf
# various versions # various versions
CONFIG_VERSION = 3 CONFIG_VERSION = 3
PROTOCOL_VERSION = 11 PROTOCOL_VERSION = 12
RELEASE_VERSION = _autoconf.PACKAGE_VERSION RELEASE_VERSION = _autoconf.PACKAGE_VERSION
OS_API_VERSION = 5 OS_API_VERSION = 5
EXPORT_VERSION = 0 EXPORT_VERSION = 0
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
import os import os
import os.path import os.path
import re
from ganeti import utils from ganeti import utils
from ganeti import constants from ganeti import constants
...@@ -186,8 +187,20 @@ class FakeHypervisor(BaseHypervisor.BaseHypervisor): ...@@ -186,8 +187,20 @@ class FakeHypervisor(BaseHypervisor.BaseHypervisor):
sum_free += int(val.split()[0])/1024 sum_free += int(val.split()[0])/1024
elif key == 'Active': elif key == 'Active':
result['memory_dom0'] = int(val.split()[0])/1024 result['memory_dom0'] = int(val.split()[0])/1024
result['memory_free'] = sum_free result['memory_free'] = sum_free
cpu_total = 0
try:
fh = open("/proc/cpuinfo")
try:
cpu_total = len(re.findall("(?m)^processor\s*:\s*[0-9]+\s*$",
fh.read()))
finally:
fh.close()
except EnvironmentError, err:
raise HypervisorError("Failed to list node info: %s" % err)
result['cpu_total'] = cpu_total
return result return result
@staticmethod @staticmethod
......
...@@ -199,6 +199,8 @@ class XenHypervisor(BaseHypervisor.BaseHypervisor): ...@@ -199,6 +199,8 @@ class XenHypervisor(BaseHypervisor.BaseHypervisor):
result['memory_total'] = int(val) result['memory_total'] = int(val)
elif key == 'free_memory': elif key == 'free_memory':
result['memory_free'] = int(val) result['memory_free'] = int(val)
elif key == 'nr_cpus':
result['cpu_total'] = int(val)
dom0_info = self.GetInstanceInfo("Domain-0") dom0_info = self.GetInstanceInfo("Domain-0")
if dom0_info is not None: if dom0_info is not None:
result['memory_dom0'] = dom0_info[2] result['memory_dom0'] = dom0_info[2]
......
...@@ -56,12 +56,15 @@ def ListNodes(opts, args): ...@@ -56,12 +56,15 @@ def ListNodes(opts, args):
output = SubmitOpCode(op) output = SubmitOpCode(op)
if not opts.no_headers: if not opts.no_headers:
headers = {"name": "Node", "pinst_cnt": "Pinst", "sinst_cnt": "Sinst", headers = {
"pinst_list": "PriInstances", "sinst_list": "SecInstances", "name": "Node", "pinst_cnt": "Pinst", "sinst_cnt": "Sinst",
"pip": "PrimaryIP", "sip": "SecondaryIP", "pinst_list": "PriInstances", "sinst_list": "SecInstances",
"dtotal": "DTotal", "dfree": "DFree", "pip": "PrimaryIP", "sip": "SecondaryIP",
"mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree", "dtotal": "DTotal", "dfree": "DFree",
"bootid": "BootID"} "mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree",
"bootid": "BootID",
"ctotal": "CTotal",
}
else: else:
headers = None headers = None
...@@ -72,7 +75,8 @@ def ListNodes(opts, args): ...@@ -72,7 +75,8 @@ def ListNodes(opts, args):
numfields = ["dtotal", "dfree", numfields = ["dtotal", "dfree",
"mtotal", "mnode", "mfree", "mtotal", "mnode", "mfree",
"pinst_cnt", "sinst_cnt"] "pinst_cnt", "sinst_cnt",
"ctotal"]
# change raw values to nicer strings # change raw values to nicer strings
for row in output: for row in output:
...@@ -309,7 +313,8 @@ commands = { ...@@ -309,7 +313,8 @@ commands = {
"", "Lists the nodes in the cluster. The available fields" "", "Lists the nodes in the cluster. The available fields"
" are (see the man page for details): name, pinst_cnt, pinst_list," " are (see the man page for details): name, pinst_cnt, pinst_list,"
" sinst_cnt, sinst_list, pip, sip, dtotal, dfree, mtotal, mnode," " sinst_cnt, sinst_list, pip, sip, dtotal, dfree, mtotal, mnode,"
" mfree, bootid. The default field list is (in order): name," " mfree, bootid, cpu_count. The default field list is"
" (in order): name,"
" dtotal, dfree, mtotal, mnode, mfree, pinst_cnt, sinst_cnt."), " dtotal, dfree, mtotal, mnode, mfree, pinst_cnt, sinst_cnt."),
'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT], 'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT],
"<node_name>", "Removes a node from the cluster"), "<node_name>", "Removes a node from the cluster"),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment