m110 / grafcli

Grafana CLI for quick and easy dashboards management.
MIT License
168 stars 20 forks source link

elasticsearch module import failing #13

Closed jgrexa closed 7 years ago

jgrexa commented 7 years ago

Module loading used in utils.py via try_module function is not working for elasticsearch module, if I change it to usual from/import, it works without problem.

Module versions: grafcli==0.4.6 elasticsearch==5.2.0

Command tried: grafcli ls remote/elastichost

Traceback (most recent call last): File "/usr/local/bin/grafcli", line 27, in sys.exit(main()) File "/usr/local/bin/grafcli", line 13, in main result = cli.execute(*sys.argv[1:]) File "/usr/local/lib/python3.6/site-packages/climb/core.py", line 73, in execute return self._commands.execute(command, *kwargs) File "/usr/local/lib/python3.6/site-packages/climb/commands.py", line 26, in execute return method(args, **kwargs) File "/usr/local/lib/python3.6/site-packages/grafcli/commands.py", line 30, in ls result = self._resources.list(path) File "/usr/local/lib/python3.6/site-packages/grafcli/resources/resources.py", line 28, in list manager, parts = self._parse_path(path) File "/usr/local/lib/python3.6/site-packages/grafcli/resources/resources.py", line 74, in _parse_path self._resources['remote'][host] = RemoteResources(host) File "/usr/local/lib/python3.6/site-packages/grafcli/resources/remote.py", line 8, in init self._storage = get_remote_storage(host) File "/usr/local/lib/python3.6/site-packages/grafcli/storage/init.py", line 31, in get_remote_storage return storage_class(host) File "/usr/local/lib/python3.6/site-packages/grafcli/storage/elastic.py", line 39, in init self._connection = Elasticsearch(addresses, NameError: name 'Elasticsearch' is not defined

m110 commented 7 years ago

Thanks!

jgrexa commented 7 years ago

still doesn't work due to

Traceback (most recent call last): File "/usr/local/bin/grafcli", line 27, in sys.exit(main()) File "/usr/local/bin/grafcli", line 13, in main result = cli.execute(*sys.argv[1:]) File "/usr/local/lib/python3.6/site-packages/climb/core.py", line 73, in execute return self._commands.execute(command, *kwargs) File "/usr/local/lib/python3.6/site-packages/climb/commands.py", line 26, in execute return method(args, **kwargs) File "/usr/local/lib/python3.6/site-packages/grafcli/commands.py", line 30, in ls result = self._resources.list(path) File "/usr/local/lib/python3.6/site-packages/grafcli/resources/resources.py", line 28, in list manager, parts = self._parse_path(path) File "/usr/local/lib/python3.6/site-packages/grafcli/resources/resources.py", line 74, in _parse_path self._resources['remote'][host] = RemoteResources(host) File "/usr/local/lib/python3.6/site-packages/grafcli/resources/remote.py", line 8, in init self._storage = get_remote_storage(host) File "/usr/local/lib/python3.6/site-packages/grafcli/storage/init.py", line 31, in get_remote_storage return storage_class(host) File "/usr/local/lib/python3.6/site-packages/grafcli/storage/elastic.py", line 38, in init http_auth=http_auth) TypeError: 'NoneType' object is not callable

seems the problem is in structure of Elasticsearch module, this doesnt work:

importlib.import_module('elasticsearch.Elasticsearch') Traceback (most recent call last): File "", line 1, in File "/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 978, in _gcd_import File "", line 961, in _find_and_load File "", line 948, in _find_and_load_unlocked ModuleNotFoundError: No module named 'elasticsearch.Elasticsearch'

this works:

getattr(importlib.import_module('elasticsearch.client'), 'Elasticsearch') <class 'elasticsearch.client.Elasticsearch'>

m110 commented 7 years ago

Thanks once again. Tested it properly now, should be importing fine.