def addHost(listHost): (json, errors) = hostValidate() if errors: return basic.resp(400, {"errors": errors}) try: if not findParams(json): return basic.resp(400, {"errors": "uncorrected"}) if not 'username' in json: username = str(json['user']) else: username = str(json['username']) newHost = Host(username, str(json['hostname']), str(json['user'])) if 'auth_type' in json: if json['auth_type'] == 'psw' and 'password' in json: newHost.setPassword(json['password']) if json['auth_type'] == 'key' and 'key' in json: newHost.setKey(json['key']) except: return basic.resp(400, {"errors": "uncorrected"}) listHost.append(newHost) return basic.resp(200, {})
def getHosts(tmp_hosts): try: answer = [] for host in tmp_hosts: answer_item = { "username": host.user, "user": host.hostuser, "auth_type": host.typeAuth, "hostname": host.hostname } if not host.activeHost: answer_item["active"] = bool(False) answer.append(answer_item) continue answer_item["active"] = bool(True) if not host.branchGit == '': answer_item["git"] = { "branch": host.branchGit, "revision": host.revisionGit } if not host.branchSVN == '': answer_item["svn"] = { "branch": host.branchSVN, "revision": host.revisionSVN } answer.append(answer_item) except: return basic.resp(400, {"errors": "Did not form response"}) return basic.resp(200, {"hosts": answer})
def clear(): lock.acquire() listHost.clear() lock.release() return basic.resp(200, {})
def ping(): return basic.resp(200, {})
def page_not_found(e): return basic.resp(405, {})
def hello_world(): return basic.resp(400, {})