fabric-testbed / InformationModel

FABRIC Information Model library
MIT License
7 stars 1 forks source link

Log collector #158

Closed ibaldin closed 1 year ago

ibaldin commented 1 year ago

Added fim.logging.log_collector.py LogCollector object (similar to attribute collector for Authz). It analyzes structure of a slice, element, sliver or topology diff and creates a dictionary of what is in it suitable for producing log messages. Also has a __str__() method that produces a validly formatted portion of a log message that describes the resources involved.

You can do

from fim.logging.log_collector import LogCollector

lc = LogCollector()
# entire topology
lc.collect_resource_attributes(source=self.topo)
# or an element (node or network service or component)
lc.collect_resource_attributes(source=self.topo.nodes['n1'])
# or a sliver of a node, service or component
lc.collect_resource_attributes(source=self.topo.nodes['n1'].get_sliver())
# or a diff from modify
lc.collect_resource_attributes(source=diff_res)

# then you can just use str() on it when you need to create a log message:
print(f'2022-09-06 19:45:56,022 Slice event slc:dead-beaf-dead-beaf create by prj:dddd-eeee-ffff-aaaa usr:1111-2222-3333-4444:joe@email.com with {str(lc)}')

also fixed a bug in AuthZ attribute collector where it was overriding facilities list with a single name.

ibaldin commented 1 year ago

This is now fabric-fim==1.4.0