Parse configuration from the device.

    models
        A list of models to be used when parsing.

    config: ``False``
        Parse config.

    state: ``False``
        Parse state.

    profiles: ``None``
        Use certain profiles to parse. If not specified, will use the device
        default profile(s).

    CLI Example:

    .. code-block:: bash

        salt '*' napalm_yang.parse models.openconfig_interfaces

    Output Example:

    .. code-block:: python

        {
            "interfaces": {
                "interface": {
                    ".local.": {
                        "name": ".local.",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 0,
                            "last-change": 0,
                            "oper-status": "UP",
                            "type": "softwareLoopback"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                ".local..0": {
                                    "index": ".local..0",
                                    "state": {
                                        "ifindex": 0,
                                        "name": ".local..0"
                                    }
                                }
                            }
                        }
                    },
                    "ae0": {
                        "name": "ae0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 531,
                            "last-change": 255203,
                            "mtu": 1518,
                            "oper-status": "DOWN"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "ae0.0": {
                                    "index": "ae0.0",
                                    "state": {
                                        "description": "ASDASDASD",
                                        "ifindex": 532,
                                        "name": "ae0.0"
                                    }
                                }
                                "ae0.32767": {
                                    "index": "ae0.32767",
                                    "state": {
                                        "ifindex": 535,
                                        "name": "ae0.32767"
                                    }
                                }
                            }
                        }
                    },
                    "dsc": {
                        "name": "dsc",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 5,
                            "last-change": 0,
                            "oper-status": "UP"
                        }
                    },
                    "ge-0/0/0": {
                        "name": "ge-0/0/0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-broadcast-pkts": 0,
                                "in-discards": 0,
                                "in-errors": 0,
                                "in-multicast-pkts": 0,
                                "in-unicast-pkts": 16877,
                                "out-broadcast-pkts": 0,
                                "out-errors": 0,
                                "out-multicast-pkts": 0,
                                "out-unicast-pkts": 15742
                            },
                            "description": "management interface",
                            "enabled": True,
                            "ifindex": 507,
                            "last-change": 258467,
                            "mtu": 1400,
                            "oper-status": "UP"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "ge-0/0/0.0": {
                                    "index": "ge-0/0/0.0",
                                    "state": {
                                        "description": "ge-0/0/0.0",
                                        "ifindex": 521,
                                        "name": "ge-0/0/0.0"
                                    }
                                }
                            }
                        }
                    }
                    "irb": {
                        "name": "irb",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 502,
                            "last-change": 0,
                            "mtu": 1514,
                            "oper-status": "UP",
                            "type": "ethernetCsmacd"
                        }
                    },
                    "lo0": {
                        "name": "lo0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "description": "lo0",
                            "enabled": True,
                            "ifindex": 6,
                            "last-change": 0,
                            "oper-status": "UP",
                            "type": "softwareLoopback"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "lo0.0": {
                                    "index": "lo0.0",
                                    "state": {
                                        "description": "lo0.0",
                                        "ifindex": 16,
                                        "name": "lo0.0"
                                    }
                                },
                                "lo0.16384": {
                                    "index": "lo0.16384",
                                    "state": {
                                        "ifindex": 21,
                                        "name": "lo0.16384"
                                    }
                                },
                                "lo0.16385": {
                                    "index": "lo0.16385",
                                    "state": {
                                        "ifindex": 22,
                                        "name": "lo0.16385"
                                    }
                                },
                                "lo0.32768": {
                                    "index": "lo0.32768",
                                    "state": {
                                        "ifindex": 248,
                                        "name": "lo0.32768"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

def parse(*models, **kwargs):
    '''
    Parse configuration from the device.

    models
        A list of models to be used when parsing.

    config: ``False``
        Parse config.

    state: ``False``
        Parse state.

    profiles: ``None``
        Use certain profiles to parse. If not specified, will use the device
        default profile(s).

    CLI Example:

    .. code-block:: bash

        salt '*' napalm_yang.parse models.openconfig_interfaces

    Output Example:

    .. code-block:: python

        {
            "interfaces": {
                "interface": {
                    ".local.": {
                        "name": ".local.",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 0,
                            "last-change": 0,
                            "oper-status": "UP",
                            "type": "softwareLoopback"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                ".local..0": {
                                    "index": ".local..0",
                                    "state": {
                                        "ifindex": 0,
                                        "name": ".local..0"
                                    }
                                }
                            }
                        }
                    },
                    "ae0": {
                        "name": "ae0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 531,
                            "last-change": 255203,
                            "mtu": 1518,
                            "oper-status": "DOWN"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "ae0.0": {
                                    "index": "ae0.0",
                                    "state": {
                                        "description": "ASDASDASD",
                                        "ifindex": 532,
                                        "name": "ae0.0"
                                    }
                                }
                                "ae0.32767": {
                                    "index": "ae0.32767",
                                    "state": {
                                        "ifindex": 535,
                                        "name": "ae0.32767"
                                    }
                                }
                            }
                        }
                    },
                    "dsc": {
                        "name": "dsc",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 5,
                            "last-change": 0,
                            "oper-status": "UP"
                        }
                    },
                    "ge-0/0/0": {
                        "name": "ge-0/0/0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-broadcast-pkts": 0,
                                "in-discards": 0,
                                "in-errors": 0,
                                "in-multicast-pkts": 0,
                                "in-unicast-pkts": 16877,
                                "out-broadcast-pkts": 0,
                                "out-errors": 0,
                                "out-multicast-pkts": 0,
                                "out-unicast-pkts": 15742
                            },
                            "description": "management interface",
                            "enabled": True,
                            "ifindex": 507,
                            "last-change": 258467,
                            "mtu": 1400,
                            "oper-status": "UP"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "ge-0/0/0.0": {
                                    "index": "ge-0/0/0.0",
                                    "state": {
                                        "description": "ge-0/0/0.0",
                                        "ifindex": 521,
                                        "name": "ge-0/0/0.0"
                                    }
                                }
                            }
                        }
                    }
                    "irb": {
                        "name": "irb",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "enabled": True,
                            "ifindex": 502,
                            "last-change": 0,
                            "mtu": 1514,
                            "oper-status": "UP",
                            "type": "ethernetCsmacd"
                        }
                    },
                    "lo0": {
                        "name": "lo0",
                        "state": {
                            "admin-status": "UP",
                            "counters": {
                                "in-discards": 0,
                                "in-errors": 0,
                                "out-errors": 0
                            },
                            "description": "lo0",
                            "enabled": True,
                            "ifindex": 6,
                            "last-change": 0,
                            "oper-status": "UP",
                            "type": "softwareLoopback"
                        },
                        "subinterfaces": {
                            "subinterface": {
                                "lo0.0": {
                                    "index": "lo0.0",
                                    "state": {
                                        "description": "lo0.0",
                                        "ifindex": 16,
                                        "name": "lo0.0"
                                    }
                                },
                                "lo0.16384": {
                                    "index": "lo0.16384",
                                    "state": {
                                        "ifindex": 21,
                                        "name": "lo0.16384"
                                    }
                                },
                                "lo0.16385": {
                                    "index": "lo0.16385",
                                    "state": {
                                        "ifindex": 22,
                                        "name": "lo0.16385"
                                    }
                                },
                                "lo0.32768": {
                                    "index": "lo0.32768",
                                    "state": {
                                        "ifindex": 248,
                                        "name": "lo0.32768"
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    '''
    if isinstance(models, tuple) and isinstance(models[0], list):
        models = models[0]
    config = kwargs.pop('config', False)
    state = kwargs.pop('state', False)
    profiles = kwargs.pop('profiles', [])
    if not profiles and hasattr(napalm_device, 'profile'):  # pylint: disable=undefined-variable
        profiles = napalm_device.profile  # pylint: disable=undefined-variable
    if not profiles:
        profiles = [__grains__.get('os')]
    root = _get_root_object(models)
    parser_kwargs = {
        'device': napalm_device.get('DRIVER'),  # pylint: disable=undefined-variable
        'profile': profiles
    }
    if config:
        root.parse_config(**parser_kwargs)
    if state:
        root.parse_state(**parser_kwargs)
    return root.to_dict(filter=True)