From 6bf5f4b375edef9550e34276aad1a56dac0525bf Mon Sep 17 00:00:00 2001 From: uggla Date: Wed, 8 Jul 2015 00:08:49 +0200 Subject: [PATCH] Elaborate around drivers. --- alexandria/alexandria.conf | 4 ++++ alexandria/app.py | 46 +++++++++++++++++++++++++------------- alexandria/drivers.py | 25 +++++++++++++++++---- 3 files changed, 55 insertions(+), 20 deletions(-) diff --git a/alexandria/alexandria.conf b/alexandria/alexandria.conf index 98474ad..2baf260 100644 --- a/alexandria/alexandria.conf +++ b/alexandria/alexandria.conf @@ -19,3 +19,7 @@ endpoint=http://ironic/rest drvtype=hw paramMondo1 paramMondo2 + +[fakecmdb] + +[fakeprovider] \ No newline at end of file diff --git a/alexandria/app.py b/alexandria/app.py index a232ffe..c84a4db 100644 --- a/alexandria/app.py +++ b/alexandria/app.py @@ -3,11 +3,13 @@ from flask import Flask from flask import jsonify from flask import request +import sys import config import models import pprint import configuration_item -from alexandria.drivers import Driver +import drivers +#from django.core.files.temp import gettempdir # Initialise Flask app = Flask(__name__) @@ -57,7 +59,7 @@ def create_ci(): # Error cas uuid already available alexandria_cis.update({request.json["uuid"]: ci }) - driver_list = conf_file.get_drivers() + #driver_list = conf_file.get_drivers() #for driver in driver_list: #driver.get(ci) @@ -80,7 +82,7 @@ def api_root(): resp = jsonify(data) resp.status_code = 200 - resp.headers["AuthorSite"] = "http://uggla.fr" + resp.headers["AuthorSite"] = "https://github.com/uggla/alexandria" return resp @@ -94,15 +96,31 @@ def shutdown_server(): class Alexandria(object): def __init__(self): self.version = "0.1" + + # Model self.model = models.Model() - driver_name_list = conf_file.get_drivers() + # Configuration file + self.conf_file = config.AlexandriaConfiguration("alexandria.conf") + + # Build driver list from configuration file + driver_name_list = self.conf_file.get_drivers() self.drivers = [] - + # Create objects !!!! TO BE CONTINUED !!!! for driver_name in driver_name_list: - setattr(self, driver_name, Driver) + # Get class + driver_class = getattr(sys.modules["drivers"], driver_name.capitalize()) + # Create object + driver_object = driver_class() + # Add to driver list + self.drivers.append(driver_object) + index = self.drivers.index(driver_object) + # Set an attribute to the coresponding driver + setattr(self, driver_name.lower(), self.drivers[index]) + + @@ -112,20 +130,16 @@ if __name__ == "__main__": alexandria = Alexandria() - # Define a PrettyPrinter for debugging. pp = pprint.PrettyPrinter(indent=4) - - # Configuration file - conf_file = config.AlexandriaConfiguration("alexandria.conf") - - # Model - models = models.Model() - + # Define a structure to handle ci alexandria_cis = {} - print models.reference_items + print alexandria.model.reference_items + alexandria.itop.get() #pp.pprint(models.EthernetInterface) # debugging example. #pp.pprint(models.Manager) # debugging example. - app.run(port=int(conf_file.get_alexandria_port())) + app.run(port=int(alexandria.conf_file.get_alexandria_port())) + + diff --git a/alexandria/drivers.py b/alexandria/drivers.py index 9fb80d1..77a6e6c 100644 --- a/alexandria/drivers.py +++ b/alexandria/drivers.py @@ -6,12 +6,29 @@ class Driver(object): # Get credentials from conf files for CMDB pass -class itop(Driver): +class Itop(Driver): def get(self): - pass + print "Get from itop" + return True + def push(self): pass - - \ No newline at end of file + +class Redfish(Driver): + pass + +class Ironic(Driver): + pass + +class Mondorescue(Driver): + pass + +class Fakecmdb(Driver): + pass + +class Fakeprovider(Driver): + pass + +