Hello community, here is the log from the commit of package python-pynetbox for openSUSE:Leap:15.2 checked in at 2020-03-26 05:41:56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Leap:15.2/python-pynetbox (Old) and /work/SRC/openSUSE:Leap:15.2/.python-pynetbox.new.3160 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-pynetbox" Thu Mar 26 05:41:56 2020 rev:2 rq:788237 version:4.3.0 Changes: -------- --- /work/SRC/openSUSE:Leap:15.2/python-pynetbox/python-pynetbox.changes 2020-02-22 18:49:57.272420980 +0100 +++ /work/SRC/openSUSE:Leap:15.2/.python-pynetbox.new.3160/python-pynetbox.changes 2020-03-26 05:42:08.219302364 +0100 @@ -1,0 +2,6 @@ +Mon Mar 23 14:49:20 UTC 2020 - pgaj...@suse.com + +- version update to 4.3.0 + * Adds the ability to thread calls to NetBox from .filter() and .all() methods. (PR #216) + +------------------------------------------------------------------- Old: ---- pynetbox-4.2.5.tar.gz New: ---- pynetbox-4.3.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-pynetbox.spec ++++++ --- /var/tmp/diff_new_pack.I3uEiX/_old 2020-03-26 05:42:08.587302555 +0100 +++ /var/tmp/diff_new_pack.I3uEiX/_new 2020-03-26 05:42:08.591302557 +0100 @@ -18,7 +18,7 @@ %{?!python_module:%define python_module() python-%{**} python3-%{**}} Name: python-pynetbox -Version: 4.2.5 +Version: 4.3.0 Release: 0 Summary: NetBox API client library License: Apache-2.0 @@ -35,7 +35,7 @@ BuildRequires: fdupes BuildRequires: python-rpm-macros Requires: python-netaddr -Requires: python-requests +Requires: python-requests >= 2.20.0 BuildArch: noarch %python_subpackages ++++++ pynetbox-4.2.5.tar.gz -> pynetbox-4.3.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pynetbox-4.2.5/PKG-INFO new/pynetbox-4.3.0/PKG-INFO --- old/pynetbox-4.2.5/PKG-INFO 2020-02-11 04:34:29.000000000 +0100 +++ new/pynetbox-4.3.0/PKG-INFO 2020-03-16 22:20:52.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pynetbox -Version: 4.2.5 +Version: 4.3.0 Summary: NetBox API client library Home-page: https://github.com/digitalocean/pynetbox Author: Zach Moody diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pynetbox-4.2.5/README.md new/pynetbox-4.3.0/README.md --- old/pynetbox-4.2.5/README.md 2020-02-11 04:34:14.000000000 +0100 +++ new/pynetbox-4.3.0/README.md 2020-03-16 22:20:37.000000000 +0100 @@ -38,3 +38,13 @@ [test1-leaf1, test1-leaf2] ``` +### Threading + +pynetbox supports multithreaded calls (in Python 3 only) for `.filter()` and `.all()` queries. It is **highly recommended** you have `MAX_PAGE_SIZE` in your Netbox install set to anything *except* `0` or `None`. The default value of `1000` is usually a good value to use. To enable threading, add `threading=True` parameter to the `.api`: + +```python +nb = pynetbox.api( + 'http://localhost:8000', + threading=True, +) +``` diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pynetbox-4.2.5/pynetbox/api.py new/pynetbox-4.3.0/pynetbox/api.py --- old/pynetbox-4.2.5/pynetbox/api.py 2020-02-11 04:34:14.000000000 +0100 +++ new/pynetbox-4.3.0/pynetbox/api.py 2020-03-16 22:20:37.000000000 +0100 @@ -13,6 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. """ +import sys + import requests from pynetbox.core.endpoint import Endpoint @@ -152,6 +154,7 @@ private_key=None, private_key_file=None, ssl_verify=True, + threading=False, ): if private_key and private_key_file: raise ValueError( @@ -165,6 +168,10 @@ self.ssl_verify = ssl_verify self.session_key = None self.http_session = requests.Session() + if threading and sys.version_info.major == 2: + raise NotImplementedError("Threaded pynetbox calls not supported \ + in Python 2") + self.threading = threading if self.private_key_file: with open(self.private_key_file, "r") as kf: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pynetbox-4.2.5/pynetbox/core/endpoint.py new/pynetbox-4.3.0/pynetbox/core/endpoint.py --- old/pynetbox-4.2.5/pynetbox/core/endpoint.py 2020-02-11 04:34:14.000000000 +0100 +++ new/pynetbox-4.3.0/pynetbox/core/endpoint.py 2020-03-16 22:20:37.000000000 +0100 @@ -96,6 +96,7 @@ session_key=self.session_key, ssl_verify=self.ssl_verify, http_session=self.api.http_session, + threading=self.api.threading, ) return [self._response_loader(i) for i in req.get()] @@ -220,6 +221,7 @@ session_key=self.session_key, ssl_verify=self.ssl_verify, http_session=self.api.http_session, + threading=self.api.threading, ) ret = [self._response_loader(i) for i in req.get()] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pynetbox-4.2.5/pynetbox/core/query.py new/pynetbox-4.3.0/pynetbox/core/query.py --- old/pynetbox-4.2.5/pynetbox/core/query.py 2020-02-11 04:34:14.000000000 +0100 +++ new/pynetbox-4.3.0/pynetbox/core/query.py 2020-03-16 22:20:37.000000000 +0100 @@ -13,6 +13,10 @@ See the License for the specific language governing permissions and limitations under the License. """ +try: + import concurrent.futures as cf +except ImportError: + pass import json from six.moves.urllib.parse import urlencode @@ -28,6 +32,11 @@ return "?{}".format(urlencode(param_dict)) +def calc_pages(limit, count): + """ Calculate number of pages required for full results set. """ + return int(count / limit) + (limit % count > 0) + + class RequestError(Exception): """Basic Request Exception @@ -141,6 +150,7 @@ session_key=None, ssl_verify=True, url=None, + threading=False, ): """ Instantiates a new Request object @@ -164,6 +174,7 @@ self.ssl_verify = ssl_verify self.http_session = http_session self.url = self.base if not key else "{}{}/".format(self.base, key) + self.threading = threading def get_version(self): """ Gets the API version of NetBox. @@ -262,6 +273,19 @@ else: raise RequestError(req) + def concurrent_get(self, ret, page_size, page_offsets): + futures_to_results = [] + with cf.ThreadPoolExecutor(max_workers=4) as pool: + for offset in page_offsets: + new_params = {"offset": offset, "limit": page_size} + futures_to_results.append( + pool.submit(self._make_call, add_params=new_params) + ) + + for future in cf.as_completed(futures_to_results): + result = future.result() + ret.extend(result["results"]) + def get(self, add_params=None): """Makes a GET request. @@ -297,6 +321,32 @@ else: return req + def req_all_threaded(add_params): + if add_params is None: + # Limit must be 0 to discover the max page size + add_params = {"limit": 0} + req = self._make_call(add_params=add_params) + if isinstance(req, dict) and req.get("results") is not None: + ret = req["results"] + if req.get("next"): + page_size = len(req["results"]) + pages = calc_pages(page_size, req["count"]) + page_offsets = [ + increment * page_size for increment in range(1, pages) + ] + if pages == 1: + req = self._make_call(url_override=req.get("next")) + ret.extend(req["results"]) + else: + self.concurrent_get(ret, page_size, page_offsets) + + return ret + else: + return req + + if self.threading: + return req_all_threaded(add_params) + return req_all() def put(self, data): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/pynetbox-4.2.5/pynetbox.egg-info/PKG-INFO new/pynetbox-4.3.0/pynetbox.egg-info/PKG-INFO --- old/pynetbox-4.2.5/pynetbox.egg-info/PKG-INFO 2020-02-11 04:34:29.000000000 +0100 +++ new/pynetbox-4.3.0/pynetbox.egg-info/PKG-INFO 2020-03-16 22:20:52.000000000 +0100 @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pynetbox -Version: 4.2.5 +Version: 4.3.0 Summary: NetBox API client library Home-page: https://github.com/digitalocean/pynetbox Author: Zach Moody