ns1-python icon indicating copy to clipboard operation
ns1-python copied to clipboard

Would be nice to have a NS1.listZones() and/or Zone.list()

Open nyetwurk opened this issue 5 years ago • 5 comments

something akin to

    return zones.Zone(self.config, None)._rest.list()

nyetwurk avatar Jul 22 '20 20:07 nyetwurk

Perhaps Zone itself can have a list() method that just extracts a list of bare zone['zone']s

nyetwurk avatar Jul 22 '20 20:07 nyetwurk

huh, definitely fair to want easier access to list, seems like an oversight.

I don't think I'd want it on Zone objects, as it's higher scope, but I think a listZones method on the client is appropriate. I'll see if i can whip up a PR.

rupa avatar Jul 23 '20 19:07 rupa

this code more or less works for me (from an api client, not an api patch)

    data = zones.Zone(api.config, None)._rest.list()
    print("known zones:")
    for z in data:
      print(z["zone"])

nyetwurk avatar Jul 29 '20 16:07 nyetwurk

yep, that works, but it's not really the way we envisioned its use. usually we access this via the "rest layer"

zones = client.zones()
zones.list()

for the "high-level" interface, I still believe that a listZones function is appropriate - my suspicion is that it hasn't been implemented as it should return Zone objects, and loading all of those zones would take N API calls. I would not want that happening if i had thousands of zones in my list!

what I'd like to do, and proposed, is to make listZones return a list of mostly empty Zone objects, and you would have to make a call to "load" the ones you want. That would need a bit of docs/comments explaining it, and i worry a bit if it would be more confusing than useful, but I'm inclined to add it. it's definitely on the radar!

rupa avatar Jul 30 '20 21:07 rupa

Hi @nyetwurk @rupa, thanks for this report We already created a ticket about this.

ThiagoYU avatar Oct 06 '21 21:10 ThiagoYU