This commit is contained in:
uggla 2015-07-02 00:43:57 +02:00
parent 2f7c61cf7d
commit 6d40985f10
4 changed files with 67 additions and 14 deletions

View File

@ -6,10 +6,12 @@ from flask import request
import config
import models
import pprint
import configuration_item
from alexandria.drivers import Driver
# Initialise Flask
app = Flask(__name__)
app.debug = False
app.debug = True
@app.route("/drivers", methods = ["GET"])
@ -46,14 +48,33 @@ def bruno():
@app.route('/ci', methods=['POST'])
def create_ci():
ci = configuration_item.ConfigurationItem(request.json["uuid"],
request.json["ip_mgmt"],
request.json["login"],
request.json["password"])
# Error cas uuid already available
alexandria_cis.update({request.json["uuid"]: ci })
driver_list = conf_file.get_drivers()
#for driver in driver_list:
#driver.get(ci)
return ("ok")
@app.route('/ci', methods=['PUT'])
def update_ci():
pass
@app.route("/", methods = ["GET"])
def api_root():
global alexandria_version
#global alexandria
data = {
"Service" : "Alexandria",
"Version" : alexandria_version
"Version" : alexandria.version
}
resp = jsonify(data)
@ -70,9 +91,27 @@ def shutdown_server():
func()
class Alexandria(object):
def __init__(self):
self.version = "0.1"
self.model = models.Model()
driver_name_list = conf_file.get_drivers()
self.drivers = []
# Create objects !!!! TO BE CONTINUED !!!!
for driver_name in driver_name_list:
setattr(self, driver_name, Driver)
if __name__ == "__main__":
# Vars
alexandria_version = "0.1"
global alexandria
alexandria = Alexandria()
# Define a PrettyPrinter for debugging.
pp = pprint.PrettyPrinter(indent=4)
@ -82,8 +121,11 @@ if __name__ == "__main__":
# Model
models = models.Model()
# Define a structure to handle ci
alexandria_cis = {}
print models.reference_items
pp.pprint(models.EthernetInterface) # debugging example.
pp.pprint(models.Manager) # debugging example.
#pp.pprint(models.EthernetInterface) # debugging example.
#pp.pprint(models.Manager) # debugging example.
app.run(port=int(conf_file.get_alexandria_port()))

View File

@ -0,0 +1,13 @@
# coding=utf-8
class ConfigurationItem(object):
def __init__(self,uuid,ip_mgmt,login,password):
self.uuid = uuid
self.ip_mgmt = ip_mgmt
self.login = login
self.password = password

View File

@ -2,18 +2,16 @@
class Driver(object):
def __init__(self, alexandria_configuration):
# Get credentials from conf files
def __init__(self):
# Get credentials from conf files for CMDB
pass
class itop(Driver):
def get_ci(self,uuid):
def get(self):
pass
def push_ci(self,uuid):
def push(self):
pass

View File

@ -17,7 +17,7 @@ class Model(object):
def read_ref_files(self):
cwd = os.getcwd()
model_files = glob.glob(cwd + "/model/*.json")
model_files = glob.glob(cwd + "/model/*.json") # change hierarchy model/std/*.json
for file in model_files:
# Derive attribute name from file.