Add opcode attribute for comments
authorMichael Hanselmann <hansmi@google.com>
Fri, 22 Jul 2011 05:35:44 +0000 (07:35 +0200)
committerMichael Hanselmann <hansmi@google.com>
Fri, 22 Jul 2011 09:03:09 +0000 (11:03 +0200)
This attribute allows programmatic submitters of jobs (e.g. iallocator)
to add a comment to each opcode, describing its purpose. Example:

$ gnt-job info 123
Job ID: 123
  …
  Opcodes:
    OP_INSTANCE_REPLACE_DISKS
      …
      Input fields:
        comment: Replaces disks on inst1.example.com
      …

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>

lib/opcodes.py

index e034546..8d50084 100644 (file)
@@ -154,6 +154,9 @@ _SUMMARY_PREFIX = {
 #: Attribute name for dependencies
 DEPEND_ATTR = "depends"
 
+#: Attribute name for comment
+COMMENT_ATTR = "comment"
+
 
 def _NameToId(name):
   """Convert an opcode class name to an OP_ID.
@@ -448,6 +451,8 @@ class OpCode(BaseOpCode):
     (DEPEND_ATTR, None, _BuildJobDepCheck(True),
      "Job dependencies; if used through ``SubmitManyJobs`` relative (negative)"
      " job IDs can be used"),
+    (COMMENT_ATTR, None, ht.TMaybeString,
+     "Comment describing the purpose of the opcode"),
     ]
 
   def __getstate__(self):