hadiasghari / pyasn

Python IP address to Autonomous System Number lookup module. (Supports fast local lookups, and historical lookups using archived BGP dumps.)
Other
294 stars 72 forks source link

Allow pyasn to be initialised with an ipasn_string #51

Closed teor2345 closed 7 years ago

teor2345 commented 7 years ago

If the ipasn data is already loaded into a string, this avoids creating a temporary file for ipasn_file.

This is implemented in a backwards-compatible way: the new ipasn_string argument is a keyword argument, and it is only used if ipasn_file is None.

ghost commented 7 years ago

I opened a PR against your branch with some small changes and tests: https://github.com/teor2345/pyasn/pull/1

teor2345 commented 7 years ago

I opened a PR against your branch with some small changes and tests: teor2345#1

@wagner-certat, I merged your PR and removed a comment that was copy-pasted, but doesn't apply to the new function.

I think we're good to go here.

hadiasghari commented 7 years ago

Hi @teor2345, thank you for the PR. Can you tell me what your use-case is for this functionality? Where do you load the ipasn_string from?

teor2345 commented 7 years ago

Hi @teor2345, thank you for the PR. Can you tell me what your use-case is for this functionality? Where do you load the ipasn_string from?

We run a cooperating group of data collecting instances on different machines. They receive their configuration from a central point.

Here is the use case in detail:

  1. The central point reads the config from a file and checks it is valid using pyasn
  2. The central point reads the file into a string, and sends the string along with many other config strings to the data collecting instances
  3. The data collecting instances read the config from the string, and load it using pyasn

This avoids the data collecting instances dumping the string to a file (they have no ability to write files) and then reading it out again using pyasn. It would be slower and more error-prone to write a file (for example, if the directory wasn't writeable, or the disk was full).

hadiasghari commented 7 years ago

Merged, cheers.