From 7e1bd64771c9f3a255861c283ab882faacb4976b Mon Sep 17 00:00:00 2001 From: uggla Date: Fri, 10 Jul 2015 14:31:05 +0200 Subject: [PATCH] Put in place synchronization. Synchronization is done between all drivers. In fact, only the fake drivers are doing something. Fakeprovider is updating the manager date add some fields. Fakecmdb is just writting the content of ci.data to a json file. This commit is a fist step in the implementation. --- alexandria/app.py | 27 ++++++++++++++++++++++----- alexandria/drivers.py | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/alexandria/app.py b/alexandria/app.py index 6babd89..2908e2b 100644 --- a/alexandria/app.py +++ b/alexandria/app.py @@ -63,18 +63,35 @@ def create_ci(): alexandria_cis.update({request.json["uuid"]: ci }) - # Now do a "broadcast" get to all our drivers - for driver in config.alexandria.drivers: - app.logger.info("Get information from {} driver.".format(driver.get_driver_type())) - driver.get_ci(ci) + # Synchronize data beetween all our drivers + synchronize_ci(ci) + app.logger.debug("citype {}".format(ci.ci_type)) # TODO : Remove next line, used just for debugging... pp.pprint(alexandria_cis) app.logger.debug("Debug message") - return ("ok") + # Craft response + resp = jsonify(ci.data) + resp.status_code = 200 + + resp.headers["AuthorSite"] = "https://github.com/uggla/alexandria" + + return resp + +def synchronize_ci(ci): + # Now do a "broadcast" get to all our drivers + for driver in config.alexandria.drivers: + app.logger.info("Get information from {} driver.".format(driver.get_driver_type())) + driver.get_ci(ci) + + # Push the data provided above to all our drivers + for driver in config.alexandria.drivers: + app.logger.info("Push information to {} driver.".format(driver.get_driver_type())) + driver.push_ci(ci) + @app.route('/ci', methods=['PUT']) def update_ci(): diff --git a/alexandria/drivers.py b/alexandria/drivers.py index 4b2d162..295764a 100644 --- a/alexandria/drivers.py +++ b/alexandria/drivers.py @@ -3,6 +3,7 @@ import types import pprint import config +import json class Driver(object): @@ -28,7 +29,7 @@ class Itop(Driver): print "Get from itop" return True - def push_ci(self): + def push_ci(self,ci): pass class Redfish(Driver): @@ -37,35 +38,56 @@ class Redfish(Driver): print "Get from redfish" return True + class Ironic(Driver): pass + class Mondorescue(Driver): pass + class Fakecmdb(Driver): - pass + def push_ci(self, ci): + # Determine ci type so we can do the proper action. + pp = pprint.PrettyPrinter(indent=4) + if ci.ci_type == "Manager": + print "We are in Fakecmdb driver !" + pp.pprint(ci.data) + # Simply write a json file with ci.data content. + with open("Fakecmdb.json", "w") as jsonfile: + json.dump(ci.data, jsonfile, indent=4) + jsonfile.close() + + # + #======================================================================= class Fakeprovider(Driver): def get_ci(self,ci): - import app # Simulate a driver that will provide Manager data. - # TODO a connect method must be implemented as + # TODO a connect method must be implemented # Assuming the connection is ok. - # Now create a manager model from reference model. + # Now create a copy of manager model from reference model. ci.ci_type = "Manager" - ci.data = config.alexandria.model.Manager.copy() + ci.data = config.alexandria.model.get_model("Manager") - if ci.data is config.alexandria.model.Manager: - print "identical" + # Update the structure with data + ci.data["ManagerType"] = "BMC" + ci.data["Model"] = "Néné Manager" + ci.data["FirmwareVersion"] = "1.00" + + + #if ci.data is config.alexandria.model.Manager: + # print "identical" pp = pprint.PrettyPrinter(indent=4) - pp.pprint(ci.data) + pp.pprint(ci.ci_type) + class DriverCollection(list): pass