4 # Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 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=E0203,W0201,R0902
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__
36 # R0902: Allow instances of these objects to have more than 20 attributes
42 from cStringIO import StringIO
44 from ganeti import errors
45 from ganeti import constants
46 from ganeti import netutils
47 from ganeti import utils
49 from socket import AF_INET
52 __all__ = ["ConfigObject", "ConfigData", "NIC", "Disk", "Instance",
53 "OS", "Node", "NodeGroup", "Cluster", "FillDict"]
55 _TIMESTAMPS = ["ctime", "mtime"]
58 # constants used to create InstancePolicy dictionary
59 TISPECS_GROUP_TYPES = {
60 constants.ISPECS_MIN: constants.VTYPE_INT,
61 constants.ISPECS_MAX: constants.VTYPE_INT,
64 TISPECS_CLUSTER_TYPES = {
65 constants.ISPECS_MIN: constants.VTYPE_INT,
66 constants.ISPECS_MAX: constants.VTYPE_INT,
67 constants.ISPECS_STD: constants.VTYPE_INT,
71 def FillDict(defaults_dict, custom_dict, skip_keys=None):
72 """Basic function to apply settings on top a default dict.
74 @type defaults_dict: dict
75 @param defaults_dict: dictionary holding the default values
76 @type custom_dict: dict
77 @param custom_dict: dictionary holding customized value
79 @param skip_keys: which keys not to fill
81 @return: dict with the 'full' values
84 ret_dict = copy.deepcopy(defaults_dict)
85 ret_dict.update(custom_dict)
95 def FillIPolicy(default_ipolicy, custom_ipolicy, skip_keys=None):
96 """Fills an instance policy with defaults.
99 assert frozenset(default_ipolicy.keys()) == constants.IPOLICY_ALL_KEYS
101 for key in constants.IPOLICY_ISPECS:
102 ret_dict[key] = FillDict(default_ipolicy[key],
103 custom_ipolicy.get(key, {}),
106 for key in [constants.IPOLICY_DTS]:
107 ret_dict[key] = list(custom_ipolicy.get(key, default_ipolicy[key]))
108 # other items which we know we can directly copy (immutables)
109 for key in constants.IPOLICY_PARAMETERS:
110 ret_dict[key] = custom_ipolicy.get(key, default_ipolicy[key])
115 def UpgradeGroupedParams(target, defaults):
116 """Update all groups for the target parameter.
118 @type target: dict of dicts
119 @param target: {group: {parameter: value}}
121 @param defaults: default parameter values
125 target = {constants.PP_DEFAULT: defaults}
128 target[group] = FillDict(defaults, target[group])
132 def UpgradeBeParams(target):
133 """Update the be parameters dict to the new format.
136 @param target: "be" parameters dict
139 if constants.BE_MEMORY in target:
140 memory = target[constants.BE_MEMORY]
141 target[constants.BE_MAXMEM] = memory
142 target[constants.BE_MINMEM] = memory
143 del target[constants.BE_MEMORY]
146 def UpgradeDiskParams(diskparams):
147 """Upgrade the disk parameters.
149 @type diskparams: dict
150 @param diskparams: disk parameters to upgrade
152 @return: the upgraded disk parameters dit
156 if diskparams is None:
157 result = constants.DISK_DT_DEFAULTS.copy()
159 # Update the disk parameter values for each disk template.
160 # The code iterates over constants.DISK_TEMPLATES because new templates
161 # might have been added.
162 for template in constants.DISK_TEMPLATES:
163 if template not in diskparams:
164 result[template] = constants.DISK_DT_DEFAULTS[template].copy()
166 result[template] = FillDict(constants.DISK_DT_DEFAULTS[template],
167 diskparams[template])
172 def MakeEmptyIPolicy():
173 """Create empty IPolicy dictionary.
177 (constants.ISPECS_MIN, {}),
178 (constants.ISPECS_MAX, {}),
179 (constants.ISPECS_STD, {}),
183 def CreateIPolicyFromOpts(ispecs_mem_size=None,
184 ispecs_cpu_count=None,
185 ispecs_disk_count=None,
186 ispecs_disk_size=None,
187 ispecs_nic_count=None,
188 ipolicy_disk_templates=None,
189 ipolicy_vcpu_ratio=None,
193 """Creation of instance policy based on command line options.
195 @param fill_all: whether for cluster policies we should ensure that
196 all values are filled
200 # prepare ipolicy dict
201 ipolicy_transposed = {
202 constants.ISPEC_MEM_SIZE: ispecs_mem_size,
203 constants.ISPEC_CPU_COUNT: ispecs_cpu_count,
204 constants.ISPEC_DISK_COUNT: ispecs_disk_count,
205 constants.ISPEC_DISK_SIZE: ispecs_disk_size,
206 constants.ISPEC_NIC_COUNT: ispecs_nic_count,
209 # first, check that the values given are correct
211 forced_type = TISPECS_GROUP_TYPES
213 forced_type = TISPECS_CLUSTER_TYPES
215 for specs in ipolicy_transposed.values():
216 utils.ForceDictType(specs, forced_type, allowed_values=allowed_values)
219 ipolicy_out = MakeEmptyIPolicy()
220 for name, specs in ipolicy_transposed.iteritems():
221 assert name in constants.ISPECS_PARAMETERS
222 for key, val in specs.items(): # {min: .. ,max: .., std: ..}
223 ipolicy_out[key][name] = val
225 # no filldict for non-dicts
226 if not group_ipolicy and fill_all:
227 if ipolicy_disk_templates is None:
228 ipolicy_disk_templates = constants.DISK_TEMPLATES
229 if ipolicy_vcpu_ratio is None:
230 ipolicy_vcpu_ratio = \
231 constants.IPOLICY_DEFAULTS[constants.IPOLICY_VCPU_RATIO]
232 if ipolicy_disk_templates is not None:
233 ipolicy_out[constants.IPOLICY_DTS] = list(ipolicy_disk_templates)
234 if ipolicy_vcpu_ratio is not None:
235 ipolicy_out[constants.IPOLICY_VCPU_RATIO] = ipolicy_vcpu_ratio
237 assert not (frozenset(ipolicy_out.keys()) - constants.IPOLICY_ALL_KEYS)
242 class ConfigObject(object):
243 """A generic config object.
245 It has the following properties:
247 - provides somewhat safe recursive unpickling and pickling for its classes
248 - unset attributes which are defined in slots are always returned
249 as None instead of raising an error
251 Classes derived from this must always declare __slots__ (we use many
252 config objects and the memory reduction is useful)
257 def __init__(self, **kwargs):
258 for k, v in kwargs.iteritems():
261 def __getattr__(self, name):
262 if name not in self._all_slots():
263 raise AttributeError("Invalid object attribute %s.%s" %
264 (type(self).__name__, name))
267 def __setstate__(self, state):
268 slots = self._all_slots()
271 setattr(self, name, state[name])
275 """Compute the list of all declared slots for a class.
279 for parent in cls.__mro__:
280 slots.extend(getattr(parent, "__slots__", []))
284 """Convert to a dict holding only standard python types.
286 The generic routine just dumps all of this object's attributes in
287 a dict. It does not work if the class has children who are
288 ConfigObjects themselves (e.g. the nics list in an Instance), in
289 which case the object should subclass the function in order to
290 make sure all objects returned are only standard python types.
294 for name in self._all_slots():
295 value = getattr(self, name, None)
296 if value is not None:
300 __getstate__ = ToDict
303 def FromDict(cls, val):
304 """Create an object from a dictionary.
306 This generic routine takes a dict, instantiates a new instance of
307 the given class, and sets attributes based on the dict content.
309 As for `ToDict`, this does not work if the class has children
310 who are ConfigObjects themselves (e.g. the nics list in an
311 Instance), in which case the object should subclass the function
312 and alter the objects.
315 if not isinstance(val, dict):
316 raise errors.ConfigurationError("Invalid object passed to FromDict:"
317 " expected dict, got %s" % type(val))
318 val_str = dict([(str(k), v) for k, v in val.iteritems()])
319 obj = cls(**val_str) # pylint: disable=W0142
323 def _ContainerToDicts(container):
324 """Convert the elements of a container to standard python types.
326 This method converts a container with elements derived from
327 ConfigData to standard python types. If the container is a dict,
328 we don't touch the keys, only the values.
331 if isinstance(container, dict):
332 ret = dict([(k, v.ToDict()) for k, v in container.iteritems()])
333 elif isinstance(container, (list, tuple, set, frozenset)):
334 ret = [elem.ToDict() for elem in container]
336 raise TypeError("Invalid type %s passed to _ContainerToDicts" %
341 def _ContainerFromDicts(source, c_type, e_type):
342 """Convert a container from standard python types.
344 This method converts a container with standard python types to
345 ConfigData objects. If the container is a dict, we don't touch the
346 keys, only the values.
349 if not isinstance(c_type, type):
350 raise TypeError("Container type %s passed to _ContainerFromDicts is"
351 " not a type" % type(c_type))
355 ret = dict([(k, e_type.FromDict(v)) for k, v in source.iteritems()])
356 elif c_type in (list, tuple, set, frozenset):
357 ret = c_type([e_type.FromDict(elem) for elem in source])
359 raise TypeError("Invalid container type %s passed to"
360 " _ContainerFromDicts" % c_type)
364 """Makes a deep copy of the current object and its children.
367 dict_form = self.ToDict()
368 clone_obj = self.__class__.FromDict(dict_form)
372 """Implement __repr__ for ConfigObjects."""
373 return repr(self.ToDict())
375 def UpgradeConfig(self):
376 """Fill defaults for missing configuration values.
378 This method will be called at configuration load time, and its
379 implementation will be object dependent.
385 class TaggableObject(ConfigObject):
386 """An generic class supporting tags.
390 VALID_TAG_RE = re.compile("^[\w.+*/:@-]+$")
393 def ValidateTag(cls, tag):
394 """Check if a tag is valid.
396 If the tag is invalid, an errors.TagError will be raised. The
397 function has no return value.
400 if not isinstance(tag, basestring):
401 raise errors.TagError("Invalid tag type (not a string)")
402 if len(tag) > constants.MAX_TAG_LEN:
403 raise errors.TagError("Tag too long (>%d characters)" %
404 constants.MAX_TAG_LEN)
406 raise errors.TagError("Tags cannot be empty")
407 if not cls.VALID_TAG_RE.match(tag):
408 raise errors.TagError("Tag contains invalid characters")
411 """Return the tags list.
414 tags = getattr(self, "tags", None)
416 tags = self.tags = set()
419 def AddTag(self, tag):
423 self.ValidateTag(tag)
424 tags = self.GetTags()
425 if len(tags) >= constants.MAX_TAGS_PER_OBJ:
426 raise errors.TagError("Too many tags")
427 self.GetTags().add(tag)
429 def RemoveTag(self, tag):
433 self.ValidateTag(tag)
434 tags = self.GetTags()
438 raise errors.TagError("Tag not found")
441 """Taggable-object-specific conversion to standard python types.
443 This replaces the tags set with a list.
446 bo = super(TaggableObject, self).ToDict()
448 tags = bo.get("tags", None)
449 if isinstance(tags, set):
450 bo["tags"] = list(tags)
454 def FromDict(cls, val):
455 """Custom function for instances.
458 obj = super(TaggableObject, cls).FromDict(val)
459 if hasattr(obj, "tags") and isinstance(obj.tags, list):
460 obj.tags = set(obj.tags)
464 class MasterNetworkParameters(ConfigObject):
465 """Network configuration parameters for the master
467 @ivar name: master name
469 @ivar netmask: master netmask
470 @ivar netdev: master network device
471 @ivar ip_family: master IP family
483 class ConfigData(ConfigObject):
484 """Top-level config object."""
495 """Custom function for top-level config data.
497 This just replaces the list of instances, nodes and the cluster
498 with standard python types.
501 mydict = super(ConfigData, self).ToDict()
502 mydict["cluster"] = mydict["cluster"].ToDict()
503 for key in "nodes", "instances", "nodegroups":
504 mydict[key] = self._ContainerToDicts(mydict[key])
509 def FromDict(cls, val):
510 """Custom function for top-level config data
513 obj = super(ConfigData, cls).FromDict(val)
514 obj.cluster = Cluster.FromDict(obj.cluster)
515 obj.nodes = cls._ContainerFromDicts(obj.nodes, dict, Node)
516 obj.instances = cls._ContainerFromDicts(obj.instances, dict, Instance)
517 obj.nodegroups = cls._ContainerFromDicts(obj.nodegroups, dict, NodeGroup)
520 def HasAnyDiskOfType(self, dev_type):
521 """Check if in there is at disk of the given type in the configuration.
523 @type dev_type: L{constants.LDS_BLOCK}
524 @param dev_type: the type to look for
526 @return: boolean indicating if a disk of the given type was found or not
529 for instance in self.instances.values():
530 for disk in instance.disks:
531 if disk.IsBasedOnDiskType(dev_type):
535 def UpgradeConfig(self):
536 """Fill defaults for missing configuration values.
539 self.cluster.UpgradeConfig()
540 for node in self.nodes.values():
542 for instance in self.instances.values():
543 instance.UpgradeConfig()
544 if self.nodegroups is None:
546 for nodegroup in self.nodegroups.values():
547 nodegroup.UpgradeConfig()
548 if self.cluster.drbd_usermode_helper is None:
549 # To decide if we set an helper let's check if at least one instance has
550 # a DRBD disk. This does not cover all the possible scenarios but it
551 # gives a good approximation.
552 if self.HasAnyDiskOfType(constants.LD_DRBD8):
553 self.cluster.drbd_usermode_helper = constants.DEFAULT_DRBD_HELPER
556 class NIC(ConfigObject):
557 """Config object representing a network card."""
558 __slots__ = ["mac", "ip", "nicparams"]
561 def CheckParameterSyntax(cls, nicparams):
562 """Check the given parameters for validity.
564 @type nicparams: dict
565 @param nicparams: dictionary with parameter names/value
566 @raise errors.ConfigurationError: when a parameter is not valid
569 if (nicparams[constants.NIC_MODE] not in constants.NIC_VALID_MODES and
570 nicparams[constants.NIC_MODE] != constants.VALUE_AUTO):
571 err = "Invalid nic mode: %s" % nicparams[constants.NIC_MODE]
572 raise errors.ConfigurationError(err)
574 if (nicparams[constants.NIC_MODE] == constants.NIC_MODE_BRIDGED and
575 not nicparams[constants.NIC_LINK]):
576 err = "Missing bridged nic link"
577 raise errors.ConfigurationError(err)
580 class Disk(ConfigObject):
581 """Config object representing a block device."""
582 __slots__ = ["dev_type", "logical_id", "physical_id",
583 "children", "iv_name", "size", "mode", "params"]
585 def CreateOnSecondary(self):
586 """Test if this device needs to be created on a secondary node."""
587 return self.dev_type in (constants.LD_DRBD8, constants.LD_LV)
589 def AssembleOnSecondary(self):
590 """Test if this device needs to be assembled on a secondary node."""
591 return self.dev_type in (constants.LD_DRBD8, constants.LD_LV)
593 def OpenOnSecondary(self):
594 """Test if this device needs to be opened on a secondary node."""
595 return self.dev_type in (constants.LD_LV,)
597 def StaticDevPath(self):
598 """Return the device path if this device type has a static one.
600 Some devices (LVM for example) live always at the same /dev/ path,
601 irrespective of their status. For such devices, we return this
602 path, for others we return None.
604 @warning: The path returned is not a normalized pathname; callers
605 should check that it is a valid path.
608 if self.dev_type == constants.LD_LV:
609 return "/dev/%s/%s" % (self.logical_id[0], self.logical_id[1])
610 elif self.dev_type == constants.LD_BLOCKDEV:
611 return self.logical_id[1]
612 elif self.dev_type == constants.LD_RBD:
613 return "/dev/%s/%s" % (self.logical_id[0], self.logical_id[1])
616 def ChildrenNeeded(self):
617 """Compute the needed number of children for activation.
619 This method will return either -1 (all children) or a positive
620 number denoting the minimum number of children needed for
621 activation (only mirrored devices will usually return >=0).
623 Currently, only DRBD8 supports diskless activation (therefore we
624 return 0), for all other we keep the previous semantics and return
628 if self.dev_type == constants.LD_DRBD8:
632 def IsBasedOnDiskType(self, dev_type):
633 """Check if the disk or its children are based on the given type.
635 @type dev_type: L{constants.LDS_BLOCK}
636 @param dev_type: the type to look for
638 @return: boolean indicating if a device of the given type was found or not
642 for child in self.children:
643 if child.IsBasedOnDiskType(dev_type):
645 return self.dev_type == dev_type
647 def GetNodes(self, node):
648 """This function returns the nodes this device lives on.
650 Given the node on which the parent of the device lives on (or, in
651 case of a top-level device, the primary node of the devices'
652 instance), this function will return a list of nodes on which this
653 devices needs to (or can) be assembled.
656 if self.dev_type in [constants.LD_LV, constants.LD_FILE,
657 constants.LD_BLOCKDEV, constants.LD_RBD]:
659 elif self.dev_type in constants.LDS_DRBD:
660 result = [self.logical_id[0], self.logical_id[1]]
661 if node not in result:
662 raise errors.ConfigurationError("DRBD device passed unknown node")
664 raise errors.ProgrammerError("Unhandled device type %s" % self.dev_type)
667 def ComputeNodeTree(self, parent_node):
668 """Compute the node/disk tree for this disk and its children.
670 This method, given the node on which the parent disk lives, will
671 return the list of all (node, disk) pairs which describe the disk
672 tree in the most compact way. For example, a drbd/lvm stack
673 will be returned as (primary_node, drbd) and (secondary_node, drbd)
674 which represents all the top-level devices on the nodes.
677 my_nodes = self.GetNodes(parent_node)
678 result = [(node, self) for node in my_nodes]
679 if not self.children:
682 for node in my_nodes:
683 for child in self.children:
684 child_result = child.ComputeNodeTree(node)
685 if len(child_result) == 1:
686 # child (and all its descendants) is simple, doesn't split
687 # over multiple hosts, so we don't need to describe it, our
688 # own entry for this node describes it completely
691 # check if child nodes differ from my nodes; note that
692 # subdisk can differ from the child itself, and be instead
693 # one of its descendants
694 for subnode, subdisk in child_result:
695 if subnode not in my_nodes:
696 result.append((subnode, subdisk))
697 # otherwise child is under our own node, so we ignore this
698 # entry (but probably the other results in the list will
702 def ComputeGrowth(self, amount):
703 """Compute the per-VG growth requirements.
705 This only works for VG-based disks.
707 @type amount: integer
708 @param amount: the desired increase in (user-visible) disk space
710 @return: a dictionary of volume-groups and the required size
713 if self.dev_type == constants.LD_LV:
714 return {self.logical_id[0]: amount}
715 elif self.dev_type == constants.LD_DRBD8:
717 return self.children[0].ComputeGrowth(amount)
721 # Other disk types do not require VG space
724 def RecordGrow(self, amount):
725 """Update the size of this disk after growth.
727 This method recurses over the disks's children and updates their
728 size correspondigly. The method needs to be kept in sync with the
729 actual algorithms from bdev.
732 if self.dev_type in (constants.LD_LV, constants.LD_FILE,
735 elif self.dev_type == constants.LD_DRBD8:
737 self.children[0].RecordGrow(amount)
740 raise errors.ProgrammerError("Disk.RecordGrow called for unsupported"
741 " disk type %s" % self.dev_type)
743 def Update(self, size=None, mode=None):
744 """Apply changes to size and mode.
747 if self.dev_type == constants.LD_DRBD8:
749 self.children[0].Update(size=size, mode=mode)
751 assert not self.children
759 """Sets recursively the size to zero for the disk and its children.
763 for child in self.children:
767 def SetPhysicalID(self, target_node, nodes_ip):
768 """Convert the logical ID to the physical ID.
770 This is used only for drbd, which needs ip/port configuration.
772 The routine descends down and updates its children also, because
773 this helps when the only the top device is passed to the remote
777 - target_node: the node we wish to configure for
778 - nodes_ip: a mapping of node name to ip
780 The target_node must exist in in nodes_ip, and must be one of the
781 nodes in the logical ID for each of the DRBD devices encountered
786 for child in self.children:
787 child.SetPhysicalID(target_node, nodes_ip)
789 if self.logical_id is None and self.physical_id is not None:
791 if self.dev_type in constants.LDS_DRBD:
792 pnode, snode, port, pminor, sminor, secret = self.logical_id
793 if target_node not in (pnode, snode):
794 raise errors.ConfigurationError("DRBD device not knowing node %s" %
796 pnode_ip = nodes_ip.get(pnode, None)
797 snode_ip = nodes_ip.get(snode, None)
798 if pnode_ip is None or snode_ip is None:
799 raise errors.ConfigurationError("Can't find primary or secondary node"
800 " for %s" % str(self))
801 p_data = (pnode_ip, port)
802 s_data = (snode_ip, port)
803 if pnode == target_node:
804 self.physical_id = p_data + s_data + (pminor, secret)
805 else: # it must be secondary, we tested above
806 self.physical_id = s_data + p_data + (sminor, secret)
808 self.physical_id = self.logical_id
812 """Disk-specific conversion to standard python types.
814 This replaces the children lists of objects with lists of
815 standard python types.
818 bo = super(Disk, self).ToDict()
820 for attr in ("children",):
821 alist = bo.get(attr, None)
823 bo[attr] = self._ContainerToDicts(alist)
827 def FromDict(cls, val):
828 """Custom function for Disks
831 obj = super(Disk, cls).FromDict(val)
833 obj.children = cls._ContainerFromDicts(obj.children, list, Disk)
834 if obj.logical_id and isinstance(obj.logical_id, list):
835 obj.logical_id = tuple(obj.logical_id)
836 if obj.physical_id and isinstance(obj.physical_id, list):
837 obj.physical_id = tuple(obj.physical_id)
838 if obj.dev_type in constants.LDS_DRBD:
839 # we need a tuple of length six here
840 if len(obj.logical_id) < 6:
841 obj.logical_id += (None,) * (6 - len(obj.logical_id))
845 """Custom str() formatter for disks.
848 if self.dev_type == constants.LD_LV:
849 val = "<LogicalVolume(/dev/%s/%s" % self.logical_id
850 elif self.dev_type in constants.LDS_DRBD:
851 node_a, node_b, port, minor_a, minor_b = self.logical_id[:5]
853 if self.physical_id is None:
856 phy = ("configured as %s:%s %s:%s" %
857 (self.physical_id[0], self.physical_id[1],
858 self.physical_id[2], self.physical_id[3]))
860 val += ("hosts=%s/%d-%s/%d, port=%s, %s, " %
861 (node_a, minor_a, node_b, minor_b, port, phy))
862 if self.children and self.children.count(None) == 0:
863 val += "backend=%s, metadev=%s" % (self.children[0], self.children[1])
865 val += "no local storage"
867 val = ("<Disk(type=%s, logical_id=%s, physical_id=%s, children=%s" %
868 (self.dev_type, self.logical_id, self.physical_id, self.children))
869 if self.iv_name is None:
870 val += ", not visible"
872 val += ", visible as /dev/%s" % self.iv_name
873 if isinstance(self.size, int):
874 val += ", size=%dm)>" % self.size
876 val += ", size='%s')>" % (self.size,)
880 """Checks that this disk is correctly configured.
884 if self.mode not in constants.DISK_ACCESS_SET:
885 all_errors.append("Disk access mode '%s' is invalid" % (self.mode, ))
888 def UpgradeConfig(self):
889 """Fill defaults for missing configuration values.
893 for child in self.children:
894 child.UpgradeConfig()
897 self.params = constants.DISK_LD_DEFAULTS[self.dev_type].copy()
899 self.params = FillDict(constants.DISK_LD_DEFAULTS[self.dev_type],
901 # add here config upgrade for this disk
904 class InstancePolicy(ConfigObject):
905 """Config object representing instance policy limits dictionary.
908 Note that this object is not actually used in the config, it's just
909 used as a placeholder for a few functions.
913 def CheckParameterSyntax(cls, ipolicy):
914 """ Check the instance policy for validity.
917 for param in constants.ISPECS_PARAMETERS:
918 InstancePolicy.CheckISpecSyntax(ipolicy, param)
919 if constants.IPOLICY_DTS in ipolicy:
920 InstancePolicy.CheckDiskTemplates(ipolicy[constants.IPOLICY_DTS])
921 for key in constants.IPOLICY_PARAMETERS:
923 InstancePolicy.CheckParameter(key, ipolicy[key])
924 wrong_keys = frozenset(ipolicy.keys()) - constants.IPOLICY_ALL_KEYS
926 raise errors.ConfigurationError("Invalid keys in ipolicy: %s" %
927 utils.CommaJoin(wrong_keys))
930 def CheckISpecSyntax(cls, ipolicy, name):
931 """Check the instance policy for validity on a given key.
933 We check if the instance policy makes sense for a given key, that is
934 if ipolicy[min][name] <= ipolicy[std][name] <= ipolicy[max][name].
937 @param ipolicy: dictionary with min, max, std specs
939 @param name: what are the limits for
940 @raise errors.ConfigureError: when specs for given name are not valid
943 min_v = ipolicy[constants.ISPECS_MIN].get(name, 0)
944 std_v = ipolicy[constants.ISPECS_STD].get(name, min_v)
945 max_v = ipolicy[constants.ISPECS_MAX].get(name, std_v)
946 err = ("Invalid specification of min/max/std values for %s: %s/%s/%s" %
948 ipolicy[constants.ISPECS_MIN].get(name, "-"),
949 ipolicy[constants.ISPECS_MAX].get(name, "-"),
950 ipolicy[constants.ISPECS_STD].get(name, "-")))
951 if min_v > std_v or std_v > max_v:
952 raise errors.ConfigurationError(err)
955 def CheckDiskTemplates(cls, disk_templates):
956 """Checks the disk templates for validity.
959 wrong = frozenset(disk_templates).difference(constants.DISK_TEMPLATES)
961 raise errors.ConfigurationError("Invalid disk template(s) %s" %
962 utils.CommaJoin(wrong))
965 def CheckParameter(cls, key, value):
966 """Checks a parameter.
968 Currently we expect all parameters to be float values.
973 except (TypeError, ValueError), err:
974 raise errors.ConfigurationError("Invalid value for key" " '%s':"
975 " '%s', error: %s" % (key, value, err))
978 class Instance(TaggableObject):
979 """Config object representing an instance."""
994 ] + _TIMESTAMPS + _UUID
996 def _ComputeSecondaryNodes(self):
997 """Compute the list of secondary nodes.
999 This is a simple wrapper over _ComputeAllNodes.
1002 all_nodes = set(self._ComputeAllNodes())
1003 all_nodes.discard(self.primary_node)
1004 return tuple(all_nodes)
1006 secondary_nodes = property(_ComputeSecondaryNodes, None, None,
1007 "List of secondary nodes")
1009 def _ComputeAllNodes(self):
1010 """Compute the list of all nodes.
1012 Since the data is already there (in the drbd disks), keeping it as
1013 a separate normal attribute is redundant and if not properly
1014 synchronised can cause problems. Thus it's better to compute it
1018 def _Helper(nodes, device):
1019 """Recursively computes nodes given a top device."""
1020 if device.dev_type in constants.LDS_DRBD:
1021 nodea, nodeb = device.logical_id[:2]
1025 for child in device.children:
1026 _Helper(nodes, child)
1029 all_nodes.add(self.primary_node)
1030 for device in self.disks:
1031 _Helper(all_nodes, device)
1032 return tuple(all_nodes)
1034 all_nodes = property(_ComputeAllNodes, None, None,
1035 "List of all nodes of the instance")
1037 def MapLVsByNode(self, lvmap=None, devs=None, node=None):
1038 """Provide a mapping of nodes to LVs this instance owns.
1040 This function figures out what logical volumes should belong on
1041 which nodes, recursing through a device tree.
1043 @param lvmap: optional dictionary to receive the
1044 'node' : ['lv', ...] data.
1046 @return: None if lvmap arg is given, otherwise, a dictionary of
1047 the form { 'nodename' : ['volume1', 'volume2', ...], ... };
1048 volumeN is of the form "vg_name/lv_name", compatible with
1053 node = self.primary_node
1061 if not node in lvmap:
1069 if dev.dev_type == constants.LD_LV:
1070 lvmap[node].append(dev.logical_id[0] + "/" + dev.logical_id[1])
1072 elif dev.dev_type in constants.LDS_DRBD:
1074 self.MapLVsByNode(lvmap, dev.children, dev.logical_id[0])
1075 self.MapLVsByNode(lvmap, dev.children, dev.logical_id[1])
1078 self.MapLVsByNode(lvmap, dev.children, node)
1082 def FindDisk(self, idx):
1083 """Find a disk given having a specified index.
1085 This is just a wrapper that does validation of the index.
1088 @param idx: the disk index
1090 @return: the corresponding disk
1091 @raise errors.OpPrereqError: when the given index is not valid
1096 return self.disks[idx]
1097 except (TypeError, ValueError), err:
1098 raise errors.OpPrereqError("Invalid disk index: '%s'" % str(err),
1101 raise errors.OpPrereqError("Invalid disk index: %d (instace has disks"
1102 " 0 to %d" % (idx, len(self.disks) - 1),
1106 """Instance-specific conversion to standard python types.
1108 This replaces the children lists of objects with lists of standard
1112 bo = super(Instance, self).ToDict()
1114 for attr in "nics", "disks":
1115 alist = bo.get(attr, None)
1117 nlist = self._ContainerToDicts(alist)
1124 def FromDict(cls, val):
1125 """Custom function for instances.
1128 if "admin_state" not in val:
1129 if val.get("admin_up", False):
1130 val["admin_state"] = constants.ADMINST_UP
1132 val["admin_state"] = constants.ADMINST_DOWN
1133 if "admin_up" in val:
1135 obj = super(Instance, cls).FromDict(val)
1136 obj.nics = cls._ContainerFromDicts(obj.nics, list, NIC)
1137 obj.disks = cls._ContainerFromDicts(obj.disks, list, Disk)
1140 def UpgradeConfig(self):
1141 """Fill defaults for missing configuration values.
1144 for nic in self.nics:
1146 for disk in self.disks:
1147 disk.UpgradeConfig()
1149 for key in constants.HVC_GLOBALS:
1151 del self.hvparams[key]
1154 if self.osparams is None:
1156 UpgradeBeParams(self.beparams)
1159 class OS(ConfigObject):
1160 """Config object representing an operating system.
1162 @type supported_parameters: list
1163 @ivar supported_parameters: a list of tuples, name and description,
1164 containing the supported parameters by this OS
1166 @type VARIANT_DELIM: string
1167 @cvar VARIANT_DELIM: the variant delimiter
1179 "supported_variants",
1180 "supported_parameters",
1186 def SplitNameVariant(cls, name):
1187 """Splits the name into the proper name and variant.
1189 @param name: the OS (unprocessed) name
1191 @return: a list of two elements; if the original name didn't
1192 contain a variant, it's returned as an empty string
1195 nv = name.split(cls.VARIANT_DELIM, 1)
1201 def GetName(cls, name):
1202 """Returns the proper name of the os (without the variant).
1204 @param name: the OS (unprocessed) name
1207 return cls.SplitNameVariant(name)[0]
1210 def GetVariant(cls, name):
1211 """Returns the variant the os (without the base name).
1213 @param name: the OS (unprocessed) name
1216 return cls.SplitNameVariant(name)[1]
1219 class NodeHvState(ConfigObject):
1220 """Hypvervisor state on a node.
1222 @ivar mem_total: Total amount of memory
1223 @ivar mem_node: Memory used by, or reserved for, the node itself (not always
1225 @ivar mem_hv: Memory used by hypervisor or lost due to instance allocation
1227 @ivar mem_inst: Memory used by instances living on node
1228 @ivar cpu_total: Total node CPU core count
1229 @ivar cpu_node: Number of CPU cores reserved for the node itself
1242 class NodeDiskState(ConfigObject):
1243 """Disk state on a node.
1253 class Node(TaggableObject):
1254 """Config object representing a node.
1256 @ivar hv_state: Hypervisor state (e.g. number of CPUs)
1257 @ivar hv_state_static: Hypervisor state overriden by user
1258 @ivar disk_state: Disk state (e.g. free space)
1259 @ivar disk_state_static: Disk state overriden by user
1278 "disk_state_static",
1279 ] + _TIMESTAMPS + _UUID
1281 def UpgradeConfig(self):
1282 """Fill defaults for missing configuration values.
1285 # pylint: disable=E0203
1286 # because these are "defined" via slots, not manually
1287 if self.master_capable is None:
1288 self.master_capable = True
1290 if self.vm_capable is None:
1291 self.vm_capable = True
1293 if self.ndparams is None:
1296 if self.powered is None:
1300 """Custom function for serializing.
1303 data = super(Node, self).ToDict()
1305 hv_state = data.get("hv_state", None)
1306 if hv_state is not None:
1307 data["hv_state"] = self._ContainerToDicts(hv_state)
1309 disk_state = data.get("disk_state", None)
1310 if disk_state is not None:
1311 data["disk_state"] = \
1312 dict((key, self._ContainerToDicts(value))
1313 for (key, value) in disk_state.items())
1318 def FromDict(cls, val):
1319 """Custom function for deserializing.
1322 obj = super(Node, cls).FromDict(val)
1324 if obj.hv_state is not None:
1325 obj.hv_state = cls._ContainerFromDicts(obj.hv_state, dict, NodeHvState)
1327 if obj.disk_state is not None:
1329 dict((key, cls._ContainerFromDicts(value, dict, NodeDiskState))
1330 for (key, value) in obj.disk_state.items())
1335 class NodeGroup(TaggableObject):
1336 """Config object representing a node group."""
1345 "disk_state_static",
1347 ] + _TIMESTAMPS + _UUID
1350 """Custom function for nodegroup.
1352 This discards the members object, which gets recalculated and is only kept
1356 mydict = super(NodeGroup, self).ToDict()
1357 del mydict["members"]
1361 def FromDict(cls, val):
1362 """Custom function for nodegroup.
1364 The members slot is initialized to an empty list, upon deserialization.
1367 obj = super(NodeGroup, cls).FromDict(val)
1371 def UpgradeConfig(self):
1372 """Fill defaults for missing configuration values.
1375 if self.ndparams is None:
1378 if self.serial_no is None:
1381 if self.alloc_policy is None:
1382 self.alloc_policy = constants.ALLOC_POLICY_PREFERRED
1384 # We only update mtime, and not ctime, since we would not be able
1385 # to provide a correct value for creation time.
1386 if self.mtime is None:
1387 self.mtime = time.time()
1389 self.diskparams = UpgradeDiskParams(self.diskparams)
1390 if self.ipolicy is None:
1391 self.ipolicy = MakeEmptyIPolicy()
1393 def FillND(self, node):
1394 """Return filled out ndparams for L{objects.Node}
1396 @type node: L{objects.Node}
1397 @param node: A Node object to fill
1398 @return a copy of the node's ndparams with defaults filled
1401 return self.SimpleFillND(node.ndparams)
1403 def SimpleFillND(self, ndparams):
1404 """Fill a given ndparams dict with defaults.
1406 @type ndparams: dict
1407 @param ndparams: the dict to fill
1409 @return: a copy of the passed in ndparams with missing keys filled
1410 from the node group defaults
1413 return FillDict(self.ndparams, ndparams)
1416 class Cluster(TaggableObject):
1417 """Config object representing the cluster."""
1421 "highest_used_port",
1424 "volume_group_name",
1426 "drbd_usermode_helper",
1428 "default_hypervisor",
1433 "use_external_mip_script",
1436 "shared_file_storage_dir",
1437 "enabled_hypervisors",
1446 "candidate_pool_size",
1449 "maintain_node_health",
1451 "default_iallocator",
1454 "primary_ip_family",
1455 "prealloc_wipe_disks",
1457 "disk_state_static",
1458 ] + _TIMESTAMPS + _UUID
1460 def UpgradeConfig(self):
1461 """Fill defaults for missing configuration values.
1464 # pylint: disable=E0203
1465 # because these are "defined" via slots, not manually
1466 if self.hvparams is None:
1467 self.hvparams = constants.HVC_DEFAULTS
1469 for hypervisor in self.hvparams:
1470 self.hvparams[hypervisor] = FillDict(
1471 constants.HVC_DEFAULTS[hypervisor], self.hvparams[hypervisor])
1473 if self.os_hvp is None:
1476 # osparams added before 2.2
1477 if self.osparams is None:
1480 if self.ndparams is None:
1481 self.ndparams = constants.NDC_DEFAULTS
1483 self.beparams = UpgradeGroupedParams(self.beparams,
1484 constants.BEC_DEFAULTS)
1485 for beparams_group in self.beparams:
1486 UpgradeBeParams(self.beparams[beparams_group])
1488 migrate_default_bridge = not self.nicparams
1489 self.nicparams = UpgradeGroupedParams(self.nicparams,
1490 constants.NICC_DEFAULTS)
1491 if migrate_default_bridge:
1492 self.nicparams[constants.PP_DEFAULT][constants.NIC_LINK] = \
1495 if self.modify_etc_hosts is None:
1496 self.modify_etc_hosts = True
1498 if self.modify_ssh_setup is None:
1499 self.modify_ssh_setup = True
1501 # default_bridge is no longer used in 2.1. The slot is left there to
1502 # support auto-upgrading. It can be removed once we decide to deprecate
1503 # upgrading straight from 2.0.
1504 if self.default_bridge is not None:
1505 self.default_bridge = None
1507 # default_hypervisor is just the first enabled one in 2.1. This slot and
1508 # code can be removed once upgrading straight from 2.0 is deprecated.
1509 if self.default_hypervisor is not None:
1510 self.enabled_hypervisors = ([self.default_hypervisor] +
1511 [hvname for hvname in self.enabled_hypervisors
1512 if hvname != self.default_hypervisor])
1513 self.default_hypervisor = None
1515 # maintain_node_health added after 2.1.1
1516 if self.maintain_node_health is None:
1517 self.maintain_node_health = False
1519 if self.uid_pool is None:
1522 if self.default_iallocator is None:
1523 self.default_iallocator = ""
1525 # reserved_lvs added before 2.2
1526 if self.reserved_lvs is None:
1527 self.reserved_lvs = []
1529 # hidden and blacklisted operating systems added before 2.2.1
1530 if self.hidden_os is None:
1533 if self.blacklisted_os is None:
1534 self.blacklisted_os = []
1536 # primary_ip_family added before 2.3
1537 if self.primary_ip_family is None:
1538 self.primary_ip_family = AF_INET
1540 if self.master_netmask is None:
1541 ipcls = netutils.IPAddress.GetClassFromIpFamily(self.primary_ip_family)
1542 self.master_netmask = ipcls.iplen
1544 if self.prealloc_wipe_disks is None:
1545 self.prealloc_wipe_disks = False
1547 # shared_file_storage_dir added before 2.5
1548 if self.shared_file_storage_dir is None:
1549 self.shared_file_storage_dir = ""
1551 if self.use_external_mip_script is None:
1552 self.use_external_mip_script = False
1554 self.diskparams = UpgradeDiskParams(self.diskparams)
1556 # instance policy added before 2.6
1557 if self.ipolicy is None:
1558 self.ipolicy = FillIPolicy(constants.IPOLICY_DEFAULTS, {})
1560 # we can either make sure to upgrade the ipolicy always, or only
1561 # do it in some corner cases (e.g. missing keys); note that this
1562 # will break any removal of keys from the ipolicy dict
1563 self.ipolicy = FillIPolicy(constants.IPOLICY_DEFAULTS, self.ipolicy)
1566 def primary_hypervisor(self):
1567 """The first hypervisor is the primary.
1569 Useful, for example, for L{Node}'s hv/disk state.
1572 return self.enabled_hypervisors[0]
1575 """Custom function for cluster.
1578 mydict = super(Cluster, self).ToDict()
1579 mydict["tcpudp_port_pool"] = list(self.tcpudp_port_pool)
1583 def FromDict(cls, val):
1584 """Custom function for cluster.
1587 obj = super(Cluster, cls).FromDict(val)
1588 if not isinstance(obj.tcpudp_port_pool, set):
1589 obj.tcpudp_port_pool = set(obj.tcpudp_port_pool)
1592 def GetHVDefaults(self, hypervisor, os_name=None, skip_keys=None):
1593 """Get the default hypervisor parameters for the cluster.
1595 @param hypervisor: the hypervisor name
1596 @param os_name: if specified, we'll also update the defaults for this OS
1597 @param skip_keys: if passed, list of keys not to use
1598 @return: the defaults dict
1601 if skip_keys is None:
1604 fill_stack = [self.hvparams.get(hypervisor, {})]
1605 if os_name is not None:
1606 os_hvp = self.os_hvp.get(os_name, {}).get(hypervisor, {})
1607 fill_stack.append(os_hvp)
1610 for o_dict in fill_stack:
1611 ret_dict = FillDict(ret_dict, o_dict, skip_keys=skip_keys)
1615 def SimpleFillHV(self, hv_name, os_name, hvparams, skip_globals=False):
1616 """Fill a given hvparams dict with cluster defaults.
1618 @type hv_name: string
1619 @param hv_name: the hypervisor to use
1620 @type os_name: string
1621 @param os_name: the OS to use for overriding the hypervisor defaults
1622 @type skip_globals: boolean
1623 @param skip_globals: if True, the global hypervisor parameters will
1626 @return: a copy of the given hvparams with missing keys filled from
1627 the cluster defaults
1631 skip_keys = constants.HVC_GLOBALS
1635 def_dict = self.GetHVDefaults(hv_name, os_name, skip_keys=skip_keys)
1636 return FillDict(def_dict, hvparams, skip_keys=skip_keys)
1638 def FillHV(self, instance, skip_globals=False):
1639 """Fill an instance's hvparams dict with cluster defaults.
1641 @type instance: L{objects.Instance}
1642 @param instance: the instance parameter to fill
1643 @type skip_globals: boolean
1644 @param skip_globals: if True, the global hypervisor parameters will
1647 @return: a copy of the instance's hvparams with missing keys filled from
1648 the cluster defaults
1651 return self.SimpleFillHV(instance.hypervisor, instance.os,
1652 instance.hvparams, skip_globals)
1654 def SimpleFillBE(self, beparams):
1655 """Fill a given beparams dict with cluster defaults.
1657 @type beparams: dict
1658 @param beparams: the dict to fill
1660 @return: a copy of the passed in beparams with missing keys filled
1661 from the cluster defaults
1664 return FillDict(self.beparams.get(constants.PP_DEFAULT, {}), beparams)
1666 def FillBE(self, instance):
1667 """Fill an instance's beparams dict with cluster defaults.
1669 @type instance: L{objects.Instance}
1670 @param instance: the instance parameter to fill
1672 @return: a copy of the instance's beparams with missing keys filled from
1673 the cluster defaults
1676 return self.SimpleFillBE(instance.beparams)
1678 def SimpleFillNIC(self, nicparams):
1679 """Fill a given nicparams dict with cluster defaults.
1681 @type nicparams: dict
1682 @param nicparams: the dict to fill
1684 @return: a copy of the passed in nicparams with missing keys filled
1685 from the cluster defaults
1688 return FillDict(self.nicparams.get(constants.PP_DEFAULT, {}), nicparams)
1690 def SimpleFillOS(self, os_name, os_params):
1691 """Fill an instance's osparams dict with cluster defaults.
1693 @type os_name: string
1694 @param os_name: the OS name to use
1695 @type os_params: dict
1696 @param os_params: the dict to fill with default values
1698 @return: a copy of the instance's osparams with missing keys filled from
1699 the cluster defaults
1702 name_only = os_name.split("+", 1)[0]
1704 result = self.osparams.get(name_only, {})
1706 result = FillDict(result, self.osparams.get(os_name, {}))
1708 return FillDict(result, os_params)
1711 def SimpleFillHvState(hv_state):
1712 """Fill an hv_state sub dict with cluster defaults.
1715 return FillDict(constants.HVST_DEFAULTS, hv_state)
1718 def SimpleFillDiskState(disk_state):
1719 """Fill an disk_state sub dict with cluster defaults.
1722 return FillDict(constants.DS_DEFAULTS, disk_state)
1724 def FillND(self, node, nodegroup):
1725 """Return filled out ndparams for L{objects.NodeGroup} and L{objects.Node}
1727 @type node: L{objects.Node}
1728 @param node: A Node object to fill
1729 @type nodegroup: L{objects.NodeGroup}
1730 @param nodegroup: A Node object to fill
1731 @return a copy of the node's ndparams with defaults filled
1734 return self.SimpleFillND(nodegroup.FillND(node))
1736 def SimpleFillND(self, ndparams):
1737 """Fill a given ndparams dict with defaults.
1739 @type ndparams: dict
1740 @param ndparams: the dict to fill
1742 @return: a copy of the passed in ndparams with missing keys filled
1743 from the cluster defaults
1746 return FillDict(self.ndparams, ndparams)
1748 def SimpleFillIPolicy(self, ipolicy):
1749 """ Fill instance policy dict with defaults.
1752 @param ipolicy: the dict to fill
1754 @return: a copy of passed ipolicy with missing keys filled from
1755 the cluster defaults
1758 return FillIPolicy(self.ipolicy, ipolicy)
1761 class BlockDevStatus(ConfigObject):
1762 """Config object representing the status of a block device."""
1774 class ImportExportStatus(ConfigObject):
1775 """Config object representing the status of an import or export."""
1781 "progress_throughput",
1789 class ImportExportOptions(ConfigObject):
1790 """Options for import/export daemon
1792 @ivar key_name: X509 key name (None for cluster certificate)
1793 @ivar ca_pem: Remote peer CA in PEM format (None for cluster certificate)
1794 @ivar compress: Compression method (one of L{constants.IEC_ALL})
1795 @ivar magic: Used to ensure the connection goes to the right disk
1796 @ivar ipv6: Whether to use IPv6
1797 @ivar connect_timeout: Number of seconds for establishing connection
1810 class ConfdRequest(ConfigObject):
1811 """Object holding a confd request.
1813 @ivar protocol: confd protocol version
1814 @ivar type: confd query type
1815 @ivar query: query request
1816 @ivar rsalt: requested reply salt
1827 class ConfdReply(ConfigObject):
1828 """Object holding a confd reply.
1830 @ivar protocol: confd protocol version
1831 @ivar status: reply status code (ok, error)
1832 @ivar answer: confd query reply
1833 @ivar serial: configuration serial number
1844 class QueryFieldDefinition(ConfigObject):
1845 """Object holding a query field definition.
1847 @ivar name: Field name
1848 @ivar title: Human-readable title
1849 @ivar kind: Field type
1850 @ivar doc: Human-readable description
1861 class _QueryResponseBase(ConfigObject):
1867 """Custom function for serializing.
1870 mydict = super(_QueryResponseBase, self).ToDict()
1871 mydict["fields"] = self._ContainerToDicts(mydict["fields"])
1875 def FromDict(cls, val):
1876 """Custom function for de-serializing.
1879 obj = super(_QueryResponseBase, cls).FromDict(val)
1880 obj.fields = cls._ContainerFromDicts(obj.fields, list, QueryFieldDefinition)
1884 class QueryRequest(ConfigObject):
1885 """Object holding a query request.
1895 class QueryResponse(_QueryResponseBase):
1896 """Object holding the response to a query.
1898 @ivar fields: List of L{QueryFieldDefinition} objects
1899 @ivar data: Requested data
1907 class QueryFieldsRequest(ConfigObject):
1908 """Object holding a request for querying available fields.
1917 class QueryFieldsResponse(_QueryResponseBase):
1918 """Object holding the response to a query for fields.
1920 @ivar fields: List of L{QueryFieldDefinition} objects
1927 class MigrationStatus(ConfigObject):
1928 """Object holding the status of a migration.
1938 class InstanceConsole(ConfigObject):
1939 """Object describing how to access the console of an instance.
1954 """Validates contents of this object.
1957 assert self.kind in constants.CONS_ALL, "Unknown console type"
1958 assert self.instance, "Missing instance name"
1959 assert self.message or self.kind in [constants.CONS_SSH,
1960 constants.CONS_SPICE,
1962 assert self.host or self.kind == constants.CONS_MESSAGE
1963 assert self.port or self.kind in [constants.CONS_MESSAGE,
1965 assert self.user or self.kind in [constants.CONS_MESSAGE,
1966 constants.CONS_SPICE,
1968 assert self.command or self.kind in [constants.CONS_MESSAGE,
1969 constants.CONS_SPICE,
1971 assert self.display or self.kind in [constants.CONS_MESSAGE,
1972 constants.CONS_SPICE,
1977 class SerializableConfigParser(ConfigParser.SafeConfigParser):
1978 """Simple wrapper over ConfigParse that allows serialization.
1980 This class is basically ConfigParser.SafeConfigParser with two
1981 additional methods that allow it to serialize/unserialize to/from a
1986 """Dump this instance and return the string representation."""
1989 return buf.getvalue()
1992 def Loads(cls, data):
1993 """Load data from a string."""
1994 buf = StringIO(data)