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.
This commit is contained in:
parent
da4f890e84
commit
7e1bd64771
|
@ -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():
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue