Querying node groups: LU/Opcode
[ganeti-local] / lib / objects.py
index bf1b6bd..597469f 100644 (file)
@@ -939,15 +939,34 @@ class Node(TaggableObject):
     "master_candidate",
     "offline",
     "drained",
-    "nodegroup",
+    "group",
+    "master_capable",
+    "vm_capable",
+    "ndparams",
     ] + _TIMESTAMPS + _UUID
 
+  def UpgradeConfig(self):
+    """Fill defaults for missing configuration values.
+
+    """
+    # pylint: disable-msg=E0203
+    # because these are "defined" via slots, not manually
+    if self.master_capable is None:
+      self.master_capable = True
+
+    if self.vm_capable is None:
+      self.vm_capable = True
+
+    if self.ndparams is None:
+      self.ndparams = {}
+
 
 class NodeGroup(ConfigObject):
   """Config object representing a node group."""
   __slots__ = [
     "name",
     "members",
+    "ndparams",
     ] + _TIMESTAMPS + _UUID
 
   def ToDict(self):
@@ -972,6 +991,35 @@ class NodeGroup(ConfigObject):
     obj.members = []
     return obj
 
+  def UpgradeConfig(self):
+    """Fill defaults for missing configuration values.
+
+    """
+    if self.ndparams is None:
+      self.ndparams = {}
+
+  def FillND(self, node):
+    """Return filled out ndparams for L{object.Node}
+
+    @type node: L{objects.Node}
+    @param node: A Node object to fill
+    @return a copy of the node's ndparams with defaults filled
+
+    """
+    return self.SimpleFillND(node.ndparams)
+
+  def SimpleFillND(self, ndparams):
+    """Fill a given ndparams dict with defaults.
+
+    @type ndparams: dict
+    @param ndparams: the dict to fill
+    @rtype: dict
+    @return: a copy of the passed in ndparams with missing keys filled
+        from the cluster defaults
+
+    """
+    return FillDict(self.ndparams, ndparams)
+
 
 class Cluster(TaggableObject):
   """Config object representing the cluster."""
@@ -997,6 +1045,7 @@ class Cluster(TaggableObject):
     "beparams",
     "osparams",
     "nicparams",
+    "ndparams",
     "candidate_pool_size",
     "modify_etc_hosts",
     "modify_ssh_setup",
@@ -1029,6 +1078,9 @@ class Cluster(TaggableObject):
     if self.osparams is None:
       self.osparams = {}
 
+    if self.ndparams is None:
+      self.ndparams = constants.NDC_DEFAULTS
+
     self.beparams = UpgradeGroupedParams(self.beparams,
                                          constants.BEC_DEFAULTS)
     migrate_default_bridge = not self.nicparams
@@ -1222,6 +1274,30 @@ class Cluster(TaggableObject):
     # specified params
     return FillDict(result, os_params)
 
+  def FillND(self, node, nodegroup):
+    """Return filled out ndparams for L{objects.NodeGroup} and L{object.Node}
+
+    @type node: L{objects.Node}
+    @param node: A Node object to fill
+    @type nodegroup: L{objects.NodeGroup}
+    @param nodegroup: A Node object to fill
+    @return a copy of the node's ndparams with defaults filled
+
+    """
+    return self.SimpleFillND(nodegroup.FillND(node))
+
+  def SimpleFillND(self, ndparams):
+    """Fill a given ndparams dict with defaults.
+
+    @type ndparams: dict
+    @param ndparams: the dict to fill
+    @rtype: dict
+    @return: a copy of the passed in ndparams with missing keys filled
+        from the cluster defaults
+
+    """
+    return FillDict(self.ndparams, ndparams)
+
 
 class BlockDevStatus(ConfigObject):
   """Config object representing the status of a block device."""
@@ -1258,6 +1334,7 @@ class ImportExportOptions(ConfigObject):
   @ivar ca_pem: Remote peer CA in PEM format (None for cluster certificate)
   @ivar compress: Compression method (one of L{constants.IEC_ALL})
   @ivar magic: Used to ensure the connection goes to the right disk
+  @ivar ipv6: Whether to use IPv6
 
   """
   __slots__ = [
@@ -1265,6 +1342,7 @@ class ImportExportOptions(ConfigObject):
     "ca_pem",
     "compress",
     "magic",
+    "ipv6",
     ]
 
 
@@ -1302,6 +1380,21 @@ class ConfdReply(ConfigObject):
     ]
 
 
+class QueryFieldDefinition(ConfigObject):
+  """Object holding a query field definition.
+
+  @ivar name: Field name as a regular expression
+  @ivar title: Human-readable title
+  @ivar kind: Field type
+
+  """
+  __slots__ = [
+    "name",
+    "title",
+    "kind",
+    ]
+
+
 class SerializableConfigParser(ConfigParser.SafeConfigParser):
   """Simple wrapper over ConfigParse that allows serialization.