def app_LogDir(self, app_id, server_type, server_id, logdir_id): # 获取具体的某个日志目录 if server_type == '2': # 虚拟机 sql = ''' SELECT b.log_dir from cmdb_server_app a , -- server—app的中间表 op_app_logdir b -- app日志目录表 where a.app_id = %s and a.server_type = %s and a.virtual_server_id = %s and a.id = b.server_app_id and b.id = %s ''' elif server_type == '1': sql = ''' SELECT b.log_dir from cmdb_server_app a , -- server—app的中间表 op_app_logdir b -- app日志目录表 where a.app_id = %s and a.server_type = %s and a.physical_server_id = %s and a.id = b.server_app_id and b.id = %s ''' try: res_dir = self._cursorQuery( sql, [app_id, server_type, server_id, logdir_id]) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return {} else: if len(res_dir) == 0: runlog.error( "[ERROR] --no found the logdir-----, Catch exception:, file: [ %s ], line: [ %s ]" % (__file__, sys._getframe().f_lineno)) return {} return res_dir
def getProjectCodeFromPhsical_server(self, id): sql = ''' select f.code from auth_user a, -- 用户表 op_app_group_user ab, -- 用户-组-中间表 op_app_group b, -- 用户组 op_app_permission c, -- 权限表 op_app_group_permission bc, -- 组-权限-中间表 cmdb_physical_server d, -- 物理服务器表 op_app_permission_server cd,-- 权限-服务器-中间表 cmdb_server_app de, -- app-服务器-中间表 cmdb_app e, -- app表 cmdb_project f -- 项目表 where a.id=%s and ab.user_id=a.id and b.id=bc.group_id and c.id=bc.permission_id and c.id=cd.permission_id and cd.physical_server_id=d.id=de.physical_server_id and de.app_id=e.id and e.project_id=f.id''' try: data = self._cursorQuery(sql, [id]) print('-----9999', data) dblog.info('data1 is: %s, file: [ %s ], line: [ %s ]' \ % (data, __file__, sys._getframe().f_lineno)) return data except Exception as e: dblog.error("[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" \ % (e, __file__, sys._getframe().f_lineno)) return ''
def projectNavinfoFromProjectTable(self, id): sql = ''' SELECT DISTINCT t6.server_type, t6.virtual_server_id, t6.physical_server_id FROM `auth_user` t1, -- 用户表 `op_app_group_user` t2, -- 用户-组-中间表 `op_app_group` t3, -- 用户组表 `op_app_group_permission` t4, -- 组-权限中间表 `op_app_permission` t5, -- 权限表 `op_app_permission_server` t6 -- 权限-服务器中间表 WHERE t1.id=%s AND t1.id=t2.user_id AND t2.group_id=t3.id AND t3.id=t4.group_id AND t4.permission_id=t5.id AND t5.id=t6.permission_id''' try: data = self._cursorQuery(sql, [id]) print('<------>\033[32;1m%s\033[0m' % len(data)) dblog.info('data is: %s, file: [ %s ], line: [ %s ]' % (data, __file__, sys._getframe().f_lineno)) if len(data) == 0: dblog.error( 'project data is None , file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return '' except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return '' return data
def whole_appLogDirs(self, app_id, server_type, server_id): # 获取这个app在这个服务器上所有的日志目录 # print('oooooooooo',app_id,server_type,server_id) if server_type == '2': # 虚拟机 sql = ''' SELECT b.log_dir,b.id from cmdb_server_app a , -- server—app的中间表 op_app_logdir b -- app日志目录表 where a.app_id = %s and a.server_type = %s and a.virtual_server_id = %s and a.id = b.server_app_id ''' elif server_type == '1': sql = ''' SELECT b.log_dir,b.id from cmdb_server_app a , -- server—app的中间表 op_app_logdir b -- app日志目录表 where a.app_id = %s and a.server_type = %s and a.physical_server_id = %s and a.id = b.server_app_id ''' try: res_dir = self._cursorQuery(sql, [app_id, server_type, server_id]) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return '' else: if len(res_dir) == 0: runlog.error( "[ERROR] --no found the logdir-----, Catch exception:, file: [ %s ], line: [ %s ]" % (__file__, sys._getframe().f_lineno)) # print('logdir is nonononononono') return '' return res_dir
def AppConfigDetail(self, server_type, app_id, server_id, env_id, project_id): # 查找app的 # 根据项目、环境、应用、ip对对应的部署在此机器上的应用信息 if server_type == '2': sql = ''' select p.code,de.install_user, e.type_app,de.app_dir, de.pkgname,de.server_port,e.name, de.ssh_pass,de.ssh_port,de.ssh_user from cmdb_server_app de, -- 服务器-app中间表 cmdb_env_server hd, -- 服务器-环境中间表 cmdb_env h, -- 环境表 cmdb_project p, -- 项目表 cmdb_app e -- app表 where de.app_id = %s and de.app_id=e.id and de.virtual_server_id = %s and hd.virtual_server_id=de.virtual_server_id and h.env_type=%s and h.id=hd.env_id and p.id=%s ''' elif server_type == '1': sql = ''' select p.code,de.install_user, e.type_app,de.app_dir, de.pkgname,de.server_port,e.name, de.ssh_pass,de.ssh_port,de.ssh_user from cmdb_server_app de, -- 服务器-app中间表 cmdb_env_server hd, -- 服务器-环境中间表 cmdb_env h, -- 环境表 cmdb_project p, -- 项目表 cmdb_app e -- app表 where de.app_id = %s and de.app_id=e.id and de.physical_server_id = %s and hd.physical_server_id=de.physical_server_id and h.env_type=%s and h.id=hd.env_id and p.id=%s ''' else: # print('--wrong-server_type---->\033[42;1m\033[0m') runlog.error( "[ERROR] --invalid-server_type-----, Catch exception:, file: [ %s ], line: [ %s ]" % (__file__, sys._getframe().f_lineno)) return ['', False] try: res = self._cursorQuery(sql, [app_id, server_id, env_id, project_id]) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ],sql:[%s]" % (e, __file__, sys._getframe().f_lineno, sql)) return ['', False] if len(res) == 0: # print('*****wrong action args....') dblog.error( "[ERROR]--invalid-action args-----, Catch exception:, file: [ %s ], line: [ %s ]" % (__file__, sys._getframe().f_lineno)) return ['', False] return [res, True]
def getNavInfo(self): # 通过用户id,系统id来获取导航 id = self.user.id for j in self.data: code = j['code'] print '2222222', code sql = '''select DISTINCT d.id, d.navname, d.url, d.icon from auth_user a, op_app_group_user ab, op_app_group b, op_app_group_permission bc, op_app_permission c, op_app_nav d, op_app_permission_nav cd where a.id=%s and a.id=ab.user_id and ab.group_id=b.id and b.id=bc.group_id and bc.permission_id=c.id and c.id=cd.permission_id and cd.nav_id=d.id and d.pid = (select dd.id from op_app_nav dd where dd.code=%s)''' try: res = self._cursorQuery(sql, [id, code]) print 'navinfo!!!!!', res if len(res) == 0: dblog.error( 'navinfo is None , file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return [] except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return [] else: r_list = [] for i in range(len(res)): dic = dict() dic['id'] = res[i][0] dic['text'] = res[i][1] dic['url'] = res[i][2] dic['iconCls'] = res[i][3] r_list.append(dic) j['children'] = r_list print('<------>\033[32;1m%s\033[0m' % r_list) # dblog.info("nav_data last: %s,file: [ %s ], line: [ %s ]" % ( # json.dumps(self.data, indent=4), __file__, sys._getframe().f_lineno)) #print('navinfo------>\033[32;1m%s\033[0m' %self.data) return self.data # if __name__ == '__main__': # m_db = DbBaseModelClass() # sql = 'select * from book_info limit 1' # ret = m_db._cursorQuery(sql, []) # print('ret:', ret)
def getProject_info(self, final_list): in_p = ', '.join((map(lambda x: '%s', final_list))) sql = '''select p.id, p.name, p.code, j.icon from cmdb_project p, op_app_nav j -- 项目表 where p.code=j.code and p.code in (%s)''' try: data = self._cursorQuery(sql % in_p, final_list) # dblog.info( # 'datajiaoji is: %s, file: [ %s ], line: [ %s ]' % (data, __file__, sys._getframe().f_lineno)) return data except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return ''
def getProjectNavinfoFromNavTable(self, id): sql = '''select DISTINCT f.code from auth_user a , -- 用户表 op_app_group g, -- 组表 op_app_group_user ag, -- 用户-组-中间表 op_app_permission c, -- 权限表 op_app_group_permission cg, -- 权限-组-中间表 op_app_nav f ,-- 导航表 op_app_permission_nav cf -- 导航-权限-中间表 where a.id = %s and a.id=ag.user_id and ag.group_id=g.id and g.id=cg.group_id and cg.permission_id=c.id and c.id=cf.permission_id and cf.nav_id=f.id and f.pid=0''' try: data = self._cursorQuery(sql, [id]) return data except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return ''
def getAccessServerInfo(self): ''' 根据用户id 获取能访问的机器信息 :return: [[server_type, server_id], [2, 10], [1, 11]] ''' ret_lst = [] sql = ''' SELECT t6.server_type, t6.physical_server_id, t6.virtual_server_id FROM auth_user t1, -- 用户表 op_app_group_user t2, -- 用户-用户组中间表 op_app_group t3, -- 用户组表 op_app_group_permission t4, -- 用户组权限中间表 op_app_permission t5, -- 用户权限表 op_app_permission_server t6 WHERE t1.id=%s AND t1.id=t2.user_id AND t2.group_id=t3.id AND t3.id=t4.group_id AND t4.permission_id=t5.id AND t5.id=t6.permission_id ''' try: data = self._cursorQuery(sql, [self.uid]) except Exception as e: dblog.error('Catch error: [ %s ], file: [ %s ], line: [ %s ]' % (e, __file__, sys._getframe().f_lineno)) return ret_lst else: if len(data) == 0: dblog.error('Get data is null, file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return ret_lst for e_data in data: # print('server_type:', e_data[0]) # print('physical_server_id:', e_data[1]) # print('virtual_server_id:', e_data[2]) if e_data[1] is None: ret_lst.append([int(e_data[0]), int(e_data[2])]) else: ret_lst.append([int(e_data[0]), int(e_data[1])]) return ret_lst
def getProjectInfo(self): '''# 1.先根据用户-组-权限-机器-应用-菜单来获取系统的菜单表,具体是先获取服务器的类型1为物理机,2为虚拟机 2.在根据用户-组-权限-菜单来获取菜单,然后将2个获取的菜单合并展示出最后的菜单表 3.根据菜单表来获取对应的nav导航 :return:返回的格式是一个字典 {} ''' dblog.info( "Enter getProjectInfo successed,file: [ %s ], line: [ %s ]" % (__file__, sys._getframe().f_lineno)) r_list = [] r_list_final = [] id = self.user.id print('9999999999999', id) sql = ''' SELECT DISTINCT t6.server_type, t6.virtual_server_id, t6.physical_server_id FROM `auth_user` t1, -- 用户表 `op_app_group_user` t2, -- 用户-组-中间表 `op_app_group` t3, -- 用户组表 `op_app_group_permission` t4, -- 组-权限中间表 `op_app_permission` t5, -- 权限表 `op_app_permission_server` t6 -- 权限-服务器中间表 WHERE t1.id=%s AND t1.id=t2.user_id AND t2.group_id=t3.id AND t3.id=t4.group_id AND t4.permission_id=t5.id AND t5.id=t6.permission_id''' try: data = self._cursorQuery(sql, [id]) print('<------>\033[32;1m%s\033[0m' % len(data)) dblog.info('data is: %s, file: [ %s ], line: [ %s ]' % (data, __file__, sys._getframe().f_lineno)) if len(data) == 0: dblog.error( 'project data is None , file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return [] for v in data: if int(v[0]) == 2: # 虚拟机 sql = '''select f.code from auth_user a, -- 用户表 op_app_group_user ab, -- 用户-组-中间表 op_app_group b, -- 用户组表 op_app_permission c, -- 权限表 op_app_group_permission bc , -- 权限-组-中间表 cmdb_virtual_server d, -- 虚拟服务器表 op_app_permission_server cd, -- 权限-服务器-中间表 cmdb_server_app de, -- 服务器-app-中间表 cmdb_app e,-- app表 cmdb_project f -- 项目表 where a.id = %s and a.id =ab.user_id and ab.group_id=b.id and b.id=bc.group_id and bc.permission_id=c.id and c.id=cd.permission_id and cd.virtual_server_id=d.id and d.id=de.virtual_server_id and de.app_id=e.id and e.project_id=f.id''' try: data = self._cursorQuery(sql, [id]) dblog.info('data2 is: %s, file: [ %s ], line: [ %s ]' % (data, __file__, sys._getframe().f_lineno)) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) else: for i in data: # dic1 = dict() # dic1['id'] = data[i][0] # dic1['text'] = data[i][1] # dic1['code'] = data[i][2] # print data[i][1] # if dic1 not in r_list: r_list.append(i[0]) # print('<------>\033[32;1m%s\033[0m' %r_list) else: sql = ''' select f.code from auth_user a, -- 用户表 op_app_group_user ab, -- 用户-组-中间表 op_app_group b, -- 用户组 op_app_permission c, -- 权限表 op_app_group_permission bc, -- 组-权限-中间表 cmdb_physical_server d, -- 物理服务器表 op_app_permission_server cd,-- 权限-服务器-中间表 cmdb_server_app de, -- app-服务器-中间表 cmdb_app e, -- app表 cmdb_project f -- 项目表 where a.id=%s and ab.user_id=a.id and b.id=bc.group_id and c.id=bc.permission_id and c.id=cd.permission_id and cd.physical_server_id=d.id=de.physical_server_id and de.app_id=e.id and e.project_id=f.id''' try: data = self._cursorQuery(sql, [id]) print('-----9999', data) dblog.info('data1 is: %s, file: [ %s ], line: [ %s ]' \ % (data, __file__, sys._getframe().f_lineno)) except Exception as e: dblog.error("[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]"\ %(e, __file__, sys._getframe().f_lineno)) else: if len(data) > 0: for i in data: # dic2 = dict() # dic2['id'] = data[i][0] # dic2['text'] = data[i][1] # dic2['code'] = data[i][2] # if dic2 not in r_list: r_list.append(i[0]) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) # 通过user-组-权限-机器-应用-系统来获取对应的系统列表 m_list = [] sql = '''select DISTINCT f.code from auth_user a , -- 用户表 op_app_group g, -- 组表 op_app_group_user ag, -- 用户-组-中间表 op_app_permission c, -- 权限表 op_app_group_permission cg, -- 权限-组-中间表 op_app_nav f ,-- 导航表 op_app_permission_nav cf -- 导航-权限-中间表 where a.id = %s and a.id=ag.user_id and ag.group_id=g.id and g.id=cg.group_id and cg.permission_id=c.id and c.id=cf.permission_id and cf.nav_id=f.id and f.pid=0''' try: data = self._cursorQuery(sql, [id]) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) else: if len(data) < 0: dblog.info('data is None , file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return [] for v in data: m_list.append(v[0]) # 对2个获取的项目code进行求交集,然后去找对应的导航 r_set = set(r_list) m_set = set(m_list) final_set = r_set.intersection(m_set) # final_set = set([u'CAP']) # print('<r_set------>\033[34;1m%s\033[0m' % r_set) # print('<m_set------>\033[34;1m%s\033[0m' % m_set) # print('<final_set------>\033[34;1m%s\033[0m' % final_set) final_list = list(final_set) # print('<final_list------>\033[34;1m%s\033[0m' % final_list) # final_list = ",".join(["'%s'"%x for x in final_list]) # final_list = '('+final_list+')' # print('<final_list------>\033[34;1m%s\033[0m' % final_list) # args = tuple(final_list) # print('<final_tuple------>\033[34;1m%s\033[0m' % args) if len(final_list) == 0: print('no intersection--') return [] # for i in final_list: in_p = ', '.join((map(lambda x: '%s', final_list))) sql = '''select p.id, p.name, p.code, j.icon from cmdb_project p, op_app_nav j -- 项目表 where p.code=j.code and p.code in (%s)''' try: data = self._cursorQuery(sql % in_p, final_list) dblog.info('datajiaoji is: %s, file: [ %s ], line: [ %s ]' % (data, __file__, sys._getframe().f_lineno)) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return [] else: if data is None: dblog.error('data is None , file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return [] for j in data: dic = dict() dic['id'] = j[0] dic['text'] = j[1] dic['code'] = j[2] dic['iconCls'] = j[3] r_list_final.append(dic) return r_list_final
def getProjectInfo(self): '''# :return:返回的格式是一个字典 ''' # 先查找出所在服务器的类型,虚拟机or物理机 sql = '''select DISTINCT de.server_type from cmdb_project p, -- 项目表 cmdb_app e , -- APP表 cmdb_server_app de -- 服务器-app-中间表 where e.project_id= p.id and e.id=de.app_id and p.code= (select aa.code from op_app_nav aa where aa.id= (SELECT a.pid from op_app_nav a where a.id=%s))''' try: server_type = self._cursorQuery(sql, [self.nav_id]) print '!!!!!server_type :', server_type except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) if len(server_type) == 0: print('wrong server_type11') return '' res1 = () res2 = () for i in server_type: env_list = [] app_list = [] if int(i[0]) == 2: #虚拟机 sql = ''' select DISTINCT p.name,p.`code`,p.id as project_id,h.id as env_id, e.id as app_id,e.`name`,h.env_type from cmdb_project p, -- 项目表 cmdb_app e , -- APP表 cmdb_server_app de , -- 服务器-app-中间表 cmdb_virtual_server d, -- 虚拟机 cmdb_env h, -- 环境表 cmdb_env_server hd -- 环境-服务器-中间表 where e.project_id= p.id and e.id=de.app_id and d.id=de.virtual_server_id and d.id=hd.virtual_server_id and hd.env_id=h.id and p.code= (select aa.code from op_app_nav aa where aa.id= (SELECT a.pid from op_app_nav a where a.id=%s)) ''' try: res1 = self._cursorQuery(sql, [self.nav_id]) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) if len(res1) == 0: print('wrong server_info-res1') return '' # print('res111',res1,type(res1)) else: sql = ''' select DISTINCT p.name,p.`code`,p.id as project_id,h.id as env_id, e.id as app_id,e.`name`,h.env_type from cmdb_project p, -- 项目表 cmdb_app e , -- APP表 cmdb_server_app de , -- 服务器-app-中间表 cmdb_physical_server d, -- 物理机 cmdb_env h, -- 环境表 cmdb_env_server hd -- 环境-服务器-中间表 where e.project_id= p.id and e.id=de.app_id and d.id=de.physical_server_id and d.id=hd.physical_server_id and hd.env_id=h.id and p.code= (select aa.code from op_app_nav aa where aa.id= (SELECT a.pid from op_app_nav a where a.id=%s)) ''' try: res2 = self._cursorQuery(sql, [self.nav_id]) print('res2------', res2) except Exception as e: dblog.error( "[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) if len(res2) == 0: print('wrong server_info-res2') return '' res1 += res2 # print('whole-res,',res1) v_dic = dict() for v in res1: v_dic['project_name'] = v[0] v_dic['project_code'] = v[1] v_dic['project_id'] = v[2] app_dic = dict() app_dic['id'] = v[4] app_dic['name'] = v[5] env_dic = dict() env_dic['id'] = v[6] env_id = v[6] env_dic['selected'] = 0 env_type_choices = { '1': 'dev', '2': 'sit', '3': 'uat', '4': 'pre', '5': 'prd', } if env_id in env_type_choices: env_dic['name'] = env_type_choices[env_id] if env_dic not in env_list: env_list.append(env_dic) # print('<FFFFFFFFFFFFFF------>\033[32;1m%s\033[0m' % env_list) if app_dic not in app_list: app_list.append(app_dic) # 如果用户有多个环境类型的权限,把第一个环境类型设为默认select = 0 env_list[0]['selected'] = 1 v_dic['envs'] = env_list v_dic['apps'] = app_list # print('<DDDDDDDDDDDD------>\033[31;1m%s\033[0m' % v_dic) # dblog.info("v_dic88888 last: %s,file: [ %s ], line: [ %s ]" % ( # json.dumps(v_dic, indent=4), __file__, sys._getframe().f_lineno)) return v_dic
def getHostInfo(self): '''# 先获取服务器的类型1为物理机,2为虚拟机 :return:返回的格式是一个字典 ''' r_list = [] user_id = self.request.user.id project_id = self.request.GET.get('project_id', '') env_id = self.request.GET.get('env_id', '') # 环境类型的id -1.dev,2.sit app_id = self.request.GET.get('app_id', '') # 应用id # print('project_id--userid--env_id,app_id',project_id,user_id,env_id,app_id) if project_id == '' or env_id == '' or app_id == '': dblog.error('wrong args from web, file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return [] # 先查询出服务器类型 sql = '''SELECT DISTINCT ab.server_type from cmdb_app a, cmdb_server_app ab where a.id=%s and a.id=ab.app_id''' try: data = self._cursorQuery(sql, [app_id]) except Exception as e: dblog.error("[ERROR] Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" \ % (e, __file__, sys._getframe().f_lineno)) return [] else: if len(data) == 0: dblog.error('Data is null, file: [ %s ], line: [ %s ]' % (__file__, sys._getframe().f_lineno)) return [] for v in data: if int(v[0]) == 2: # 虚拟机,获取虚拟机的ip,责任人信息 sql = '''select ip.sys_ip,u.user_name,h.name,hd.server_type,hd.virtual_server_id from auth_user a, -- 用户表 op_app_group b, -- 组表 op_app_group_user ab, -- 用户-组-中间表 op_app_permission c, -- 权限表 op_app_group_permission bc, -- 权限- 组-中间表 op_app_permission_server cd , -- 权限-服务器-中间表 cmdb_virtual_server d, -- 虚拟服务器表 cmdb_app e , -- app表 cmdb_server_app de, -- 服务器 - app-中间表 cmdb_project p, -- 项目表 cmdb_user_info u, -- 用户详情表 cmdb_ip ip, -- ip表 cmdb_env h , -- 环境信息表 cmdb_env_server hd -- 环境-服务器中间表 where a.id=%s and a.id=ab.user_id and ab.group_id = b.id and b.id=bc.group_id and bc.permission_id=c.id and c.id=cd.permission_id and cd.server_type=2 and cd.virtual_server_id=d.id and d.id=de.virtual_server_id and de.app_id=e.id and e.id= %s and e.project_id=p.id and p.project_manager=u.only_id and d.ip_id=ip.id and h.env_type=%s and h.id=hd.env_id and d.id=hd.virtual_server_id''' try: data2 = self._cursorQuery(sql, [user_id, app_id, env_id]) except Exception as e: dblog.error( "Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return [] else: if len(data2) == 0: dblog.error( "Data2 is null virtualserver ip fail or no permissions, \ file: [ %s ], line: [ %s ]" % (__file__, sys._getframe().f_lineno)) return [] for v_data2 in data2: dic1 = dict() dic1['ip'] = v_data2[0] dic1['manager'] = v_data2[1] dic1['env_name'] = v_data2[2] dic1['server_type'] = v_data2[3] dic1['server_id'] = v_data2[4] r_list.append(dic1) else: # 如果是物理服务器 sql = '''select u.user_name,ip.sys_ip,hd.server_type,hd.physical_server_id from auth_user a, -- 用户表 op_app_group b, -- 组表 op_app_group_user ab, -- 用户-组-中间表 op_app_permission c, -- 权限表 op_app_group_permission bc, -- 权限- 组-中间表 op_app_permission_server cd , -- 权限-服务器-中间表 cmdb_physical_server d, -- 虚拟服务器表 cmdb_app e , -- app表 cmdb_server_app de, -- 服务器 - app-中间表 cmdb_project p, -- 项目表 cmdb_user_info u, -- 用户详情表 cmdb_ip ip, -- ip表 cmdb_env h , -- 环境信息表 cmdb_env_server hd -- 环境-服务器中间表 where a.id=%s and a.id=ab.user_id and ab.group_id = b.id and b.id=bc.group_id and bc.permission_id=c.id and c.id=cd.permission_id and cd.server_type=1 and cd.physical_server_id=d.id and d.id=de.physical_server_id and de.app_id=e.id and e.id= %s and e.project_id=p.id and p.project_manager=u.only_id and d.ip_id=ip.id and h.env_type=%s and h.id=hd.env_id and hd.physical_server_id = d.id ''' try: data3 = self._cursorQuery(sql, [user_id, app_id, env_id]) except Exception as e: dblog.error( "Query error, Catch exception:[ %s ], file: [ %s ], line: [ %s ]" % (e, __file__, sys._getframe().f_lineno)) return [] for v_data3 in data3: dic2 = dict() dic2['ip'] = v_data3[0] dic2['manager'] = v_data3[1] dic2['env_name'] = env_id dic2['server_type'] = v_data3[3] dic2['server_id'] = v_data3[4] r_list.append(dic2) return r_list