nornir-automation / nornir

Pluggable multi-threaded framework with inventory management to help operate collections of devices
https://nornir.readthedocs.io/
Apache License 2.0
1.4k stars 237 forks source link

Nornir state property returning GlobalState class, not object #666

Closed brandomando closed 3 years ago

brandomando commented 3 years ago

https://github.com/nornir-automation/nornir/blob/e4f6b8c6258ae2dcfb286098b30652c7a31ecf30/nornir/core/__init__.py#L177

I'm not sure if this is intended behavior but it is a bit confusing to me why there would be a need to return the GlobalState class rather than the instantiated object like the data attribute, which is an instance of GlobalState.

brandomando commented 3 years ago

This causes issue with the dict method of the GlobalState object when you're trying to return the dict of the data attribute of a Nornir object because it doesn't have a self since the class is returned and not the instance of it.

https://github.com/nornir-automation/nornir/blob/e4f6b8c6258ae2dcfb286098b30652c7a31ecf30/nornir/core/state.py#L27

def dict(self) -> Dict[str, Any]:
        """ Return a dictionary representing the object. """
        return {item: getattr(self, item) for item in GlobalState.__slots__}
dbarrosop commented 3 years ago

GlobalState used to be a singleton but that's no longer true so I think this is a leftover. As a matter of fact, state is redundant as data is what we care about nowadays.

brandomando commented 3 years ago

I thought that might be the case. I will submit a PR to remove it.

dbarrosop commented 3 years ago

Thanks!