+ self.dump_config(self._nodeconfig)
+ return self._vpp_config
+
+ def add_config_item(self, config, value, path):
+ """Add startup configuration item.
+
+ :param config: Startup configuration of node.
+ :param value: Value to insert.
+ :param path: Path where to insert item.
+ :type config: dict
+ :type value: str
+ :type path: list
+ """
+ if len(path) == 1:
+ config[path[0]] = value
+ return
+ if path[0] not in config:
+ config[path[0]] = {}
+ self.add_config_item(config[path[0]], value, path[1:])
+
+ def dump_config(self, obj, level=-1):
+ """Dump the startup configuration in VPP config format.
+
+ :param obj: Python Object to print.
+ :param level: Nested level for indentation.
+ :type obj: Obj
+ :type level: int
+ :returns: nothing
+ """
+ indent = ' '
+ if level >= 0:
+ self._vpp_config += '{}{{\n'.format((level) * indent)
+ if isinstance(obj, dict):
+ for key, val in obj.items():
+ if hasattr(val, '__iter__'):
+ self._vpp_config += '{}{}\n'.format((level + 1) * indent,
+ key)
+ self.dump_config(val, level + 1)
+ else:
+ self._vpp_config += '{}{} {}\n'.format((level + 1) * indent,
+ key, val)
+ else:
+ for val in obj:
+ self._vpp_config += '{}{}\n'.format((level + 1) * indent, val)
+ if level >= 0:
+ self._vpp_config += '{}}}\n'.format(level * indent)
+
+ def add_unix_log(self, value='/tmp/vpe.log'):
+ """Add UNIX log configuration.
+
+ :param value: Log file.
+ :type value: str
+ """
+ path = ['unix', 'log']
+ self.add_config_item(self._nodeconfig, value, path)