How to use the pynetbox.core.query function in pynetbox

To help you get started, we’ve selected a few pynetbox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Solvik / netbox_agent / netbox_agent / inventory.py View on Github external
def get_netbox_inventory(self, device_id, tag):
        try:
            items = nb.dcim.inventory_items.filter(
                device_id=device_id,
                tag=tag
            )
        except pynetbox.core.query.RequestError:
            logging.info('Tag {tag} is missing, returning empty array.'.format(tag=tag))
            items = []

        return items
github Cloud-Temple / yaani / yaani / yaani.py View on Github external
endpoint = getattr(getattr(self._api, nb_app), nb_type)

        collection = []
        try:
            if "filters" in args:
                seen_id = []
                for filter_args in args['filters']:
                    for elt in endpoint.filter(**filter_args):
                        # Add the element to collection only if it is not
                        # already in
                        if elt.id not in seen_id:
                            seen_id.append(elt.id)
                            collection.append(dict(elt))
            else:
                collection = [dict(e) for e in endpoint.all()]
        except pynetbox.core.query.RequestError as err:
            raise YaaniError(
                "An error occured while requesting Netbox: {}\n"
                .format(str(err))
            )
        except requests.exceptions.ConnectionError as err:
            raise YaaniError(
                "An error occured while requesting Netbox: {}\n"
                .format(str(err))
            )
        return collection