Commit 1ae17369 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

query: Add support for field description

Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarRené Nussbaumer <>
parent 92ea69bf
......@@ -284,6 +284,10 @@ A field definition is a dictionary with the following entries:
formatting any unknown types the same way as "other", which should be
a string representation in most cases.
``doc`` (string)
Human-readable description. Must start with uppercase character and
must not end with punctuation or contain newlines.
.. TODO: Investigate whether there are fields with floating point
.. numbers
......@@ -1415,12 +1415,14 @@ class QueryFieldDefinition(ConfigObject):
@ivar name: Field name
@ivar title: Human-readable title
@ivar kind: Field type
@ivar doc: Human-readable description
__slots__ = [
......@@ -93,6 +93,7 @@ from ganeti.constants import (QFT_UNKNOWN, QFT_TEXT, QFT_BOOL, QFT_NUMBER,
FIELD_NAME_RE = re.compile(r"^[a-z0-9/._]+$")
TITLE_RE = re.compile(r"^[^\s]+$")
DOC_RE = re.compile(r"^[A-Z].*[^.,?!]$")
#: Verification function for each field type
......@@ -307,6 +308,9 @@ def _PrepareFieldList(fields, aliases):
assert and fdef.title, "Name and title are required"
assert FIELD_NAME_RE.match(
assert TITLE_RE.match(fdef.title)
assert (fdef.doc is None or
(DOC_RE.match(fdef.doc) and len(fdef.doc.splitlines()) == 1 and
fdef.doc.strip() == fdef.doc))
assert callable(fn)
assert not in result, \
"Duplicate field name '%s' found" %
......@@ -360,15 +364,17 @@ def QueryFields(fielddefs, selected):
return objects.QueryFieldsResponse(fields=fdefs).ToDict()
def _MakeField(name, title, kind):
def _MakeField(name, title, kind, doc=None):
"""Wrapper for creating L{objects.QueryFieldDefinition} instances.
@param name: Field name as a regular expression
@param title: Human-readable title
@param kind: Field type
@param doc: Human-readable description
return objects.QueryFieldDefinition(name=name, title=title, kind=kind)
return objects.QueryFieldDefinition(name=name, title=title, kind=kind,
def _GetNodeRole(node, master_name):
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