I was hoping that somebody could help me with either changing the way I am approaching this problem or with some suggestions on how to implement it.
I am creating a script that will retrieve information from a number of devices. There are several types of devices, Currently I am able to one using telnet to connect and with telnetlib and run the commands to retrive the data. Another device produces a handy xml page that I can parse. These are the devices that I know about in my current location. However I need to deploy this in another location and I have no idea what devices they are using or how those devices present the data once it has been converted. And I will have to leave it to others to write the modules required for these different devices. I am trying to create a standard interface so that the modules only have to return their info in a specific way. So....
What I am trying to do is work out how to manage this in a plugin type fashion. My initial investigation have gone down the road of loading modules at runtime as in the dive into python book --
My problem here though is that I end up with a list, that contains each of the modules but I have no way to match up each module in the list to the type of device that it will need to use to retrieve the date.
I have a database set up that will have the ip address of each device and the name of the module that it will need to use e.g.
192.168.1.1 | egx-100
What I am struggling with is how to bridge the gap between all the modules that have registered at run time, which I will not know the name of them ahead of time and the module that gets added to the list imported at run time... maybe if I get each module to declare it's name and the script can query each module in the list to find the name ... this just occured to me as I was typing this.
I am using a database as the results will all be stored in here so it is convenient to create a lookup table that has this information in it.
current_path = os.getcwd() + "/drivers"
directory = os.getcwd() + "/drivers"
extension = ".py"
list_of_files = [file for file in os.listdir(directory) if file.lower().endswith(extension)]
module_names = 
for file_name in list_of_files:
file_name = file_name.rstrip(".py")
modules = map(__import__,module_names)
modules.print_string('this is a test')
This code looks in the drivers directory and imports and modules in there. However all I have at this point is a list of each of the module objects.
I would appreciate any assistance or suggestions when it comes to alternative ways to approach or resolve this. As I said this will need to be something that I can deploy and then once I have properly documented the interface I can leave it to others to write their own modules for their own devices.
Thank you all and I understand if this is a big ask.