def rsync_comment(): try: #获取服务器信息 db_server = db_idc.idc_servers db_third = db_idc.third_resource db_project = db_op.project_list server_list = db_server.query.with_entities(db_server.ip,db_server.ssh_port,db_server.hostname,db_server.comment).all() for list in server_list: try: comment = list[-1] hostname = list[2] if not list[-1]: ip,ssh_port = list[0:2] third_info = db_third.query.with_entities(distinct(db_third.resource_type)).filter(and_(db_third.ip==ip,db_third.ssh_port==ssh_port)).all() if third_info: third_info = [info[0] for info in third_info] project_info = db_project.query.with_entities(distinct(db_project.project)).filter(and_(db_project.ip == ip, db_project.ssh_port == ssh_port)).all() if project_info: project_info = [info[0] for info in project_info] comment = ','.join(project_info+third_info) if comment: tools.modify_jumpserver_comment(hostname,comment) except: continue except Exception as e: logging.error(e) finally: db_idc.DB.session.remove() db_op.DB.session.remove()
def modify_ops_comment(): status = None infos = '同步备注信息失败!' try: infos = request.get_json() status = tools.modify_jumpserver_comment(infos['hostname'],infos['comment']) if int(status) == 200: status = 'ok' infos = '同步备注信息成功!' except Exception as e: logging.error(e) finally: return jsonify({'status':status,'infos':infos})