make connector config update generic

This commit is contained in:
itsikkes 2016-06-04 23:25:15 +03:00
parent 5113cc6400
commit 1acab50f51
1 changed files with 34 additions and 18 deletions

View File

@ -65,31 +65,47 @@ class Job(restful.Resource):
class Connector(restful.Resource):
def get(self, **kw):
type = request.args.get('type')
if type == 'VCenterConnector':
vcenter = VCenterConnector()
properties = mongo.db.connector.find_one({"type": 'VCenterConnector'})
contype = request.args.get('type')
# if no type given - return list of types
if not contype:
conlist = []
for jobclass in available_jobs:
if jobclass.connector.__name__ not in conlist:
conlist.append(jobclass.connector.__name__)
return {"oneOf": conlist}
con = get_connector_by_name(contype)
if not con:
return {}
properties = mongo.db.connector.find_one({"type": con.__class__.__name__})
if properties:
vcenter.load_properties(properties)
ret = vcenter.get_properties()
con.load_properties(properties)
ret = con.get_properties()
ret["password"] = "" # for better security, don't expose password
return ret
return {}
def post(self, **kw):
settings_json = json.loads(request.data)
if settings_json.get("type") == 'VCenterConnector':
contype = settings_json.get("type")
# preserve password
properties = mongo.db.connector.find_one({"type": 'VCenterConnector'})
# preserve password if empty given
properties = mongo.db.connector.find_one({"type": contype})
if properties and (not settings_json.has_key("password") or not settings_json["password"]):
settings_json["password"] = properties.get("password")
return mongo.db.connector.update({"type": 'VCenterConnector'},
return mongo.db.connector.update({"type": contype},
{"$set": settings_json},
upsert=True)
def get_connector_by_name(name):
for jobclass in available_jobs:
if name == jobclass.connector.__name__:
return jobclass.connector()
return None
def get_jobclass_by_name(name):
for jobclass in available_jobs:
if jobclass.__name__ == name: