Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nested XML configuration #3

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions ntc_rosetta/parsers/openconfig/junos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from copy import copy
from lxml import etree

from ntc_rosetta.parsers.openconfig.junos.openconfig_interfaces.interfaces import (
Expand All @@ -18,9 +19,15 @@ class JunosParser(parser.RootParser):

class Yangify(parser.ParserData):
def init(self) -> None:
self.root_native["dev_conf"] = etree.fromstring(
self.root_native["dev_conf"]
)
parsed_xml = etree.fromstring(self.root_native["dev_conf"])
if parsed_xml.tag != "configuration":
parsed_xml = parsed_xml.find('configuration')
if parsed_xml is None:
raise AttributeError("Unable to locate 'configuration' tag in XML blob")
# We need to copy the XML element here, otherwise it will retain its parent
benmcbenben marked this conversation as resolved.
Show resolved Hide resolved
# references, meaning we can inadvertantly walk up the tree when we shouldn't.
parsed_xml = copy(parsed_xml)
jathanism marked this conversation as resolved.
Show resolved Hide resolved
self.root_native["dev_conf"] = parsed_xml
self.native["dev_conf"] = self.root_native["dev_conf"]

interfaces = Interfaces
Expand Down