-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added the ability for pure xml to be returned from either a .all() or a .search(). #11
base: master
Are you sure you want to change the base?
Conversation
This is my first actual open source PR (woweee!) let me know if I fudged something. |
Thanks for your input. I do have a couple of questions:
I'm not against merging this, but I would like to better understand the motivation behind it. |
The company I work for has over 400 routers in netdot inventory. I am making a script to pull the router hostnames from netdot so I can connect to them remotely and run commands. This library parses the xml and creates an object for each element in the xml DOM. With the amount of routers I have to pull (which will continually go up) this takes some time to create the object for each element. I timed it to be roughly .1-.2 seconds each, not too much but with 400+ routers that gets slow very fast, especially considering we want this project I'm working on to run at least once every 10 mins. There was only a small bit of information I needed to grab from the netdot API (hostname). With my changes, I was able to parse and get the information I needed with:
This takes roughly 5-6 seconds with the amount of routers we have compared to the ~2 mins it took with the xml parsing built in. |
Ooohhh I see what your problem is now! It's not actually the XML parsing that is taking the time. In fact a device name attribute is not a plain string in netdot but a reference to antother type of resource - a DNS record. So when you try to do Now, fortunately you can access the hostname without hitting the API again:
I'm sure you'll find this method is much faster. |
+1, that worked. Though I have to ask... if you already have the info in the dict why bind the property to an API call? |
Well the name attribute of a device is another type of resource in netdot (DNS resource record). So when you do Now when you call the API to get devices, the response XML already has the string representation of that DNS resource record object - and that gets stored in I know this is not an optimal solution and I need to find a better way to handle it. Especially device names are such a common use-case that pynetdot really should not be accessing the API for every device. I do have some ideas how to solve this, but I need some time to test. Hope my explanations makes some sense :) |
This allows for potentially much faster searching through the data, as you don't have to wait for each element in the tree to build into an object.