-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_selector.py
56 lines (40 loc) · 1.52 KB
/
device_selector.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
48
49
50
51
52
53
54
55
56
# Python library import
from netscud.devices.alcatel.alcatel_aos import AlcatelAOS
from netscud.devices.cisco.cisco_ios import CiscoIOS
from netscud.devices.cisco.cisco_s300 import CiscoS300
from netscud.devices.mikrotik.mikrotik_routeros import MikrotikRouterOS
# The supported device_types are the keys of this dictionary
ALL_DEVICE_TYPE_CLASS = {
"alcatel_aos": AlcatelAOS,
"cisco_ios": CiscoIOS,
"cisco_s300": CiscoS300,
"mikrotik_routeros": MikrotikRouterOS,
}
def ConnectDevice(**kwargs):
"""
Async function to be used for connnecting a device
This async function allows to use a class with an async method.
This function includes a connection to a device.
:param kwargs: dictionary with the device connection parameters
:type kwargs: dict
:return: Return the object with the
:rtype: object with the device class
"""
# Device type provided in the device dictionary?
if "device_type" in kwargs:
# Yes
# Get device type
device_type = kwargs["device_type"]
else:
# No
# Display error message
raise Exception("ConnectDevice: no device type specified")
# Check if device type is amongst the supported ones
if device_type not in ALL_DEVICE_TYPE_CLASS:
# Not a supported device
# Display error message
raise Exception(f"ConnectDevice: device type unknown: {device_type}")
# Create a class
my_class = ALL_DEVICE_TYPE_CLASS[device_type](**kwargs)
# Return the class
return my_class