- raise ValueError('Node type is not a DUT')
-
- if pci_device is None:
- # No PCI device was given. Add all device from topology.
- for port in node['interfaces'].values():
- port_name = port.get('name')
- pci_addr = Topology.get_interface_pci_addr(node, port_name)
- if pci_addr:
- self.add_pci_device(node, pci_addr)
+ raise RuntimeError('Startup config can only be applied to DUT'
+ 'node.')
+ self._node = node
+ self._hostname = Topology.get_node_hostname(node)
+
+ def get_config_str(self):
+ """Get dumped startup configuration in VPP config format.
+
+ :returns: Startup configuration in VPP config format.
+ :rtype: str
+ """
+ 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)