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.38k stars 234 forks source link

Nornir run command will not work when converting to exe file #819

Closed aminelami closed 1 year ago

aminelami commented 1 year ago

Hi, I have my script working fine as .py file, but when converted to .exe the run will not return anything:

fact = nr.run(task=napalm_get, getters=["facts"])

Any suggestion or help please ?

ktbyers commented 1 year ago

No idea...doesn't sound like a Nornir issue though. Sounds more like Python execution bundling issue (i.e. it is outside the scope of the Nornir library).

dbarrosop commented 1 year ago

Closing issue as this is not really related to nornir. Feel free to move to a discussion but I'd suggest providing more details in that case, for instance, how to reproduce.

aminelami commented 1 year ago

Sorry about my late response. I am not sure if it is a bundling issue since I am able to launch the exe from CMD without any error. Here is the script:

`from Convert_to_Yaml import Convert_to_YAML from Get_devices import Get_devices_Excel,Get_devices_csv from nornir import InitNornir from nornir_utils.plugins.functions import print_result from nornir_napalm.plugins.tasks import napalm_get,napalm_cli from nornir_rich.progress_bar import RichProgressBar from nornir_pyez.plugins.tasks import pyez_rpc

def optical_info(fact): for Host in fact: try: Hostname=fact[Host][0].result['facts']['hostname'] interfaces_counters_optics=fact[Host][0].result['optics'] for intf, intf_data in interfaces_counters_optics.items(): for physical_channels, intf_optics in intf_data.items(): for channel, channel_optics in intf_optics.items(): for int, int_optics in channel_optics[0].items(): if int == 'state': Interfaces_Optics_table.add_row([Hostname, intf, int_optics["input_power"]["instant"], int_optics["output_power"]["instant"]]) except Exception as e: print(Host,e) print(Interfaces_Optics_table)

layout = [ [sg.Text("Please selet the Excel File:",size=(25, 1), font='Lucida',justification='left'), sg.Input(), sg.FileBrowse(key="file"),sg.Button('Load', font=('Times New Roman',12))], [sg.Output(key='output', size=(80,20), font='Courier 12')], [sg.Button('Go'), sg.Button('Exit')] ]

window = sg.Window('My window').Layout(layout)

while True:
event, values = window.Read() if (event is None)|(event=='Exit'): break if event == "Load": inventory_Sheet = pd.read_excel(str(values['file'])) Convert_to_YAML(inventory_Sheet,'Excel') nr = InitNornir(runner={"plugin": "threaded", "options": {"num_workers": 20}}, inventory={"plugin": "SimpleInventory", "options": { "host_file": "inventory/hosts.yaml", "group_file": "inventory/groups.yaml"}}) fact = nr.run(task=napalm_get, getters=["facts","interfaces","interfaces_counters","optics","environment"]) if event == 'Go': optical_info(fact) window.Close() `

I was able to generate the exe file without issues with: pyinstaller --onefile main.py --collect-data netutils --collect-data napalm --collect-data nornir --collect-data nornir_utils --collect-data nornir_napalm --collect-data nornir.plugins --collect-submodules nornir.plugins --collect-submodules napalm

Please let me know if you are able to reproduce with that.