Add method to update a disk object size
[ganeti-local] / lib / objects.py
index 74c0c7e..424c198 100644 (file)
@@ -27,7 +27,6 @@ pass to and from external parties.
 """
 
 
-import simplejson
 import ConfigParser
 import re
 from cStringIO import StringIO
@@ -40,14 +39,6 @@ __all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
            "OS", "Node", "Cluster"]
 
 
-# Check whether the simplejson module supports indentation
-_JSON_INDENT = 2
-try:
-  simplejson.dumps(1, indent=_JSON_INDENT)
-except TypeError:
-  _JSON_INDENT = None
-
-
 class ConfigObject(object):
   """A generic config object.
 
@@ -90,34 +81,6 @@ class ConfigObject(object):
       if name in self.__slots__:
         setattr(self, name, state[name])
 
-  def Dump(self, fobj):
-    """Dump to a file object.
-
-    """
-    data = self.ToDict()
-    if _JSON_INDENT is None:
-      simplejson.dump(data, fobj)
-    else:
-      simplejson.dump(data, fobj, indent=_JSON_INDENT)
-
-  @classmethod
-  def Load(cls, fobj):
-    """Load data from the given stream.
-
-    """
-    return cls.FromDict(simplejson.load(fobj))
-
-  def Dumps(self):
-    """Dump and return the string representation."""
-    buf = StringIO()
-    self.Dump(buf)
-    return buf.getvalue()
-
-  @classmethod
-  def Loads(cls, data):
-    """Load data from a string."""
-    return cls.Load(StringIO(data))
-
   def ToDict(self):
     """Convert to a dict holding only standard python types.
 
@@ -379,12 +342,9 @@ class Disk(ConfigObject):
 
     This method, given the node on which the parent disk lives, will
     return the list of all (node, disk) pairs which describe the disk
-    tree in the most compact way. For example, a md/drbd/lvm stack
-    will be returned as (primary_node, md) and (secondary_node, drbd)
-    which represents all the top-level devices on the nodes. This
-    means that on the primary node we need to activate the the md (and
-    recursively all its children) and on the secondary node we need to
-    activate the drbd device (and its children, the two lvm volumes).
+    tree in the most compact way. For example, a drbd/lvm stack
+    will be returned as (primary_node, drbd) and (secondary_node, drbd)
+    which represents all the top-level devices on the nodes.
 
     """
     my_nodes = self.GetNodes(parent_node)
@@ -412,6 +372,24 @@ class Disk(ConfigObject):
             # be different)
     return result
 
+  def RecordGrow(self, amount):
+    """Update the size of this disk after growth.
+
+    This method recurses over the disks's children and updates their
+    size correspondigly. The method needs to be kept in sync with the
+    actual algorithms from bdev.
+
+    """
+    if self.dev_type == constants.LD_LV:
+      self.size += amount
+    elif self.dev_type == constants.LD_DRBD8:
+      if self.children:
+        self.children[0].RecordGrow(amount)
+      self.size += amount
+    else:
+      raise errors.ProgrammerError("Disk.RecordGrow called for unsupported"
+                                   " disk type %s" % self.dev_type)
+
   def ToDict(self):
     """Disk-specific conversion to standard python types.
 
@@ -495,6 +473,10 @@ class Instance(TaggableObject):
     "kernel_path",
     "initrd_path",
     "hvm_boot_order",
+    "hvm_acpi",
+    "hvm_pae",
+    "hvm_cdrom_image_path",
+    "vnc_bind_address",
     ]
 
   def _ComputeSecondaryNodes(self):