spotify/pyfg

Add FortiConfig.to_dict() for genie parser to compare.

Opened this issue · 0 comments

#5adb234

` def to_dict(self, root=None, tree_dict=None):
"""
This method convert FortiConfig to dict.

    Args:
        - **root** (class:`~pyFG.forticonfig.FortiConfig` object):
                * If ``None`` use self as tree root.
        - **tree_dict** (dict): This value is for output.
                * If ``None`` use a blank dict.
    """
    if root is None:
        root = self
    if tree_dict is None:
        tree_dict = {}
    if not hasattr(root, 'get_block_names') or not root.get_block_names():
        return
    for child in root.get_block_names():
        if not tree_dict.get(child):
            if root[child].get_parameter_names():
                tree_dict[child] = {k: root[child].get_param(k).replace('"', '')
                                    for k in root[child].get_parameter_names()}
            else:
                tree_dict[child] = {}
        self.to_dict(root[child], tree_dict[child])
    return tree_dict

`