-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwarf.py
47 lines (36 loc) · 1.58 KB
/
dwarf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -----------------------------------------------------------------------------
# System Imports
# -----------------------------------------------------------------------------
import asyncio
import time
# -----------------------------------------------------------------------------
# Private Imports
# -----------------------------------------------------------------------------
from aioeapi import Device
# -----------------------------------------------------------------------------
#
# CODE BEGINS
#
# -----------------------------------------------------------------------------
async def get_information(host: str, username, password):
async with Device(host=host, username=username, password=password, proto='http', port=80) as dev:
'''Check the connectivity before sending the command'''
if await dev.check_connection():
result = await dev.cli(commands=['show version'])
return host, result
return host, "None"
async def main_function(inventory, username, password):
commands_info = []
"""Build the list of tasks"""
tasks = [get_information(host=host, username=username, password=password) for host in inventory]
for this_dev in asyncio.as_completed(tasks):
commands_info.append(await this_dev)
return commands_info
async def main(inventory, username, password):
start = time.time()
result = await main_function(inventory, username, password)
end = time.time()
print(end - start)
# print(result)
for record in result:
print(result[0][1][0]['version'])