"""
-import simplejson
import ConfigParser
import re
from cStringIO import StringIO
"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.
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.
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)
# 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.
"kernel_path",
"initrd_path",
"hvm_boot_order",
+ "hvm_acpi",
+ "hvm_pae",
+ "hvm_cdrom_image_path",
+ "vnc_bind_address",
]
def _ComputeSecondaryNodes(self):