class documentation

A generic config object.

It has the following properties:

  • provides somewhat safe recursive unpickling and pickling for its classes
  • unset attributes which are defined in slots are always returned as None instead of raising an error

Classes derived from this must always declare __slots__ (we use many config objects and the memory reduction is useful)

Class Method FromDict Create an object from a dictionary.
Method __getattr__ Undocumented
Method __repr__ Implement __repr__ for ConfigObjects.
Method __setstate__ Undocumented
Method Copy Makes a deep copy of the current object and its children.
Method ToDict Convert to a dict holding only standard python types.
Method UpgradeConfig Fill defaults for missing configuration values.
Method Validate Validates the slots.
Class Variable __slots__ Undocumented

Inherited from ValidatedSlots:

Class Method GetAllSlots Compute the list of all declared slots for a class.
Method __init__ Constructor for BaseOpCode.
@classmethod
def FromDict(cls, val):

Create an object from a dictionary.

This generic routine takes a dict, instantiates a new instance of the given class, and sets attributes based on the dict content.

As for `ToDict`, this does not work if the class has children who are ConfigObjects themselves (e.g. the nics list in an Instance), in which case the object should subclass the function and alter the objects.

def __getattr__(self, name):

Undocumented

def __repr__(self):

Implement __repr__ for ConfigObjects.

def __setstate__(self, state):

Undocumented

def Copy(self):

Makes a deep copy of the current object and its children.

def ToDict(self, _with_private=False):

Convert to a dict holding only standard python types.

The generic routine just dumps all of this object's attributes in a dict. It does not work if the class has children who are ConfigObjects themselves (e.g. the nics list in an Instance), in which case the object should subclass the function in order to make sure all objects returned are only standard python types.

Private fields can be included or not with the _with_private switch. The actual implementation of this switch is left for those subclassses with private fields to implement.

Parameters
_with_private:boolif True, the object will leak its private fields in the dictionary representation. If False, the values will be replaced with None.
def UpgradeConfig(self):

Fill defaults for missing configuration values.

This method will be called at configuration load time, and its implementation will be object dependent.

def Validate(self):

Validates the slots.

This method returns None if the validation succeeds, or raises an exception otherwise.

This method must be implemented by the child classes.

Returns
NoneTypeNone, if the validation succeeds
Raises
Exceptionvalidation fails