4 # Copyright (C) 2006, 2007 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """Transportable objects for Ganeti.
24 This module provides small, mostly data-only objects which are safe to
25 pass to and from external parties.
29 # pylint: disable-msg=E0203,W0201
31 # E0203: Access to member %r before its definition, since we use
32 # objects.py which doesn't explicitely initialise its members
34 # W0201: Attribute '%s' defined outside __init__
39 from cStringIO import StringIO
41 from ganeti import errors
42 from ganeti import constants
45 __all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
46 "OS", "Node", "Cluster", "FillDict"]
48 _TIMESTAMPS = ["ctime", "mtime"]
51 def FillDict(defaults_dict, custom_dict, skip_keys=None):
52 """Basic function to apply settings on top a default dict.
54 @type defaults_dict: dict
55 @param defaults_dict: dictionary holding the default values
56 @type custom_dict: dict
57 @param custom_dict: dictionary holding customized value
59 @param skip_keys: which keys not to fill
61 @return: dict with the 'full' values
64 ret_dict = copy.deepcopy(defaults_dict)
65 ret_dict.update(custom_dict)
75 def UpgradeGroupedParams(target, defaults):
76 """Update all groups for the target parameter.
78 @type target: dict of dicts
79 @param target: {group: {parameter: value}}
81 @param defaults: default parameter values
85 target = {constants.PP_DEFAULT: defaults}
88 target[group] = FillDict(defaults, target[group])
92 class ConfigObject(object):
93 """A generic config object.
95 It has the following properties:
97 - provides somewhat safe recursive unpickling and pickling for its classes
98 - unset attributes which are defined in slots are always returned
99 as None instead of raising an error
101 Classes derived from this must always declare __slots__ (we use many
102 config objects and the memory reduction is useful)
107 def __init__(self, **kwargs):
108 for k, v in kwargs.iteritems():
111 def __getattr__(self, name):
112 if name not in self._all_slots():
113 raise AttributeError("Invalid object attribute %s.%s" %
114 (type(self).__name__, name))
117 def __setstate__(self, state):
118 slots = self._all_slots()
121 setattr(self, name, state[name])
125 """Compute the list of all declared slots for a class.
129 for parent in cls.__mro__:
130 slots.extend(getattr(parent, "__slots__", []))
134 """Convert to a dict holding only standard python types.
136 The generic routine just dumps all of this object's attributes in
137 a dict. It does not work if the class has children who are
138 ConfigObjects themselves (e.g. the nics list in an Instance), in
139 which case the object should subclass the function in order to
140 make sure all objects returned are only standard python types.
144 for name in self._all_slots():
145 value = getattr(self, name, None)
146 if value is not None:
150 __getstate__ = ToDict
153 def FromDict(cls, val):
154 """Create an object from a dictionary.
156 This generic routine takes a dict, instantiates a new instance of
157 the given class, and sets attributes based on the dict content.
159 As for `ToDict`, this does not work if the class has children
160 who are ConfigObjects themselves (e.g. the nics list in an
161 Instance), in which case the object should subclass the function
162 and alter the objects.
165 if not isinstance(val, dict):
166 raise errors.ConfigurationError("Invalid object passed to FromDict:"
167 " expected dict, got %s" % type(val))
168 val_str = dict([(str(k), v) for k, v in val.iteritems()])
169 obj = cls(**val_str) # pylint: disable-msg=W0142
173 def _ContainerToDicts(container):
174 """Convert the elements of a container to standard python types.
176 This method converts a container with elements derived from
177 ConfigData to standard python types. If the container is a dict,
178 we don't touch the keys, only the values.
181 if isinstance(container, dict):
182 ret = dict([(k, v.ToDict()) for k, v in container.iteritems()])
183 elif isinstance(container, (list, tuple, set, frozenset)):
184 ret = [elem.ToDict() for elem in container]
186 raise TypeError("Invalid type %s passed to _ContainerToDicts" %
191 def _ContainerFromDicts(source, c_type, e_type):
192 """Convert a container from standard python types.
194 This method converts a container with standard python types to
195 ConfigData objects. If the container is a dict, we don't touch the
196 keys, only the values.
199 if not isinstance(c_type, type):
200 raise TypeError("Container type %s passed to _ContainerFromDicts is"
201 " not a type" % type(c_type))
203 ret = dict([(k, e_type.FromDict(v)) for k, v in source.iteritems()])
204 elif c_type in (list, tuple, set, frozenset):
205 ret = c_type([e_type.FromDict(elem) for elem in source])
207 raise TypeError("Invalid container type %s passed to"
208 " _ContainerFromDicts" % c_type)
212 """Makes a deep copy of the current object and its children.
215 dict_form = self.ToDict()
216 clone_obj = self.__class__.FromDict(dict_form)
220 """Implement __repr__ for ConfigObjects."""
221 return repr(self.ToDict())
223 def UpgradeConfig(self):
224 """Fill defaults for missing configuration values.
226 This method will be called at configuration load time, and its
227 implementation will be object dependent.
233 class TaggableObject(ConfigObject):
234 """An generic class supporting tags.
238 VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$")
241 def ValidateTag(cls, tag):
242 """Check if a tag is valid.
244 If the tag is invalid, an errors.TagError will be raised. The
245 function has no return value.
248 if not isinstance(tag, basestring):
249 raise errors.TagError("Invalid tag type (not a string)")
250 if len(tag) > constants.MAX_TAG_LEN:
251 raise errors.TagError("Tag too long (>%d characters)" %
252 constants.MAX_TAG_LEN)
254 raise errors.TagError("Tags cannot be empty")
255 if not cls.VALID_TAG_RE.match(tag):
256 raise errors.TagError("Tag contains invalid characters")
259 """Return the tags list.
262 tags = getattr(self, "tags", None)
264 tags = self.tags = set()
267 def AddTag(self, tag):
271 self.ValidateTag(tag)
272 tags = self.GetTags()
273 if len(tags) >= constants.MAX_TAGS_PER_OBJ:
274 raise errors.TagError("Too many tags")
275 self.GetTags().add(tag)
277 def RemoveTag(self, tag):
281 self.ValidateTag(tag)
282 tags = self.GetTags()
286 raise errors.TagError("Tag not found")
289 """Taggable-object-specific conversion to standard python types.
291 This replaces the tags set with a list.
294 bo = super(TaggableObject, self).ToDict()
296 tags = bo.get("tags", None)
297 if isinstance(tags, set):
298 bo["tags"] = list(tags)
302 def FromDict(cls, val):
303 """Custom function for instances.
306 obj = super(TaggableObject, cls).FromDict(val)
307 if hasattr(obj, "tags") and isinstance(obj.tags, list):
308 obj.tags = set(obj.tags)
312 class ConfigData(ConfigObject):
313 """Top-level config object."""
314 __slots__ = (["version", "cluster", "nodes", "instances", "serial_no"] +
318 """Custom function for top-level config data.
320 This just replaces the list of instances, nodes and the cluster
321 with standard python types.
324 mydict = super(ConfigData, self).ToDict()
325 mydict["cluster"] = mydict["cluster"].ToDict()
326 for key in "nodes", "instances":
327 mydict[key] = self._ContainerToDicts(mydict[key])
332 def FromDict(cls, val):
333 """Custom function for top-level config data
336 obj = super(ConfigData, cls).FromDict(val)
337 obj.cluster = Cluster.FromDict(obj.cluster)
338 obj.nodes = cls._ContainerFromDicts(obj.nodes, dict, Node)
339 obj.instances = cls._ContainerFromDicts(obj.instances, dict, Instance)
342 def UpgradeConfig(self):
343 """Fill defaults for missing configuration values.
346 self.cluster.UpgradeConfig()
347 for node in self.nodes.values():
349 for instance in self.instances.values():
350 instance.UpgradeConfig()
353 class NIC(ConfigObject):
354 """Config object representing a network card."""
355 __slots__ = ["mac", "ip", "bridge", "nicparams"]
358 def CheckParameterSyntax(cls, nicparams):
359 """Check the given parameters for validity.
361 @type nicparams: dict
362 @param nicparams: dictionary with parameter names/value
363 @raise errors.ConfigurationError: when a parameter is not valid
366 if nicparams[constants.NIC_MODE] not in constants.NIC_VALID_MODES:
367 err = "Invalid nic mode: %s" % nicparams[constants.NIC_MODE]
368 raise errors.ConfigurationError(err)
370 if (nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED and
371 not nicparams[constants.NIC_LINK]):
372 err = "Missing bridged nic link"
373 raise errors.ConfigurationError(err)
375 def UpgradeConfig(self):
376 """Fill defaults for missing configuration values.
379 if self.nicparams is None:
381 if self.bridge is not None:
382 self.nicparams[constants.NIC_MODE] = constants.NIC_MODE_BRIDGED
383 self.nicparams[constants.NIC_LINK] = self.bridge
384 # bridge is no longer used it 2.1. The slot is left there to support
385 # upgrading, but will be removed in 2.2
386 if self.bridge is not None:
390 class Disk(ConfigObject):
391 """Config object representing a block device."""
392 __slots__ = ["dev_type", "logical_id", "physical_id",
393 "children", "iv_name", "size", "mode"]
395 def CreateOnSecondary(self):
396 """Test if this device needs to be created on a secondary node."""
397 return self.dev_type in (constants.LD_DRBD8, constants.LD_LV)
399 def AssembleOnSecondary(self):
400 """Test if this device needs to be assembled on a secondary node."""
401 return self.dev_type in (constants.LD_DRBD8, constants.LD_LV)
403 def OpenOnSecondary(self):
404 """Test if this device needs to be opened on a secondary node."""
405 return self.dev_type in (constants.LD_LV,)
407 def StaticDevPath(self):
408 """Return the device path if this device type has a static one.
410 Some devices (LVM for example) live always at the same /dev/ path,
411 irrespective of their status. For such devices, we return this
412 path, for others we return None.
415 if self.dev_type == constants.LD_LV:
416 return "/dev/%s/%s" % (self.logical_id[0], self.logical_id[1])
419 def ChildrenNeeded(self):
420 """Compute the needed number of children for activation.
422 This method will return either -1 (all children) or a positive
423 number denoting the minimum number of children needed for
424 activation (only mirrored devices will usually return >=0).
426 Currently, only DRBD8 supports diskless activation (therefore we
427 return 0), for all other we keep the previous semantics and return
431 if self.dev_type == constants.LD_DRBD8:
435 def GetNodes(self, node):
436 """This function returns the nodes this device lives on.
438 Given the node on which the parent of the device lives on (or, in
439 case of a top-level device, the primary node of the devices'
440 instance), this function will return a list of nodes on which this
441 devices needs to (or can) be assembled.
444 if self.dev_type in [constants.LD_LV, constants.LD_FILE]:
446 elif self.dev_type in constants.LDS_DRBD:
447 result = [self.logical_id[0], self.logical_id[1]]
448 if node not in result:
449 raise errors.ConfigurationError("DRBD device passed unknown node")
451 raise errors.ProgrammerError("Unhandled device type %s" % self.dev_type)
454 def ComputeNodeTree(self, parent_node):
455 """Compute the node/disk tree for this disk and its children.
457 This method, given the node on which the parent disk lives, will
458 return the list of all (node, disk) pairs which describe the disk
459 tree in the most compact way. For example, a drbd/lvm stack
460 will be returned as (primary_node, drbd) and (secondary_node, drbd)
461 which represents all the top-level devices on the nodes.
464 my_nodes = self.GetNodes(parent_node)
465 result = [(node, self) for node in my_nodes]
466 if not self.children:
469 for node in my_nodes:
470 for child in self.children:
471 child_result = child.ComputeNodeTree(node)
472 if len(child_result) == 1:
473 # child (and all its descendants) is simple, doesn't split
474 # over multiple hosts, so we don't need to describe it, our
475 # own entry for this node describes it completely
478 # check if child nodes differ from my nodes; note that
479 # subdisk can differ from the child itself, and be instead
480 # one of its descendants
481 for subnode, subdisk in child_result:
482 if subnode not in my_nodes:
483 result.append((subnode, subdisk))
484 # otherwise child is under our own node, so we ignore this
485 # entry (but probably the other results in the list will
489 def RecordGrow(self, amount):
490 """Update the size of this disk after growth.
492 This method recurses over the disks's children and updates their
493 size correspondigly. The method needs to be kept in sync with the
494 actual algorithms from bdev.
497 if self.dev_type == constants.LD_LV:
499 elif self.dev_type == constants.LD_DRBD8:
501 self.children[0].RecordGrow(amount)
504 raise errors.ProgrammerError("Disk.RecordGrow called for unsupported"
505 " disk type %s" % self.dev_type)
508 """Sets recursively the size to zero for the disk and its children.
512 for child in self.children:
516 def SetPhysicalID(self, target_node, nodes_ip):
517 """Convert the logical ID to the physical ID.
519 This is used only for drbd, which needs ip/port configuration.
521 The routine descends down and updates its children also, because
522 this helps when the only the top device is passed to the remote
526 - target_node: the node we wish to configure for
527 - nodes_ip: a mapping of node name to ip
529 The target_node must exist in in nodes_ip, and must be one of the
530 nodes in the logical ID for each of the DRBD devices encountered
535 for child in self.children:
536 child.SetPhysicalID(target_node, nodes_ip)
538 if self.logical_id is None and self.physical_id is not None:
540 if self.dev_type in constants.LDS_DRBD:
541 pnode, snode, port, pminor, sminor, secret = self.logical_id
542 if target_node not in (pnode, snode):
543 raise errors.ConfigurationError("DRBD device not knowing node %s" %
545 pnode_ip = nodes_ip.get(pnode, None)
546 snode_ip = nodes_ip.get(snode, None)
547 if pnode_ip is None or snode_ip is None:
548 raise errors.ConfigurationError("Can't find primary or secondary node"
549 " for %s" % str(self))
550 p_data = (pnode_ip, port)
551 s_data = (snode_ip, port)
552 if pnode == target_node:
553 self.physical_id = p_data + s_data + (pminor, secret)
554 else: # it must be secondary, we tested above
555 self.physical_id = s_data + p_data + (sminor, secret)
557 self.physical_id = self.logical_id
561 """Disk-specific conversion to standard python types.
563 This replaces the children lists of objects with lists of
564 standard python types.
567 bo = super(Disk, self).ToDict()
569 for attr in ("children",):
570 alist = bo.get(attr, None)
572 bo[attr] = self._ContainerToDicts(alist)
576 def FromDict(cls, val):
577 """Custom function for Disks
580 obj = super(Disk, cls).FromDict(val)
582 obj.children = cls._ContainerFromDicts(obj.children, list, Disk)
583 if obj.logical_id and isinstance(obj.logical_id, list):
584 obj.logical_id = tuple(obj.logical_id)
585 if obj.physical_id and isinstance(obj.physical_id, list):
586 obj.physical_id = tuple(obj.physical_id)
587 if obj.dev_type in constants.LDS_DRBD:
588 # we need a tuple of length six here
589 if len(obj.logical_id) < 6:
590 obj.logical_id += (None,) * (6 - len(obj.logical_id))
594 """Custom str() formatter for disks.
597 if self.dev_type == constants.LD_LV:
598 val = "<LogicalVolume(/dev/%s/%s" % self.logical_id
599 elif self.dev_type in constants.LDS_DRBD:
600 node_a, node_b, port, minor_a, minor_b = self.logical_id[:5]
602 if self.physical_id is None:
605 phy = ("configured as %s:%s %s:%s" %
606 (self.physical_id[0], self.physical_id[1],
607 self.physical_id[2], self.physical_id[3]))
609 val += ("hosts=%s/%d-%s/%d, port=%s, %s, " %
610 (node_a, minor_a, node_b, minor_b, port, phy))
611 if self.children and self.children.count(None) == 0:
612 val += "backend=%s, metadev=%s" % (self.children[0], self.children[1])
614 val += "no local storage"
616 val = ("<Disk(type=%s, logical_id=%s, physical_id=%s, children=%s" %
617 (self.dev_type, self.logical_id, self.physical_id, self.children))
618 if self.iv_name is None:
619 val += ", not visible"
621 val += ", visible as /dev/%s" % self.iv_name
622 if isinstance(self.size, int):
623 val += ", size=%dm)>" % self.size
625 val += ", size='%s')>" % (self.size,)
629 """Checks that this disk is correctly configured.
633 if self.mode not in constants.DISK_ACCESS_SET:
634 all_errors.append("Disk access mode '%s' is invalid" % (self.mode, ))
637 def UpgradeConfig(self):
638 """Fill defaults for missing configuration values.
642 for child in self.children:
643 child.UpgradeConfig()
644 # add here config upgrade for this disk
647 class Instance(TaggableObject):
648 """Config object representing an instance."""
662 ] + _TIMESTAMPS + _UUID
664 def _ComputeSecondaryNodes(self):
665 """Compute the list of secondary nodes.
667 This is a simple wrapper over _ComputeAllNodes.
670 all_nodes = set(self._ComputeAllNodes())
671 all_nodes.discard(self.primary_node)
672 return tuple(all_nodes)
674 secondary_nodes = property(_ComputeSecondaryNodes, None, None,
675 "List of secondary nodes")
677 def _ComputeAllNodes(self):
678 """Compute the list of all nodes.
680 Since the data is already there (in the drbd disks), keeping it as
681 a separate normal attribute is redundant and if not properly
682 synchronised can cause problems. Thus it's better to compute it
686 def _Helper(nodes, device):
687 """Recursively computes nodes given a top device."""
688 if device.dev_type in constants.LDS_DRBD:
689 nodea, nodeb = device.logical_id[:2]
693 for child in device.children:
694 _Helper(nodes, child)
697 all_nodes.add(self.primary_node)
698 for device in self.disks:
699 _Helper(all_nodes, device)
700 return tuple(all_nodes)
702 all_nodes = property(_ComputeAllNodes, None, None,
703 "List of all nodes of the instance")
705 def MapLVsByNode(self, lvmap=None, devs=None, node=None):
706 """Provide a mapping of nodes to LVs this instance owns.
708 This function figures out what logical volumes should belong on
709 which nodes, recursing through a device tree.
711 @param lvmap: optional dictionary to receive the
712 'node' : ['lv', ...] data.
714 @return: None if lvmap arg is given, otherwise, a dictionary
715 of the form { 'nodename' : ['volume1', 'volume2', ...], ... }
719 node = self.primary_node
722 lvmap = { node : [] }
725 if not node in lvmap:
733 if dev.dev_type == constants.LD_LV:
734 lvmap[node].append(dev.logical_id[1])
736 elif dev.dev_type in constants.LDS_DRBD:
738 self.MapLVsByNode(lvmap, dev.children, dev.logical_id[0])
739 self.MapLVsByNode(lvmap, dev.children, dev.logical_id[1])
742 self.MapLVsByNode(lvmap, dev.children, node)
746 def FindDisk(self, idx):
747 """Find a disk given having a specified index.
749 This is just a wrapper that does validation of the index.
752 @param idx: the disk index
754 @return: the corresponding disk
755 @raise errors.OpPrereqError: when the given index is not valid
760 return self.disks[idx]
761 except (TypeError, ValueError), err:
762 raise errors.OpPrereqError("Invalid disk index: '%s'" % str(err),
765 raise errors.OpPrereqError("Invalid disk index: %d (instace has disks"
766 " 0 to %d" % (idx, len(self.disks)),
770 """Instance-specific conversion to standard python types.
772 This replaces the children lists of objects with lists of standard
776 bo = super(Instance, self).ToDict()
778 for attr in "nics", "disks":
779 alist = bo.get(attr, None)
781 nlist = self._ContainerToDicts(alist)
788 def FromDict(cls, val):
789 """Custom function for instances.
792 obj = super(Instance, cls).FromDict(val)
793 obj.nics = cls._ContainerFromDicts(obj.nics, list, NIC)
794 obj.disks = cls._ContainerFromDicts(obj.disks, list, Disk)
797 def UpgradeConfig(self):
798 """Fill defaults for missing configuration values.
801 for nic in self.nics:
803 for disk in self.disks:
806 for key in constants.HVC_GLOBALS:
808 del self.hvparams[key]
813 class OS(ConfigObject):
814 """Config object representing an operating system."""
823 "supported_variants",
827 class Node(TaggableObject):
828 """Config object representing a node."""
837 ] + _TIMESTAMPS + _UUID
840 class Cluster(TaggableObject):
841 """Config object representing the cluster."""
850 "default_hypervisor",
856 "enabled_hypervisors",
860 "candidate_pool_size",
863 ] + _TIMESTAMPS + _UUID
865 def UpgradeConfig(self):
866 """Fill defaults for missing configuration values.
869 # pylint: disable-msg=E0203
870 # because these are "defined" via slots, not manually
871 if self.hvparams is None:
872 self.hvparams = constants.HVC_DEFAULTS
874 for hypervisor in self.hvparams:
875 self.hvparams[hypervisor] = FillDict(
876 constants.HVC_DEFAULTS[hypervisor], self.hvparams[hypervisor])
878 self.beparams = UpgradeGroupedParams(self.beparams,
879 constants.BEC_DEFAULTS)
880 migrate_default_bridge = not self.nicparams
881 self.nicparams = UpgradeGroupedParams(self.nicparams,
882 constants.NICC_DEFAULTS)
883 if migrate_default_bridge:
884 self.nicparams[constants.PP_DEFAULT][constants.NIC_LINK] = \
887 if self.modify_etc_hosts is None:
888 self.modify_etc_hosts = True
890 if self.modify_ssh_setup is None:
891 self.modify_ssh_setup = True
893 # default_bridge is no longer used it 2.1. The slot is left there to
894 # support auto-upgrading, but will be removed in 2.2
895 if self.default_bridge is not None:
896 self.default_bridge = None
898 # default_hypervisor is just the first enabled one in 2.1
899 if self.default_hypervisor is not None:
900 self.enabled_hypervisors = ([self.default_hypervisor] +
901 [hvname for hvname in self.enabled_hypervisors
902 if hvname != self.default_hypervisor])
903 self.default_hypervisor = None
906 """Custom function for cluster.
909 mydict = super(Cluster, self).ToDict()
910 mydict["tcpudp_port_pool"] = list(self.tcpudp_port_pool)
914 def FromDict(cls, val):
915 """Custom function for cluster.
918 obj = super(Cluster, cls).FromDict(val)
919 if not isinstance(obj.tcpudp_port_pool, set):
920 obj.tcpudp_port_pool = set(obj.tcpudp_port_pool)
923 def FillHV(self, instance, skip_globals=False):
924 """Fill an instance's hvparams dict.
926 @type instance: L{objects.Instance}
927 @param instance: the instance parameter to fill
928 @type skip_globals: boolean
929 @param skip_globals: if True, the global hypervisor parameters will
932 @return: a copy of the instance's hvparams with missing keys filled from
937 skip_keys = constants.HVC_GLOBALS
940 return FillDict(self.hvparams.get(instance.hypervisor, {}),
941 instance.hvparams, skip_keys=skip_keys)
943 def FillBE(self, instance):
944 """Fill an instance's beparams dict.
946 @type instance: L{objects.Instance}
947 @param instance: the instance parameter to fill
949 @return: a copy of the instance's beparams with missing keys filled from
953 return FillDict(self.beparams.get(constants.PP_DEFAULT, {}),
957 class BlockDevStatus(ConfigObject):
958 """Config object representing the status of a block device."""
970 class ConfdRequest(ConfigObject):
971 """Object holding a confd request.
973 @ivar protocol: confd protocol version
974 @ivar type: confd query type
975 @ivar query: query request
976 @ivar rsalt: requested reply salt
987 class ConfdReply(ConfigObject):
988 """Object holding a confd reply.
990 @ivar protocol: confd protocol version
991 @ivar status: reply status code (ok, error)
992 @ivar answer: confd query reply
993 @ivar serial: configuration serial number
1004 class SerializableConfigParser(ConfigParser.SafeConfigParser):
1005 """Simple wrapper over ConfigParse that allows serialization.
1007 This class is basically ConfigParser.SafeConfigParser with two
1008 additional methods that allow it to serialize/unserialize to/from a
1013 """Dump this instance and return the string representation."""
1016 return buf.getvalue()
1020 """Load data from a string."""
1021 buf = StringIO(data)
1022 cfp = SerializableConfigParser()