This checks that the fields required are valid output fields.
"""
- self.dynamic_fields = frozenset(["dtotal", "dfree",
- "mtotal", "mnode", "mfree",
- "bootid"])
+ self.dynamic_fields = frozenset([
+ "dtotal", "dfree",
+ "mtotal", "mnode", "mfree",
+ "bootid",
+ "ctotal",
+ ])
_CheckOutputFields(static=["name", "pinst_cnt", "sinst_cnt",
"pinst_list", "sinst_list",
"mfree": utils.TryConvert(int, nodeinfo['memory_free']),
"dtotal": utils.TryConvert(int, nodeinfo['vg_size']),
"dfree": utils.TryConvert(int, nodeinfo['vg_free']),
+ "ctotal": utils.TryConvert(int, nodeinfo['cpu_total']),
"bootid": nodeinfo['bootid'],
}
else:
import time
import os
+import re
from cStringIO import StringIO
from ganeti import utils
result['memory_total'] = int(val)
elif key == 'free_memory':
result['memory_free'] = int(val)
+ elif key == 'nr_cpus':
+ result['cpu_total'] = int(val)
dom0_info = self.GetInstanceInfo("Domain-0")
if dom0_info is not None:
result['memory_dom0'] = dom0_info[2]
sum_free += int(val.split()[0])/1024
elif key == 'Active':
result['memory_dom0'] = int(val.split()[0])/1024
-
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
@staticmethod
output = SubmitOpCode(op)
if not opts.no_headers:
- headers = {"name": "Node", "pinst_cnt": "Pinst", "sinst_cnt": "Sinst",
- "pinst_list": "PriInstances", "sinst_list": "SecInstances",
- "pip": "PrimaryIP", "sip": "SecondaryIP",
- "dtotal": "DTotal", "dfree": "DFree",
- "mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree",
- "bootid": "BootID"}
+ headers = {
+ "name": "Node", "pinst_cnt": "Pinst", "sinst_cnt": "Sinst",
+ "pinst_list": "PriInstances", "sinst_list": "SecInstances",
+ "pip": "PrimaryIP", "sip": "SecondaryIP",
+ "dtotal": "DTotal", "dfree": "DFree",
+ "mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree",
+ "bootid": "BootID",
+ "ctotal": "CTotal",
+ }
else:
headers = None
numfields = ["dtotal", "dfree",
"mtotal", "mnode", "mfree",
- "pinst_cnt", "sinst_cnt"]
+ "pinst_cnt", "sinst_cnt",
+ "ctotal"]
# change raw values to nicer strings
for row in output:
"", "Lists the nodes in the cluster. The available fields"
" are (see the man page for details): name, pinst_cnt, pinst_list,"
" 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."),
'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT],
"<node_name>", "Removes a node from the cluster"),