UI change to generic connector config

still needs to handle client cache problem
This commit is contained in:
itsikkes 2016-06-05 23:41:12 +03:00
parent 9343d102ce
commit 6d444920e7
5 changed files with 101 additions and 99 deletions

View File

@ -129,26 +129,19 @@
</div> </div>
<div id="config" style="overflow: visible" class="panel-body panel-collapse collapse in" aria-expanded="true"> <div id="config" style="overflow: visible" class="panel-body panel-collapse collapse in" aria-expanded="true">
<span class="input-group-btn"> <span class="input-group-btn">
<button id="btnLoadVCenterConfig" class="btn btn-default" type="button" <button id="btnLoadConnectorsConfig" class="btn btn-default" type="button"
onclick="loadVcenterConfig()" style="margin-top:-4px"> onclick="loadConnectorsConfig()" style="margin-top:-4px">
Reload VCenter Config Change Connectors Config
</button>
<button id="btnUpdateVCenterConfig" class="btn btn-default" type="button"
onclick="updateVcenterConfig()" style="margin-top:-4px">
Save VCenter Config
</button> </button>
</span> </span>
<div id="vcenter-config"> <div id="connector-config-section">
</div> <div id="connectors-config">
<!--<span class="input-group-btn"> </div>
<button id="btnConfigLoad" style="display: none;" class="btn btn-default" type="button" <button id="btnSaveConnectorConfig" class="btn btn-default" type="button"
onclick="loadMonkeyConfig()" style="margin-top:-4px"> onclick="updateConnectorConfig()" style="margin-top:-4px; visibility: hidden"">
Load Save Conectors Config
</button> </button>
<button id="btnConfigUpdate" style="display: none;" class="btn btn-default" type="button" </div>
onclick="updateMonkeyConfig()" style="margin-top:-4px">
Update
</button>-->
</span> </span>
</div> </div>

View File

@ -12,8 +12,8 @@ const ICONS_EXT = ".png";
var jobsTable = undefined; var jobsTable = undefined;
var logsTable = undefined; var logsTable = undefined;
var vcenterCfg = undefined;
var jobCfg = undefined; var jobCfg = undefined;
var conCfg = undefined;
var selectedJob = undefined; var selectedJob = undefined;
JSONEditor.defaults.theme = 'bootstrap3'; JSONEditor.defaults.theme = 'bootstrap3';
@ -41,73 +41,8 @@ function initAdmin() {
showLog(selectedJob); showLog(selectedJob);
} ); } );
vcenterCfg = new JSONEditor(document.getElementById('vcenter-config'),{
schema: {
type: "object",
title: "vcenter",
properties: {
address: {
title: "Address",
type: "string",
},
port: {
title: "Port",
type: "integer",
},
username: {
title: "Username",
type: "string",
},
password: {
title: "Password",
type: "string",
},
monkey_template_name: {
title: "Monkey Template Name",
type: "string",
},
monkey_vm_info: {
title: "Monkey Creation VM",
type: "object",
properties: {
name: {
title: "Deployment Name",
type: "string",
},
vm_folder: {
title: "VM Folder (opt.)",
type: "string",
},
resource_pool: {
title: "Resource Pool (opt.)",
type: "string",
},
datacenter_name: {
title: "Datacenter (opt.)",
type: "string",
},
cluster_name: {
title: "Cluster (opt.)",
type: "string",
},
datastore_name: {
title: "Datastore (opt.)",
type: "string",
},
}
}
},
options: {
"collapsed": true
},
},
disable_edit_json: false,
disable_properties: true,
});
setInterval(updateJobs, 5000); setInterval(updateJobs, 5000);
setInterval(showLog, 5000); setInterval(showLog, 5000);
loadVcenterConfig();
updateJobs(); updateJobs();
} }
@ -140,20 +75,39 @@ function updateJobs() {
} }
jobsTable.draw(); jobsTable.draw();
//enableJobsSelect();
}); });
} }
function loadVcenterConfig() { function loadConnectorsConfig() {
$.getJSON('/connector?type=VCenterConnector', function(json) { elem = document.getElementById('connectors-config');
vcenterCfg.setValue(json); elem.innerHTML = ""
conCfg = new JSONEditor(elem,{
schema: {
type: "object",
title: "Connector",
properties: {
connector: {
title: "Type",
$ref: "/connector",
}
},
options: {
"collapsed": false
},
},
ajax: true,
disable_edit_json: false,
disable_collapse: true,
disable_properties: true,
no_additional_properties: true
});
conCfg.on('ready',function() {
document.getElementById("btnSaveConnectorConfig").style.visibility = "visible";
}); });
} }
function updateVcenterConfig() { function updateConnectorConfig() {
var vc_config = vcenterCfg.getValue() var con_config = conCfg.getValue()
vc_config["type"] = "VCenterConnector";
$.ajax({ $.ajax({
headers : { headers : {
'Accept' : 'application/json', 'Accept' : 'application/json',
@ -161,9 +115,12 @@ function updateVcenterConfig() {
}, },
url : '/connector', url : '/connector',
type : 'POST', type : 'POST',
data : JSON.stringify(vc_config), data : JSON.stringify(con_config.connector),
success : function(response, textStatus, jqXhr) { success : function(response, textStatus, jqXhr) {
console.log("New vcenter config successfully updated!"); console.log("New vcenter config successfully updated!");
document.getElementById("btnSaveConnectorConfig").style.visibility = "hidden";
elem = document.getElementById('connectors-config');
elem.innerHTML = ""
}, },
error : function(jqXHR, textStatus, errorThrown) { error : function(jqXHR, textStatus, errorThrown) {
// log the error to the console // log the error to the console

View File

@ -65,6 +65,8 @@ class NetControllerJob(object):
if self._logger: if self._logger:
self._logger.log(text) self._logger.log(text)
# external API
def get_job_properties(self): def get_job_properties(self):
return self._properties return self._properties
@ -80,4 +82,10 @@ class NetControllerJob(object):
raise NotImplementedError() raise NotImplementedError()
def get_results(self): def get_results(self):
return [] return []
def get_state(self):
return None
def stop(self):
raise NotImplementedError()

View File

@ -12,7 +12,6 @@ class VCenterConnector(NetControllerConnector):
"password": "", "password": "",
"monkey_template_name": "", "monkey_template_name": "",
"monkey_vm_info": { "monkey_vm_info": {
"name": "Monkey Test",
"datacenter_name": "", "datacenter_name": "",
"vm_folder": "", "vm_folder": "",
"datastore_name": "", "datastore_name": "",

View File

@ -63,15 +63,39 @@ class Job(restful.Resource):
class Connector(restful.Resource): class Connector(restful.Resource):
def _build_prop_dict(self, properties, job_obj=None):
res = dict()
for prop in properties:
res[prop] = dict({})
res[prop]["default"] = properties[prop]
if type(properties[prop]) is int:
res[prop]["type"] = "number"
elif type(properties[prop]) is bool:
res[prop]["type"] = "boolean"
elif type(properties[prop]) is dict:
res[prop]["type"] = "object"
res[prop]["properties"] = self._build_prop_dict(properties[prop], job_obj)
else:
res[prop]["type"] = "string"
if job_obj:
enum = job_obj.get_property_function(prop)
if enum:
properties[prop]["enum"] = list(
active_connectors[job_obj.connector_type.__name__].__getattribute__(enum)())
return res
def get(self, **kw): def get(self, **kw):
contype = request.args.get('type') contype = request.args.get('type')
# if no type given - return list of types # if no type given - return list of types
if not contype: if not contype:
conlist = [] conlist = []
checked_con = [] # used for easy checking for reoccurring connectors
for jobclass in available_jobs: for jobclass in available_jobs:
if jobclass.connector_type.__name__ not in conlist: if jobclass.connector_type.__name__ not in checked_con:
conlist.append(jobclass.connector_type.__name__) checked_con.append(jobclass.connector_type.__name__)
conlist.append({"title": jobclass.connector_type.__name__, "$ref": "/connector?type=" + jobclass.connector_type.__name__})
return {"oneOf": conlist} return {"oneOf": conlist}
con = get_connector_by_name(contype) con = get_connector_by_name(contype)
@ -80,14 +104,34 @@ class Connector(restful.Resource):
properties = mongo.db.connector.find_one({"type": con.__class__.__name__}) properties = mongo.db.connector.find_one({"type": con.__class__.__name__})
if properties: if properties:
con.load_properties(properties) con.load_properties(properties)
ret = con.get_properties() con_prop = con.get_properties()
ret["password"] = "" # for better security, don't expose password con_prop["password"] = "" # for better security, don't expose password
return ret
properties = self._build_prop_dict(con_prop)
properties["type"] = {
"type": "enum",
"enum": [contype],
"options": {"hidden": True}
}
res = dict({
"title": "%s Connector" % contype,
"type": "object",
"options": {
"disable_collapse": True,
"disable_properties": True,
},
"properties": properties
})
return res
def post(self, **kw): def post(self, **kw):
settings_json = json.loads(request.data) settings_json = json.loads(request.data)
contype = settings_json.get("type") contype = settings_json.get("type")
if not contype:
return {}
# preserve password if empty given # preserve password if empty given
properties = mongo.db.connector.find_one({"type": contype}) properties = mongo.db.connector.find_one({"type": contype})
if properties and (not settings_json.has_key("password") or not settings_json["password"]): if properties and (not settings_json.has_key("password") or not settings_json["password"]):
@ -97,6 +141,7 @@ class Connector(restful.Resource):
{"$set": settings_json}, {"$set": settings_json},
upsert=True) upsert=True)
class JobCreation(restful.Resource): class JobCreation(restful.Resource):
def get(self, **kw): def get(self, **kw):
jobtype = request.args.get('type') jobtype = request.args.get('type')