Exemplo n.º 1
0
    async def fetch(self, **params):

        api: IPFabricClient(IPFPortChannels) = self.source.client
        api.mixin(IPFPortChannels)

        if (filters := params.get("filters")) is not None:
            params["filters"] = parse_filter(filters)
Exemplo n.º 2
0
def test_group_filter_and():
    res = parse_filter("and( hostname = Foo, interface = bar)")
    assert res == {
        "and": [{
            "hostname": ["eq", "Foo"]
        }, {
            "interface": ["eq", "bar"]
        }]
    }
Exemplo n.º 3
0
    async def fetch(self, **params):

        # going to fetch the associated devices and store them into the
        # collection cache so that these items/values can be used for filtering
        # purposes.  For example, the User may want to filter out port-channels
        # based on device model/family.

        dev_col = self.cache['devices'] = get_collection(source=self.source,
                                                         name='devices')
        await dev_col.fetch(**params)
        dev_col.make_keys('hostname')

        api: IPFabricClient(IPFPortChannels) = self.source.client
        api.mixin(IPFPortChannelsMixin)

        if (filters := params.get("filters")) is not None:
            params["filters"] = parse_filter(filters)
Exemplo n.º 4
0
    async def fetch(self, **params):

        if (filters := params.get("filters")) is not None:
            params["filters"] = parse_filter(filters)
Exemplo n.º 5
0
        # We want to know information about the device, such as os_name, and we
        # will key this collection by the hostname value

        dev_col = self.cache.setdefault(
            'devices', get_collection(source=self.source, name='devices'))

        if (hostname := params.pop('hostname', None)) is not None:
            await dev_col.fetch(filters=f"hostname = '{hostname}'")
        else:
            await dev_col.fetch(**params)

        dev_col.make_keys('hostname')

        if (filters := params.get("filters")) is not None:
            params["filters"] = parse_filter(filters)

        records = await self.source.client.fetch_table(
            url="/tables/inventory/interfaces",
            columns=[
                "hostname", "intName", "dscr", "siteName", "l1", "primaryIp"
            ],
            **params,
        )

        self.source_records.extend(records)

    async def fetch_items(self, items: Dict):
        raise NotImplementedError()

    def itemize(self, rec: Dict) -> Dict:
Exemplo n.º 6
0
        q_name = None if snapshot == "Untitled" else snapshot

        log.info(f"Looking for IP Fabric snapshot: {snapshot}")

        if not (
            sn_rec := next(
                (rec for rec in ipf.snapshots if rec["name"] == q_name), None
            )
        ):
            log.error(f"IP Fabric snapshot not found: {snapshot}")
            return
        ipf.active_snapshot = sn_rec["id"]

    if filters:
        log.info(f"Filters: {filters}")
        ipf_filters = parse_filter(filters)

    else:
        log.warning("No device filtering specified")
        ipf_filters = None

    # obtain the device inventory that is matching the User provided filters.
    # This list of hostnames is used to filter the configuration files that are
    # requested.

    devices = await ipf.fetch_devices(columns=["hostname"], filters=ipf_filters)

    if not len(devices):
        log.warning("No devices matching filter")
        return
Exemplo n.º 7
0
def test_group_filter_compound_and():
    res = parse_filter(
        "and(hostname = Boo, or( hostname = Foo, interface = bar))")
    inner = {"or": [{"hostname": ["eq", "Foo"]}, {"interface": ["eq", "bar"]}]}
    expected = {"and": [{"hostname": ["eq", "Boo"]}, inner]}
    assert res == expected
Exemplo n.º 8
0
def test_simple_filter():
    res = parse_filter("hostname = Foo")
    assert res == {"hostname": ["eq", "Foo"]}