mirror of https://github.com/jumpserver/jumpserver
fix bugs
parent
0c0f05b6d9
commit
159398b391
|
@ -1,4 +1,6 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
|
import xlsxwriter
|
||||||
|
|
||||||
from jumpserver.api import *
|
from jumpserver.api import *
|
||||||
|
|
||||||
|
|
||||||
|
@ -171,3 +173,62 @@ def db_asset_update(**kwargs):
|
||||||
# else:
|
# else:
|
||||||
# return httperror(request, '删除失败, 没有这个IDC!')
|
# return httperror(request, '删除失败, 没有这个IDC!')
|
||||||
|
|
||||||
|
|
||||||
|
SERVER_STATUS = {1: u"已安装系统", 2: u"未安装系统", 3: u"正在安装系统", 4: u"报废"}
|
||||||
|
now = datetime.datetime.now().strftime('%Y_%m_%d_%H_%M')
|
||||||
|
file_name = 'cmdb_excel_' + now + '.xlsx'
|
||||||
|
workbook = xlsxwriter.Workbook('static/excels/%s' % file_name)
|
||||||
|
worksheet = workbook.add_worksheet('CMDB数据')
|
||||||
|
worksheet.set_first_sheet()
|
||||||
|
worksheet.set_column('A:Z', 15)
|
||||||
|
|
||||||
|
|
||||||
|
def write_excel(hosts):
|
||||||
|
data = []
|
||||||
|
title = [u'主机名', u'IP', u'IDC', u'MAC', u'远控IP', u'CPU', u'内存', u'硬盘', u'操作系统', u'机柜位置',
|
||||||
|
u'资产编号', u'所属业务', u'机器状态', u'SN', u'运行服务', u'备注']
|
||||||
|
for host in hosts:
|
||||||
|
projects_list, services_list = [], []
|
||||||
|
for p in host.project.all():
|
||||||
|
projects_list.append(p.name)
|
||||||
|
for s in host.service.all():
|
||||||
|
print s.name, s.port
|
||||||
|
services_list.append(s.name + '-' + str(s.port))
|
||||||
|
projects = '/'.join(projects_list)
|
||||||
|
services = '/'.join(services_list)
|
||||||
|
status = SERVER_STATUS.get(int(host.status))
|
||||||
|
info = [host.hostname, host.eth1, host.idc.name, host.mac, host.remote_ip, host.cpu, host.memory,
|
||||||
|
host.disk, host.system_type, host.cabinet, host.number, projects, status,
|
||||||
|
host.sn, services, host.comment]
|
||||||
|
data.append(info)
|
||||||
|
print data
|
||||||
|
format = workbook.add_format()
|
||||||
|
format.set_border(1)
|
||||||
|
format.set_align('center')
|
||||||
|
|
||||||
|
format_title = workbook.add_format()
|
||||||
|
format_title.set_border(1)
|
||||||
|
format_title.set_bg_color('#cccccc')
|
||||||
|
format_title.set_align('center')
|
||||||
|
format_title.set_bold()
|
||||||
|
|
||||||
|
format_ave = workbook.add_format()
|
||||||
|
format_ave.set_border(1)
|
||||||
|
format_ave.set_num_format('0.00')
|
||||||
|
|
||||||
|
worksheet.write_row('A1', title, format_title)
|
||||||
|
i = 2
|
||||||
|
for info in data:
|
||||||
|
location = 'A' + str(i)
|
||||||
|
worksheet.write_row(location, info, format)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
workbook.close()
|
||||||
|
ret = (True, file_name)
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def sort_ip_list(ip_list):
|
||||||
|
""" ip地址排序 """
|
||||||
|
ip_list.sort(key=lambda s: map(int, s.split('.')))
|
||||||
|
return ip_list
|
|
@ -4,6 +4,23 @@ import datetime
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from juser.models import User, UserGroup
|
from juser.models import User, UserGroup
|
||||||
|
|
||||||
|
ENVIRONMENT = (
|
||||||
|
(0, U'生产环境'),
|
||||||
|
(1, U'测试环境')
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSET_STATUS = (
|
||||||
|
(0, u"已使用"),
|
||||||
|
(1, u"未使用"),
|
||||||
|
(2, u"报废")
|
||||||
|
)
|
||||||
|
|
||||||
|
ASSET_TYPE = (
|
||||||
|
(0, u"服务器"),
|
||||||
|
(2, u"网络设备"),
|
||||||
|
(3, u"其他")
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class AssetGroup(models.Model):
|
class AssetGroup(models.Model):
|
||||||
GROUP_TYPE = (
|
GROUP_TYPE = (
|
||||||
|
@ -83,21 +100,6 @@ class Asset(models.Model):
|
||||||
"""
|
"""
|
||||||
asset modle
|
asset modle
|
||||||
"""
|
"""
|
||||||
ENVIRONMENT = (
|
|
||||||
(0, U'生产环境'),
|
|
||||||
(1, U'测试环境')
|
|
||||||
)
|
|
||||||
SERVER_STATUS = (
|
|
||||||
(0, u"已使用"),
|
|
||||||
(1, u"未使用"),
|
|
||||||
(2, u"报废")
|
|
||||||
)
|
|
||||||
ASSET_TYPE = (
|
|
||||||
(0, u"服务器"),
|
|
||||||
(2, u"网络设备"),
|
|
||||||
(3, u"其他")
|
|
||||||
)
|
|
||||||
|
|
||||||
ip = models.IPAddressField(unique=True, verbose_name=u"主机IP")
|
ip = models.IPAddressField(unique=True, verbose_name=u"主机IP")
|
||||||
second_ip = models.CharField(max_length=255, blank=True, null=True, verbose_name=u"其他IP")
|
second_ip = models.CharField(max_length=255, blank=True, null=True, verbose_name=u"其他IP")
|
||||||
hostname = models.CharField(max_length=64, blank=True, null=True, verbose_name=u"主机名")
|
hostname = models.CharField(max_length=64, blank=True, null=True, verbose_name=u"主机名")
|
||||||
|
@ -118,7 +120,7 @@ class Asset(models.Model):
|
||||||
cabinet = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机柜号')
|
cabinet = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机柜号')
|
||||||
position = models.IntegerField(max_length=2, blank=True, null=True, verbose_name=u'机器位置')
|
position = models.IntegerField(max_length=2, blank=True, null=True, verbose_name=u'机器位置')
|
||||||
number = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'资产编号')
|
number = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'资产编号')
|
||||||
status = models.IntegerField(max_length=2, choices=SERVER_STATUS, blank=True, null=True, default=1, verbose_name=u"机器状态")
|
status = models.IntegerField(max_length=2, choices=ASSET_STATUS, blank=True, null=True, default=1, verbose_name=u"机器状态")
|
||||||
asset_type = models.IntegerField(max_length=2, choices=ASSET_TYPE, blank=True, null=True, verbose_name=u"主机类型")
|
asset_type = models.IntegerField(max_length=2, choices=ASSET_TYPE, blank=True, null=True, verbose_name=u"主机类型")
|
||||||
env = models.IntegerField(max_length=2, choices=ENVIRONMENT, blank=True, null=True, verbose_name=u"运行环境")
|
env = models.IntegerField(max_length=2, choices=ENVIRONMENT, blank=True, null=True, verbose_name=u"运行环境")
|
||||||
sn = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"SN编号")
|
sn = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"SN编号")
|
||||||
|
@ -129,22 +131,6 @@ class Asset(models.Model):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.ip
|
return self.ip
|
||||||
|
|
||||||
def get_user(self):
|
|
||||||
perm_list = []
|
|
||||||
asset_group_all = self.bis_group.all()
|
|
||||||
for asset_group in asset_group_all:
|
|
||||||
perm_list.extend(asset_group.perm_set.all())
|
|
||||||
|
|
||||||
user_group_list = []
|
|
||||||
for perm in perm_list:
|
|
||||||
user_group_list.append(perm.user_group)
|
|
||||||
|
|
||||||
user_permed_list = []
|
|
||||||
for user_group in user_group_list:
|
|
||||||
user_permed_list.extend(user_group.user_set.all())
|
|
||||||
user_permed_list = list(set(user_permed_list))
|
|
||||||
return user_permed_list
|
|
||||||
|
|
||||||
|
|
||||||
class AssetAlias(models.Model):
|
class AssetAlias(models.Model):
|
||||||
user = models.ForeignKey(User)
|
user = models.ForeignKey(User)
|
||||||
|
|
|
@ -12,6 +12,7 @@ urlpatterns = patterns('',
|
||||||
url(r'^asset_del/$', asset_del),
|
url(r'^asset_del/$', asset_del),
|
||||||
url(r"^asset_detail/$", asset_detail),
|
url(r"^asset_detail/$", asset_detail),
|
||||||
url(r'^asset_edit/$', asset_edit),
|
url(r'^asset_edit/$', asset_edit),
|
||||||
|
url(r'^asset_search/$', asset_search),
|
||||||
# url(r'^search/$', host_search),
|
# url(r'^search/$', host_search),
|
||||||
# url(r"^host_detail/$", host_detail),
|
# url(r"^host_detail/$", host_detail),
|
||||||
# url(r"^dept_host_ajax/$", dept_host_ajax),
|
# url(r"^dept_host_ajax/$", dept_host_ajax),
|
||||||
|
|
398
jasset/views.py
398
jasset/views.py
|
@ -9,6 +9,7 @@ from django.shortcuts import get_object_or_404
|
||||||
from jasset.asset_api import *
|
from jasset.asset_api import *
|
||||||
from jumpserver.api import *
|
from jumpserver.api import *
|
||||||
from jasset.forms import AssetForm
|
from jasset.forms import AssetForm
|
||||||
|
from jasset.models import Asset, IDC, AssetGroup, ASSET_TYPE, ASSET_STATUS
|
||||||
|
|
||||||
|
|
||||||
@require_role('admin')
|
@require_role('admin')
|
||||||
|
@ -165,119 +166,6 @@ def asset_add(request):
|
||||||
esg = u'主机 %s 添加失败' % ip
|
esg = u'主机 %s 添加失败' % ip
|
||||||
|
|
||||||
return my_render('jasset/asset_add.html', locals(), request)
|
return my_render('jasset/asset_add.html', locals(), request)
|
||||||
#
|
|
||||||
#
|
|
||||||
# @require_admin
|
|
||||||
# def host_add_batch(request):
|
|
||||||
# """ 批量添加主机 """
|
|
||||||
# header_title, path1, path2 = u'批量添加主机', u'资产管理', u'批量添加主机'
|
|
||||||
# login_types = {'LDAP': 'L', 'MAP': 'M'}
|
|
||||||
# active_types = {'激活': 1, '禁用': 0}
|
|
||||||
# dept_id = get_user_dept(request)
|
|
||||||
# if request.method == 'POST':
|
|
||||||
# multi_hosts = request.POST.get('j_multi').split('\n')
|
|
||||||
# for host in multi_hosts:
|
|
||||||
# if host == '':
|
|
||||||
# break
|
|
||||||
# j_ip, j_port, j_type, j_idc, j_groups, j_depts, j_active, j_comment = host.split()
|
|
||||||
# j_active = active_types[str(j_active)]
|
|
||||||
# j_group = ast.literal_eval(j_groups)
|
|
||||||
# j_dept = ast.literal_eval(j_depts)
|
|
||||||
#
|
|
||||||
# if j_type not in ['LDAP', 'MAP']:
|
|
||||||
# return httperror(request, u'没有%s这种登录方式!' %j_type)
|
|
||||||
#
|
|
||||||
# j_type = login_types[j_type]
|
|
||||||
# idc = IDC.objects.filter(name=j_idc)
|
|
||||||
# if idc:
|
|
||||||
# j_idc = idc[0].id
|
|
||||||
# else:
|
|
||||||
# return httperror(request, '添加失败, 没有%s这个IDC' % j_idc)
|
|
||||||
#
|
|
||||||
# group_ids, dept_ids = [], []
|
|
||||||
# for group_name in j_group:
|
|
||||||
# group = BisGroup.objects.filter(name=group_name)
|
|
||||||
# if group:
|
|
||||||
# group_id = group[0].id
|
|
||||||
# else:
|
|
||||||
# return httperror(request, '添加失败, 没有%s这个主机组' % group_name)
|
|
||||||
# group_ids.append(group_id)
|
|
||||||
#
|
|
||||||
# for dept_name in j_dept:
|
|
||||||
# dept = DEPT.objects.filter(name=dept_name)
|
|
||||||
# if dept:
|
|
||||||
# dept_id = dept[0].id
|
|
||||||
# else:
|
|
||||||
# return httperror(request, '添加失败, 没有%s这个部门' % dept_name)
|
|
||||||
# dept_ids.append(dept_id)
|
|
||||||
#
|
|
||||||
# if is_group_admin(request) and not validate(request, asset_group=group_ids, edept=dept_ids):
|
|
||||||
# return httperror(request, '添加失败, 没有%s这个主机组' % group_name)
|
|
||||||
#
|
|
||||||
# if Asset.objects.filter(ip=str(j_ip)):
|
|
||||||
# return httperror(request, '添加失败, 改IP%s已存在' % j_ip)
|
|
||||||
#
|
|
||||||
# host_info = [j_ip, j_port, j_idc, j_type, group_ids, dept_ids, j_active, j_comment]
|
|
||||||
# db_host_insert(host_info)
|
|
||||||
#
|
|
||||||
# smg = u'批量添加添加成功'
|
|
||||||
# return my_render('jasset/host_add_multi.html', locals(), request)
|
|
||||||
#
|
|
||||||
# return my_render('jasset/host_add_multi.html', locals(), request)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# @require_admin
|
|
||||||
# def host_edit_batch(request):
|
|
||||||
# """ 批量修改主机 """
|
|
||||||
# if request.method == 'POST':
|
|
||||||
# len_table = request.POST.get('len_table')
|
|
||||||
# for i in range(int(len_table)):
|
|
||||||
# j_id = "editable[" + str(i) + "][j_id]"
|
|
||||||
# j_ip = "editable[" + str(i) + "][j_ip]"
|
|
||||||
# j_port = "editable[" + str(i) + "][j_port]"
|
|
||||||
# j_dept = "editable[" + str(i) + "][j_dept]"
|
|
||||||
# j_idc = "editable[" + str(i) + "][j_idc]"
|
|
||||||
# j_type = "editable[" + str(i) + "][j_type]"
|
|
||||||
# j_group = "editable[" + str(i) + "][j_group]"
|
|
||||||
# j_active = "editable[" + str(i) + "][j_active]"
|
|
||||||
# j_comment = "editable[" + str(i) + "][j_comment]"
|
|
||||||
#
|
|
||||||
# j_id = request.POST.get(j_id).strip()
|
|
||||||
# j_ip = request.POST.get(j_ip).strip()
|
|
||||||
# j_port = request.POST.get(j_port).strip()
|
|
||||||
# j_dept = request.POST.getlist(j_dept)
|
|
||||||
# j_idc = request.POST.get(j_idc).strip()
|
|
||||||
# j_type = request.POST.get(j_type).strip()
|
|
||||||
# j_group = request.POST.getlist(j_group)
|
|
||||||
# j_active = request.POST.get(j_active).strip()
|
|
||||||
# j_comment = request.POST.get(j_comment).strip()
|
|
||||||
#
|
|
||||||
# host_info = [j_id, j_ip, j_idc, j_port, j_type, j_group, j_dept, j_active, j_comment]
|
|
||||||
# batch_host_edit(host_info)
|
|
||||||
#
|
|
||||||
# return HttpResponseRedirect('/jasset/host_list/')
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# @require_role(role='user')
|
|
||||||
# def host_edit_common_batch(request):
|
|
||||||
# """ 普通用户批量修改主机别名 """
|
|
||||||
# u = get_session_user_info(request)[2]
|
|
||||||
# if request.method == 'POST':
|
|
||||||
# len_table = request.POST.get('len_table')
|
|
||||||
# for i in range(int(len_table)):
|
|
||||||
# j_id = "editable[" + str(i) + "][j_id]"
|
|
||||||
# j_alias = "editable[" + str(i) + "][j_alias]"
|
|
||||||
# j_id = request.POST.get(j_id, '').strip()
|
|
||||||
# j_alias = request.POST.get(j_alias, '').strip()
|
|
||||||
# a = Asset.objects.get(id=j_id)
|
|
||||||
# asset_alias = AssetAlias.objects.filter(user=u, host=a)
|
|
||||||
# if asset_alias:
|
|
||||||
# asset_alias = asset_alias[0]
|
|
||||||
# asset_alias.alias = j_alias
|
|
||||||
# asset_alias.save()
|
|
||||||
# else:
|
|
||||||
# AssetAlias.objects.create(user=u, host=a, alias=j_alias)
|
|
||||||
# return my_render('jasset/host_list_common.html', locals(), request)
|
|
||||||
|
|
||||||
|
|
||||||
@require_role(role='user')
|
@require_role(role='user')
|
||||||
|
@ -287,6 +175,10 @@ def asset_list(request):
|
||||||
列出资产表
|
列出资产表
|
||||||
"""
|
"""
|
||||||
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
|
header_title, path1, path2 = u'查看主机', u'资产管理', u'查看主机'
|
||||||
|
idc_all = IDC.objects.filter()
|
||||||
|
asset_group_all = AssetGroup.objects.all()
|
||||||
|
asset_type = ASSET_TYPE
|
||||||
|
asset_status = ASSET_STATUS
|
||||||
keyword = request.GET.get('keyword', '')
|
keyword = request.GET.get('keyword', '')
|
||||||
gid = request.GET.get('gid', '') # asset group id
|
gid = request.GET.get('gid', '') # asset group id
|
||||||
sid = request.GET.get('sid', '')
|
sid = request.GET.get('sid', '')
|
||||||
|
@ -309,8 +201,17 @@ def asset_del(request):
|
||||||
asset_id = request.GET.get('id', '')
|
asset_id = request.GET.get('id', '')
|
||||||
if asset_id:
|
if asset_id:
|
||||||
Asset.objects.filter(id=asset_id).delete()
|
Asset.objects.filter(id=asset_id).delete()
|
||||||
return HttpResponse(u'删除成功')
|
|
||||||
return Http404
|
if request.method == 'POST':
|
||||||
|
asset_batch = request.GET.get('arg', '')
|
||||||
|
asset_id_all = str(request.POST.get('asset_id_all', ''))
|
||||||
|
|
||||||
|
if asset_batch:
|
||||||
|
for asset_id in asset_id_all.split(','):
|
||||||
|
asset = get_object(Asset, id=asset_id)
|
||||||
|
asset.delete()
|
||||||
|
|
||||||
|
return HttpResponse(u'删除成功')
|
||||||
|
|
||||||
|
|
||||||
@require_role(role='super')
|
@require_role(role='super')
|
||||||
|
@ -368,56 +269,11 @@ def asset_edit(request):
|
||||||
return my_render('jasset/asset_edit.html', locals(), request)
|
return my_render('jasset/asset_edit.html', locals(), request)
|
||||||
|
|
||||||
|
|
||||||
# @require_role(role='admin')
|
|
||||||
# def host_edit_adm(request):
|
|
||||||
# """ 部门管理员修改主机 """
|
|
||||||
# header_title, path1, path2 = u'修改主机', u'资产管理', u'修改主机'
|
|
||||||
# actives = {1: u'激活', 0: u'禁用'}
|
|
||||||
# login_types = {'L': 'LDAP', 'M': 'MAP'}
|
|
||||||
# eidc = IDC.objects.all()
|
|
||||||
# dept = get_session_user_info(request)[5]
|
|
||||||
# egroup = BisGroup.objects.exclude(name='ALL').filter(dept=dept)
|
|
||||||
# host_id = request.GET.get('id', '')
|
|
||||||
# post = Asset.objects.filter(id=int(host_id))
|
|
||||||
# if post:
|
|
||||||
# post = post[0]
|
|
||||||
# else:
|
|
||||||
# return httperror(request, '没有此主机!')
|
|
||||||
#
|
|
||||||
# e_group = post.bis_group.all()
|
|
||||||
#
|
|
||||||
# if request.method == 'POST':
|
|
||||||
# j_ip = request.POST.get('j_ip')
|
|
||||||
# j_idc = request.POST.get('j_idc')
|
|
||||||
# j_port = request.POST.get('j_port')
|
|
||||||
# j_type = request.POST.get('j_type')
|
|
||||||
# j_dept = request.POST.getlist('j_dept')
|
|
||||||
# j_group = request.POST.getlist('j_group')
|
|
||||||
# j_active = request.POST.get('j_active')
|
|
||||||
# j_comment = request.POST.get('j_comment')
|
|
||||||
#
|
|
||||||
# host_info = [j_ip, j_port, j_idc, j_type, j_group, j_dept, j_active, j_comment]
|
|
||||||
#
|
|
||||||
# if not validate(request, asset_group=j_group, edept=j_dept):
|
|
||||||
# emg = u'修改失败,您无权操作!'
|
|
||||||
# return my_render('jasset/asset_edit.html', locals(), request)
|
|
||||||
#
|
|
||||||
# if j_type == 'M':
|
|
||||||
# j_user = request.POST.get('j_user')
|
|
||||||
# j_password = request.POST.get('j_password')
|
|
||||||
# db_host_update(host_info, j_user, j_password, post)
|
|
||||||
# else:
|
|
||||||
# db_host_update(host_info, post)
|
|
||||||
#
|
|
||||||
# smg = u'主机 %s 修改成功' % j_ip
|
|
||||||
# return HttpResponseRedirect('/jasset/host_detail/?id=%s' % host_id)
|
|
||||||
#
|
|
||||||
# return my_render('jasset/asset_edit.html', locals(), request)
|
|
||||||
|
|
||||||
|
|
||||||
@require_role('admin')
|
@require_role('admin')
|
||||||
def asset_detail(request):
|
def asset_detail(request):
|
||||||
""" 主机详情 """
|
"""
|
||||||
|
主机详情
|
||||||
|
"""
|
||||||
header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情'
|
header_title, path1, path2 = u'主机详细信息', u'资产管理', u'主机详情'
|
||||||
asset_id = request.GET.get('id', '')
|
asset_id = request.GET.get('id', '')
|
||||||
asset = get_object(Asset, id=asset_id)
|
asset = get_object(Asset, id=asset_id)
|
||||||
|
@ -425,146 +281,82 @@ def asset_detail(request):
|
||||||
return my_render('jasset/asset_detail.html', locals(), request)
|
return my_render('jasset/asset_detail.html', locals(), request)
|
||||||
|
|
||||||
|
|
||||||
|
@require_role('user')
|
||||||
|
def asset_search(request):
|
||||||
|
"""
|
||||||
|
主机搜索
|
||||||
|
"""
|
||||||
|
idc_all = IDC.objects.filter()
|
||||||
|
asset_group_all = AssetGroup.objects.all()
|
||||||
|
asset_type = ASSET_TYPE
|
||||||
|
asset_status = ASSET_STATUS
|
||||||
|
|
||||||
|
idc_name = request.GET.get('idc', '')
|
||||||
|
group_name = request.GET.get('group', '')
|
||||||
|
asset_type = request.GET.get('asset_type', '')
|
||||||
|
status = request.GET.get('status', '')
|
||||||
|
keyword = request.GET.get('keyword', '')
|
||||||
|
|
||||||
#
|
if not idc_name and not asset_type and not status and group_name == 'all':
|
||||||
#
|
select_number = 0
|
||||||
# @require_admin
|
else:
|
||||||
# def group_edit(request):
|
select_number = 1
|
||||||
# """ 修改主机组 """
|
|
||||||
# header_title, path1, path2 = u'编辑主机组', u'资产管理', u'编辑主机组'
|
|
||||||
# group_id = request.GET.get('id', '')
|
|
||||||
# group = BisGroup.objects.filter(id=group_id)
|
|
||||||
# if group:
|
|
||||||
# group = group[0]
|
|
||||||
# else:
|
|
||||||
# httperror(request, u'没有这个主机组!')
|
|
||||||
#
|
|
||||||
# host_all = Asset.objects.all()
|
|
||||||
# dept_id = get_session_user_info(request)[3]
|
|
||||||
# eposts = Asset.objects.filter(bis_group=group)
|
|
||||||
#
|
|
||||||
# if is_group_admin(request) and not validate(request, asset_group=[group_id]):
|
|
||||||
# return httperror(request, '编辑失败, 您无权操作!')
|
|
||||||
# dept = DEPT.objects.filter(id=group.dept.id)
|
|
||||||
# if dept:
|
|
||||||
# dept = dept[0]
|
|
||||||
# else:
|
|
||||||
# return httperror(request, u'没有这个部门!')
|
|
||||||
#
|
|
||||||
# all_dept = dept.asset_set.all()
|
|
||||||
# posts = [g for g in all_dept if g not in eposts]
|
|
||||||
#
|
|
||||||
# if request.method == 'POST':
|
|
||||||
# j_group = request.POST.get('j_group', '')
|
|
||||||
# j_hosts = request.POST.getlist('j_hosts', '')
|
|
||||||
# j_dept = request.POST.get('j_dept', '')
|
|
||||||
# j_comment = request.POST.get('j_comment', '')
|
|
||||||
#
|
|
||||||
# j_dept = DEPT.objects.filter(id=int(j_dept))
|
|
||||||
# j_dept = j_dept[0]
|
|
||||||
#
|
|
||||||
# group.asset_set.clear()
|
|
||||||
# for host in j_hosts:
|
|
||||||
# g = Asset.objects.get(id=host)
|
|
||||||
# group.asset_set.add(g)
|
|
||||||
# BisGroup.objects.filter(id=group_id).update(name=j_group, dept=j_dept, comment=j_comment)
|
|
||||||
# smg = u'主机组%s修改成功' % j_group
|
|
||||||
# return HttpResponseRedirect('/jasset/group_list')
|
|
||||||
#
|
|
||||||
# return my_render('jasset/group_edit.html', locals(), request)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# @require_admin
|
|
||||||
# def group_detail(request):
|
|
||||||
# """ 主机组详情 """
|
|
||||||
# header_title, path1, path2 = u'主机组详情', u'资产管理', u'主机组详情'
|
|
||||||
# login_types = {'L': 'LDAP', 'M': 'MAP'}
|
|
||||||
# dept = get_session_user_info(request)[5]
|
|
||||||
# group_id = request.GET.get('id', '')
|
|
||||||
# group = BisGroup.objects.get(id=group_id)
|
|
||||||
# if is_super_user(request):
|
|
||||||
# posts = Asset.objects.filter(bis_group=group).order_by('ip')
|
|
||||||
#
|
|
||||||
# elif is_group_admin(request):
|
|
||||||
# if not validate(request, asset_group=[group_id]):
|
|
||||||
# return httperror(request, u'您无权查看!')
|
|
||||||
# posts = Asset.objects.filter(bis_group=group).filter(dept=dept).order_by('ip')
|
|
||||||
#
|
|
||||||
# contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
|
|
||||||
# return my_render('jasset/group_detail.html', locals(), request)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# @require_admin
|
|
||||||
# def group_del_host(request):
|
|
||||||
# """ 主机组中剔除主机, 并不删除真实主机 """
|
|
||||||
# if request.method == 'POST':
|
|
||||||
# group_id = request.POST.get('group_id')
|
|
||||||
# offset = request.GET.get('id', '')
|
|
||||||
# group = BisGroup.objects.get(id=group_id)
|
|
||||||
# if offset == 'group':
|
|
||||||
# len_list = request.POST.get("len_list")
|
|
||||||
# for i in range(int(len_list)):
|
|
||||||
# key = "id_list[" + str(i) + "]"
|
|
||||||
# jid = request.POST.get(key)
|
|
||||||
# g = Asset.objects.get(id=jid)
|
|
||||||
# group.asset_set.remove(g)
|
|
||||||
#
|
|
||||||
# else:
|
|
||||||
# offset = request.GET.get('id', '')
|
|
||||||
# group_id = request.GET.get('gid', '')
|
|
||||||
# group = BisGroup.objects.get(id=group_id)
|
|
||||||
# g = Asset.objects.get(id=offset)
|
|
||||||
# group.asset_set.remove(g)
|
|
||||||
#
|
|
||||||
# return HttpResponseRedirect('/jasset/group_detail/?id=%s' % group.id)
|
|
||||||
#
|
|
||||||
|
|
||||||
# @require_admin
|
if group_name == 'all':
|
||||||
# def dept_host_ajax(request):
|
asset_find = Asset.objects.filter(
|
||||||
# """ 添加主机组时, 部门联动主机异步 """
|
idc__name__contains=idc_name,
|
||||||
# dept_id = request.GET.get('id', '')
|
asset_type__contains=asset_type,
|
||||||
# if dept_id not in ['1', '2']:
|
status__contains=status
|
||||||
# dept = DEPT.objects.filter(id=dept_id)
|
)
|
||||||
# if dept:
|
|
||||||
# dept = dept[0]
|
else:
|
||||||
# hosts = dept.asset_set.all()
|
asset_find = Asset.objects.filter(
|
||||||
# else:
|
idc__name__contains=idc_name,
|
||||||
# hosts = Asset.objects.all()
|
group__name__contains=group_name,
|
||||||
#
|
asset_type__contains=asset_type,
|
||||||
# return my_render('jasset/dept_host_ajax.html', locals(), request)
|
status__contains=status
|
||||||
#
|
)
|
||||||
#
|
if keyword and select_number == 1:
|
||||||
# def show_all_ajax(request):
|
asset_find = asset_find.filter(
|
||||||
# """ 批量修改主机时, 部门和组全部显示 """
|
Q(hostname__contains=keyword) |
|
||||||
# env = request.GET.get('env', '')
|
Q(idc__name__contains=keyword) |
|
||||||
# get_id = request.GET.get('id', '')
|
Q(ip__contains=keyword) |
|
||||||
# host = Asset.objects.filter(id=get_id)
|
Q(remote_ip__contains=keyword) |
|
||||||
# if host:
|
Q(comment__contains=keyword) |
|
||||||
# host = host[0]
|
Q(group__name__contains=keyword) |
|
||||||
# return my_render('jasset/show_all_ajax.html', locals(), request)
|
Q(cpu__contains=keyword) |
|
||||||
#
|
Q(memory__contains=keyword) |
|
||||||
#
|
Q(disk__contains=keyword))
|
||||||
# @require_login
|
|
||||||
# def host_search(request):
|
elif keyword:
|
||||||
# """ 搜索主机 """
|
asset_find = Asset.objects.filter(
|
||||||
# keyword = request.GET.get('keyword')
|
Q(hostname__contains=keyword) |
|
||||||
# login_types = {'L': 'LDAP', 'M': 'MAP'}
|
Q(idc__name__contains=keyword) |
|
||||||
# dept = get_session_user_info(request)[5]
|
Q(ip__contains=keyword) |
|
||||||
# post_all = Asset.objects.filter(Q(ip__contains=keyword) |
|
Q(remote_ip__contains=keyword) |
|
||||||
# Q(idc__name__contains=keyword) |
|
Q(comment__contains=keyword) |
|
||||||
# Q(bis_group__name__contains=keyword) |
|
Q(group__name__contains=keyword) |
|
||||||
# Q(comment__contains=keyword)).distinct().order_by('ip')
|
Q(cpu__contains=keyword) |
|
||||||
# if is_super_user(request):
|
Q(memory__contains=keyword) |
|
||||||
# posts = post_all
|
Q(disk__contains=keyword))
|
||||||
#
|
|
||||||
# elif is_group_admin(request):
|
# asset_find = list(set(asset_find))
|
||||||
# posts = post_all.filter(dept=dept)
|
# asset_find_dic = {}
|
||||||
#
|
# asset_find_lis = []
|
||||||
# elif is_common_user(request):
|
# for server in asset_find:
|
||||||
# user_id, username = get_session_user_info(request)[0:2]
|
# if server.ip:
|
||||||
# post_perm = user_perm_asset_api(username)
|
# asset_find_dic[server.ip] = server
|
||||||
# posts = list(set(post_all) & set(post_perm))
|
# asset_find_lis.append(server.ip)
|
||||||
# contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(posts, request)
|
# sort_ip_list(asset_find_lis)
|
||||||
#
|
# asset_find = []
|
||||||
# return my_render('jasset/host_search.html', locals(), request)
|
# for ip in asset_find_lis:
|
||||||
|
# asset_find.append(asset_find_dic[ip])
|
||||||
|
# search_status = request.GET.get("_search", False)
|
||||||
|
# if search_status:
|
||||||
|
# s = write_excel(asset_find)
|
||||||
|
# if s[0]:
|
||||||
|
# file_name = s[1]
|
||||||
|
# smg = 'excel文件已生成,请点击下载!'
|
||||||
|
# return my_render('cmdb/excel_download.html', locals(), request)
|
||||||
|
contact_list, p, contacts, page_range, current_page, show_first, show_end = pages(asset_find, request)
|
||||||
|
return my_render('jasset/asset_list.html', locals(), request)
|
|
@ -119,3 +119,11 @@ function selectAll(){
|
||||||
// })
|
// })
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
function getIDall() {
|
||||||
|
var check_array = [];
|
||||||
|
$(".gradeX input:checked").each(function () {
|
||||||
|
var id = $(this).attr("value");
|
||||||
|
check_array.push(id);
|
||||||
|
});
|
||||||
|
return check_array.join(",");
|
||||||
|
}
|
|
@ -23,109 +23,125 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ibox-content">
|
<div class="ibox-content">
|
||||||
<div class="col-sm-2" style="padding-left: 0px">
|
<form id="asset_form">
|
||||||
<label>
|
<div class="col-sm-2" style="padding-left: 0px">
|
||||||
<select name="change_idc" class="form-control m-b" onchange="change_info()">
|
<label>
|
||||||
<option value="">IDC机房</option>
|
<select name="idc" class="form-control m-b" onchange="change_info()">
|
||||||
{% for i in idcs %}
|
<option value="">IDC机房</option>
|
||||||
<option value="{{i.name}}"> {{ i }}</option>
|
{% for idc in idc_all %}
|
||||||
{% endfor %}
|
{% ifequal idc.name idc_name %}
|
||||||
</select>
|
<option value="{{idc.name}}" selected> {{ idc.name }}</option>
|
||||||
</label>
|
{% else %}
|
||||||
</div>
|
<option value="{{idc.name}}"> {{ idc.name }}</option>
|
||||||
<div class="col-sm-2">
|
{% endifequal %}
|
||||||
<label>
|
{% endfor %}
|
||||||
<select name="change_project" class="form-control m-b" onchange="change_info()">
|
</select>
|
||||||
<option value="all">主机组</option>
|
</label>
|
||||||
{% for i in projects %}
|
</div>
|
||||||
<option value="{{ i.name }}"> {{ i.name }} </option>
|
<div class="col-sm-2">
|
||||||
{% endfor %}
|
<label>
|
||||||
</select>
|
<select name="group" class="form-control m-b" onchange="change_info()">
|
||||||
</label>
|
<option value="all">主机组</option>
|
||||||
</div>
|
{% for asset_group in asset_group_all %}
|
||||||
|
{% ifequal asset_group.name group_name %}
|
||||||
<div class="col-sm-2">
|
<option value="{{ asset_group.name }}" selected> {{ asset_group.name }} </option>
|
||||||
<label>
|
{% else %}
|
||||||
<select name="change_type" class="form-control m-b" onchange="change_info()">
|
<option value="{{ asset_group.name }}"> {{ asset_group.name }} </option>
|
||||||
<option value="">所有类型</option>
|
{% endifequal %}
|
||||||
{% for i in server_type %}
|
{% endfor %}
|
||||||
<option value="{{ i.0 }}"> {{ i.1 }}</option>
|
</select>
|
||||||
{% endfor %}
|
</label>
|
||||||
</select>
|
</div>
|
||||||
</label>
|
|
||||||
</div>
|
<div class="col-sm-2">
|
||||||
<div class="col-sm-2">
|
<label>
|
||||||
<label>
|
<select name="server_type" class="form-control m-b" onchange="change_info()">
|
||||||
<select name="change_type" class="form-control m-b" onchange="change_info()">
|
<option value="">所有类型</option>
|
||||||
<option value="">状态</option>
|
{% for type in asset_type %}
|
||||||
{% for i in server_type %}
|
{% ifequal type.0|int2str asset_type %}
|
||||||
<option value="{{ i.0 }}"> {{ i.1 }}</option>
|
<option value="{{ type.0 }}" selected> {{ type.1 }}</option>
|
||||||
{% endfor %}
|
{% else %}
|
||||||
</select>
|
<option value="{{ type.0 }}"> {{ type.1 }}</option>
|
||||||
</label>
|
{% endifequal %}
|
||||||
</div>
|
{% endfor %}
|
||||||
<div>
|
</select>
|
||||||
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
</label>
|
||||||
<div class="input-group">
|
</div>
|
||||||
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
|
<div class="col-sm-2">
|
||||||
<input type="text" style="display: none">
|
<label>
|
||||||
<div class="input-group-btn">
|
<select name="status" class="form-control m-b" onchange="change_info()">
|
||||||
<button type="submit" class="btn btn-sm btn-primary">
|
<option value="">状态</option>
|
||||||
- 搜索 -
|
{% for status in asset_status %}
|
||||||
</button>
|
{% ifequal status.0|int2str status %}
|
||||||
</div>
|
<option value="{{ status.0 }}" selected> {{ status.1 }}</option>
|
||||||
</div>
|
{% else %}
|
||||||
</form>
|
<option value="{{ status.0 }}"> {{ status.1 }}</option>
|
||||||
</div>
|
{% endifequal %}
|
||||||
|
{% endfor %}
|
||||||
<form id="contents_form" name="contents_form">
|
</select>
|
||||||
<table class="table table-striped table-bordered table-hover " id="editable" name="editable">
|
</label>
|
||||||
<thead>
|
</div>
|
||||||
<tr>
|
<div>
|
||||||
<th class="text-center">
|
<form id="search_form" method="get" action="" class="pull-right mail-search">
|
||||||
<input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')">
|
<div class="input-group">
|
||||||
</th>
|
<input type="text" class="form-control input-sm" id="search_input" name="keyword" placeholder="Search">
|
||||||
<th class="text-center" name="ip"> IP地址 </th>
|
<input type="text" style="display: none">
|
||||||
<th class="text-center"> 主机名 </th>
|
<div class="input-group-btn">
|
||||||
<th class="text-center"> IDC </th>
|
<button type="submit" class="btn btn-sm btn-primary">
|
||||||
<th class="text-center"> 所属主机组 </th>
|
- 搜索 -
|
||||||
<th class="text-center"> 配置信息 </th>
|
</button>
|
||||||
<th class="text-center"> 使用默认管理 </th>
|
</div>
|
||||||
<th class="text-center"> 操作 </th>
|
</div>
|
||||||
</tr>
|
</form>
|
||||||
</thead>
|
</div>
|
||||||
<tbody>
|
|
||||||
{% for asset in assets.object_list %}
|
<table class="table table-striped table-bordered table-hover " id="editable" name="editable">
|
||||||
<tr class="gradeX">
|
<thead>
|
||||||
<td class="text-center" name="id" value="{{ asset.id }}" data-editable='false'>
|
<tr>
|
||||||
<input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks">
|
<th class="text-center">
|
||||||
</td>
|
<input id="checkall" type="checkbox" class="i-checks" name="checkall" value="checkall" data-editable='false' onclick="check_all('contents_form')">
|
||||||
<td class="text-center"> {{ asset.ip }} </td>
|
</th>
|
||||||
<td class="text-center"> {{ asset.hostname }} </td>
|
<th class="text-center" name="ip"> IP地址 </th>
|
||||||
<td class="text-center"> {{ asset.idc.name }} </td>
|
<th class="text-center"> 主机名 </th>
|
||||||
<td class="text-center">{{ asset.port }}</td>
|
<th class="text-center"> IDC </th>
|
||||||
<td class="text-center">{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}</td>
|
<th class="text-center"> 所属主机组 </th>
|
||||||
<td class="text-center"> {{ asset.use_default_auth|bool2str }} </td>
|
<th class="text-center"> 配置信息 </th>
|
||||||
<td class="text-center" data-editable='false'>
|
<th class="text-center"> 使用默认管理 </th>
|
||||||
<a href="/jasset/asset_detail/?id={{ asset.id }}" class="btn btn-xs btn-primary">详情</a>
|
<th class="text-center"> 操作 </th>
|
||||||
{% ifnotequal session_role_id 0 %}
|
</tr>
|
||||||
<a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</a>
|
</thead>
|
||||||
<a value="/jasset/asset_del/?id={{ asset.id }}" class="btn btn-xs btn-danger asset_del">删除</a>
|
<tbody>
|
||||||
{% endifnotequal %}
|
{% for asset in assets.object_list %}
|
||||||
</td>
|
<tr class="gradeX">
|
||||||
</tr>
|
<td class="text-center" name="id" value="{{ asset.id }}" data-editable='false'>
|
||||||
{% endfor %}
|
<input name="id" value="{{ asset.id }}" type="checkbox" class="i-checks">
|
||||||
</tbody>
|
</td>
|
||||||
</table>
|
<td class="text-center"> {{ asset.ip }} </td>
|
||||||
<div class="row">
|
<td class="text-center"> {{ asset.hostname }} </td>
|
||||||
<div class="col-sm-6">
|
<td class="text-center"> {{ asset.idc.name }} </td>
|
||||||
<input type="button" id="del_button" class="btn btn-danger btn-sm" name="del_button" value="删除" onclick="del('contents_form')" />
|
<td class="text-center">{{ asset.port }}</td>
|
||||||
<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />
|
<td class="text-center">{{ asset.cpu }}|{{ asset.memory }}|{{ asset.disk }}</td>
|
||||||
|
<td class="text-center"> {{ asset.use_default_auth|bool2str }} </td>
|
||||||
|
<td class="text-center" data-editable='false'>
|
||||||
|
<a href="/jasset/asset_detail/?id={{ asset.id }}" class="btn btn-xs btn-primary">详情</a>
|
||||||
|
{% ifnotequal session_role_id 0 %}
|
||||||
|
<a href="/jasset/asset_edit/?id={{ asset.id }}" class="btn btn-xs btn-info">编辑</a>
|
||||||
|
<a value="/jasset/asset_del/?id={{ asset.id }}" class="btn btn-xs btn-danger asset_del">删除</a>
|
||||||
|
{% endifnotequal %}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-sm-6">
|
||||||
|
<input type="button" id="asset_del" class="btn btn-danger btn-sm" name="del_button" value="删除"/>
|
||||||
|
<input type="button" id="alter_button" class="btn btn-warning btn-sm" name="alter_button" value="修改" onclick="alter('contents_form')" />
|
||||||
|
</div>
|
||||||
|
{% include 'paginator.html' %}
|
||||||
</div>
|
</div>
|
||||||
{% include 'paginator.html' %}
|
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -180,38 +196,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function del(form) {
|
$('#asset_del').click(function () {
|
||||||
var checkboxes = document.getElementById(form);
|
var asset_id_all = getIDall();
|
||||||
var id_list = {};
|
console.log(asset_id_all);
|
||||||
var j = 0;
|
if (asset_id_all == ''){
|
||||||
for (var i = 0; i < checkboxes.elements.length; i++) {
|
alert("请至少选择一行!");
|
||||||
if (checkboxes.elements[i].type == "checkbox" && checkboxes.elements[i].checked == true && checkboxes.elements[i].value != "checkall") {
|
return false;
|
||||||
id_list[j] = checkboxes.elements[i].value;
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (confirm("确定删除")) {
|
if (confirm("确定删除")) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "post",
|
||||||
url: "/jasset/host_del/multi/",
|
data: {asset_id_all: asset_id_all},
|
||||||
data: {"id_list": id_list, "len_list": j},
|
url: "/jasset/asset_del/?arg=batch",
|
||||||
success: function (data) {
|
success: function () {
|
||||||
window.open("/jasset/host_list/", "_self");
|
window.open("/jasset/asset_list/", "_self");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function change_info(){
|
||||||
|
var args = $("#asset_form").serialize();
|
||||||
|
window.location = "/jasset/asset_search/?" + args
|
||||||
}
|
}
|
||||||
|
|
||||||
{# function host_search(){#}
|
|
||||||
{# $.ajax({#}
|
|
||||||
{# type: "GET",#}
|
|
||||||
{# url: "/jasset/search/",#}
|
|
||||||
{# data: $("#search_form").serialize(),#}
|
|
||||||
{# success: function (data) {#}
|
|
||||||
{# $("#contents_form").html(data);#}
|
|
||||||
{# }#}
|
|
||||||
{# });#}
|
|
||||||
{# }#}
|
|
||||||
|
|
||||||
$("#search_input").keydown(function(e){
|
$("#search_input").keydown(function(e){
|
||||||
if(e.keyCode==13){
|
if(e.keyCode==13){
|
||||||
|
|
Loading…
Reference in New Issue