Exemplo n.º 1
0
Arquivo: views.py Projeto: zqwlai/oms
    def update_template(self, request):
        print request.POST.dict()
        template_id = int(request.POST['template_id'])
        parent_id = int(request.POST['parent_id'])
        name = request.POST['name']
        group_ids = request.POST.getlist('group_ids[]')
        #先更新模板基本信息
        f = Falcon(request.user.username)
        result = f.update_template(template_id, parent_id, name)
        if result.has_key('error'):
            return JsonResponse({
                'code': 1,
                'data': '',
                'message': result['error']
            })
        #再更新机器组
        hostgroups = f.get_hostgroups_of_template(template_id)  # 当前模板下已关联的机器组
        old_hostgroup_ids = [i['id'] for i in hostgroups['hostgroups']]
        current_hostgroup_ids = [int(i) for i in group_ids]

        need_add_hostgroup_ids = list(
            set(current_hostgroup_ids).difference(old_hostgroup_ids))
        need_remove_hostgroup_ids = list(
            set(old_hostgroup_ids).difference(current_hostgroup_ids))
        for i in need_add_hostgroup_ids:
            f.bindTemplate2HostGroup(template_id, i)
        for i in need_remove_hostgroup_ids:
            f.unbindTemplate2HostGroup(template_id, i)
        return JsonResponse({'code': 0, 'data': '', 'message': 'ok'})
Exemplo n.º 2
0
Arquivo: views.py Projeto: zqwlai/oms
 def view(self, request):
     template_id = request.GET['id']
     f = Falcon()
     hostgroups = f.get_hostgroups_of_template(template_id)  #当前模板下已关联的机器组
     current_hostgroup_ids = [i['id'] for i in hostgroups['hostgroups']]
     template_info = f.get_template_info(template_id)
     print template_info
     cur_uic = template_info['action']['uic']
     return render(request, 'alarm/template_view.html', locals())
Exemplo n.º 3
0
Arquivo: views.py Projeto: zqwlai/oms
 def update(self, request):
     template_id = request.GET['id']
     f = Falcon()
     hostgroups = f.get_hostgroups_of_template(template_id)  #当前模板下已关联的机器组
     current_hostgroup_ids = [i['id'] for i in hostgroups['hostgroups']]
     template_info = f.get_template_info(template_id)
     print template_info
     all_template_list = f.get_all_template_list()
     all_template_list = all_template_list['templates']
     print all_template_list
     all_hostgroup_list = f.get_all_hostgroup_list()
     op_list = ['==', '!=', '<', '<=', '>', '>=']
     cur_uic = template_info['action']['uic']
     cur_uic_list = cur_uic.split(',')
     all_uic = f.query_team()
     all_uic_list = [i['team']['name'] for i in all_uic]
     return render(request, 'alarm/template_update.html', locals())