cmdb/urls.py
from cmdbapp import machinaroomviews,serverviews,networkdeviceviews,securitydeviceviews,storagedeviceviews
urlpatterns = [
url(r'^static/(?P
url(r'^base',machinaroomviews.base,name='base'),
url(r'^search_machinaroom.html',machinaroomviews.add_machinaroom,name='add_machinaroom'),
url(r'^edit_machinaroom.html',machinaroomviews.edit_machinaroom,name='edit_machinaroom'),
url(r'^del_machinaroom.html',machinaroomviews.del_machinaroom,name='del_machinaroom'),
url(r'^batdel_machinaroom.html',machinaroomviews.batdel_machinaroom,name='batdel_machinaroom'),
url(r'^excel_machinaroom.html',machinaroomviews.excel_machinaroom,name='excel_machinaroom'),
url(r'^login/',serverviews.search_server,name='search_server'),
url(r'^add_server.html',serverviews.edit_server,name="edit_server"),
url(r'^del_server.html',serverviews.del_server,name='del_server'),
url(r'^batdel_server.html',serverviews.batdel_server,name='batdel_server'),
url(r'^excel_server.html',serverviews.excel_server,name='excel_server'),
url(r'^search_networkdevice.html',networkdeviceviews.add_networkdevice,name="add_networkdevice"),
url(r'^edit_networkdevice.html',securitydeviceviews.search_securitydevice,name='search_securitydevice'),
url(r'^add_securitydevice.html',securitydeviceviews.edit_securitydevice,name="edit_securitydevice"),
url(r'^del_securitydevice.html',securitydeviceviews.del_securitydevice,name='del_securitydevice'),
url(r'^batdel_securitydevice.html',securitydeviceviews.batdel_securitydevice,name='batdel_securitydevice'),
url(r'^excel_securitydevice.html',securitydeviceviews.excel_securitydevice,name='excel_securitydevice'),
url(r'^search_storagedevice.html',storagedeviceviews.add_storagedevice,name="add_storagedevice"),
url(r'^edit_storagedevice.html$',storagedeviceviews.edit_storagedevice,name="edit_storagedevice"),
url(r'^del_storagedevice.html',storagedeviceviews.del_storagedevice,name='del_storagedevice'),
url(r'^batdel_storagedevice.html',storagedeviceviews.batdel_storagedevice,name='batdel_storagedevice'),
url(r'^excel_storagedevice.html',storagedeviceviews.excel_storagedevice,name='excel_storagedevice'),
]
cmdbapp/networkdeviceviews.py securitydeviceviews.py storagedeviceviews.py
-- coding: utf-8 --
from future import unicode_literals
from django.shortcuts import render,render_to_response
from django.core.paginator import Paginator,InvalidPage,EmptyPage
from cmdbapp.models import *
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from xlwt import *
import StringIO
def search_networkdevice(request):
error = False
each_page = 8
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
os=request.GET.get('os','').strip()
status=int(request.GET.get('status',100))
if mname=='' and sname=='' and ip=='' and os=='' and status==100:
record_list = Networkdevice.objects.all()
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_networkdevice.html',{'networkdevicelist':contacts,"mname":mname,"sname":sname,"ip":ip,"os":os,"status":status})
else:
q={}
if mname!='' and sname=='' and ip=='' and os=='' and status==100:
a=Machinaroom.objects.filter(name__icontains=mname).values("id")
q['machinaroom__in']=a
if sname!='':
q['hostname__icontains']=sname
if ip!='':
q['ip__icontains']=ip
if os!='':
q['model_icontains']=os
if status!=100:
q['status']=status
record_list = Networkdevice.objects.filter(**q)
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_networkdevice.html',{'networkdevicelist':contacts,"mname":mname,"sname":sname,"ip":ip,"os":os,"status":status})
def add_networkdevice(request):
if request.method=='GET':
objs=Machinaroom.objects.all()
return render_to_response("add_networkdevice.html",{"machinaroomlist":objs})
else:
hostname=request.POST.get("networkdevicehostname","")
model=request.POST.get("networkdevicemodel","")
ip=request.POST.get("networkdeviceip","")
memo=request.POST.get("networkdevicememo","")
port_num=request.POST.get('networkdeviceport_num','')
status=request.POST.get("networkdevicestatus",0)
machinaroomid=request.POST.get("networkdevicemachinaroom")
machinaroom=Machinaroom.objects.get(id=int(machinaroomid))
uu=Networkdevice(hostname=hostname,model=model,ip=ip,memo=memo,port_num=port_num,status=status,machinaroom=machinaroom)
uu.save()
return HttpResponseRedirect("add_networkdevice.html")
def edit_networkdevice(request):
if request.method=='GET':
obj=Networkdevice.objects.get(id=int(request.GET.get('id')))
objs=Machinaroom.objects.all()
return render_to_response('edit_networkdevice.html',{'networkdevice':obj,'machinaroomlist':objs})
else:
id=request.POST.get("id")
hostname=request.POST.get("networkdevicehostname","")
model=request.POST.get("networkdevicemodel","")
ip=request.POST.get("networkdeviceip","")
memo=request.POST.get("networkdevicememo","")
status=request.POST.get("networkdevicestatus",0)
machinaroomid=request.POST.get("networkdevicemachinaroom")
machinaroom=Machinaroom.objects.get(id=int(machinaroomid))
uu=Networkdevice.objects.filter(id=id).update(hostname=hostname,model=model,ip=ip,memo=memo,status=status,machinaroom=machinaroom)
return HttpResponseRedirect("edit_networkdevice.html?id="+id)
def del_networkdevice(request):
id=request.GET.get('id')
iid=int(id)
Networkdevice.objects.filter(id=iid).delete()
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
os=request.GET.get('os','').strip()
status=request.GET.get('status',100)
page=request.GET.get('page','1')
return HttpResponseRedirect('search_networkdevice.html?mname='+mname+"&&page="+page+"&&sname="+sname+"&&ip="+ip+"&&os="+os+"&&status="+status)
def batdel_networkdevice(request):
ids=request.GET.get('ids')
b=ids.split(',')
arr = map(int,b)
for aaa in arr:
Networkdevice.objects.filter(id=aaa).delete()
mname=request.GET.get('mname')
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
os=request.GET.get('os','').strip()
status=request.GET.get('status',100)
return HttpResponseRedirect('search_networkdevice.html?mname='+mname+"&&sname="+sname+"&&ip="+ip+"&&os="+os+"&&status="+status)
def excel_networkdevice(request):
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
os=request.GET.get('os','').strip()
status=int(request.GET.get('status',100))
if mname=='' and sname=='' and ip=='' and os=='' and status==100:
list_obj = Networkdevice.objects.all()
else:
q={}
if mname!='' and sname=='' and ip=='' and os=='' and status==100:
a=Machinaroom.objects.filter(name__icontains=mname).values("id")
q['machinaroom__in']=a
if sname!='':
q['hostname__icontains']=sname
if ip!='':
q['ip__icontains']=ip
if os!='':
q['model__icontains']=os
if status!=100:
q['status']=status
list_obj = Networkdevice.objects.filter(**q)
if list_obj:
# 创建工作薄
ws = Workbook(encoding='utf-8')
w = ws.add_sheet(u"网络设备清单")
w.write(0, 0, "id")
w.write(0, 1, u"设备名字")
w.write(0, 2, u"制造商/型号")
w.write(0, 3, u"IP")
w.write(0, 4, u"端口数量")
w.write(0,5,u"备注")
w.write(0,6,u"状态")
w.write(0,7,u"机房")
# 写入数据
excel_row = 1
for obj in list_obj:
data_id = obj.id
data_hostname = obj.hostname
data_model = obj.model
data_ip = obj.ip
data_port_num = obj.port_num
data_memo=obj.memo
if obj.status == 0:
data_status='在线'
elif obj.status == 1:
data_status='已下线'
elif obj.status == 2:
data_status='未知'
elif obj.status == 3:
data_status='故障'
else:
data_status='备用'
data_machinaroom=obj.machinaroom.name
w.write(excel_row, 0, data_id)
w.write(excel_row, 1, data_hostname)
w.write(excel_row, 2, data_model)
w.write(excel_row, 3, data_ip)
w.write(excel_row, 4, data_port_num)
w.write(excel_row, 5, data_memo)
w.write(excel_row, 6, data_status)
w.write(excel_row, 7, data_machinaroom)
excel_row += 1
sio = StringIO.StringIO()
ws.save(sio)
sio.seek(0)
response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=服务器清单-'+mname+sname+ip+os+'.xls'
response.write(sio.getvalue())
return response
-- coding: utf-8 --
from future import unicode_literals
from django.shortcuts import render,render_to_response
from django.core.paginator import Paginator,InvalidPage,EmptyPage
from cmdbapp.models import *
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from xlwt import *
import StringIO
def search_securitydevice(request):
error = False
each_page = 8
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
type=request.GET.get('type','').strip()
status=int(request.GET.get('status',100))
if mname=='' and sname=='' and ip=='' and model=='' and type=='' and status==100:
record_list = Securitydevice.objects.all()
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_securitydevice.html',{'securitydevicelist':contacts,"mname":mname,"sname":sname,"ip":ip,"model":model,"type":type,"status":status})
else:
q={}
if mname!='' and sname=='' and ip=='' and model=='' and type=='' and status==100:
a=Machinaroom.objects.filter(name__icontains=mname).values("id")
q['machinaroom__in']=a
if sname!='':
q['hostname__icontains']=sname
if ip!='':
q['ip__icontains']=ip
if model!='':
q['model_icontains']=model
if type!='':
q['type_icontains']=type
if status!=100:
q['status']=status
record_list = Securitydevice.objects.filter(**q)
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_securitydevice.html',{'securitydevicelist':contacts,"mname":mname,"sname":sname,"ip":ip,"model":model,"type":type,"status":status})
def add_securitydevice(request):
if request.method=='GET':
objs=Machinaroom.objects.all()
return render_to_response("add_securitydevice.html",{"machinaroomlist":objs})
else:
hostname=request.POST.get("securitydevicehostname","")
model=request.POST.get("securitydevicemodel","")
ip=request.POST.get("securitydeviceip","")
memo=request.POST.get("securitydevicememo","")
port_num=request.POST.get('securitydeviceport_num',0)
status=request.POST.get("securitydevicestatus",0)
machinaroomid=request.POST.get("securitydevicemachinaroom")
machinaroom=Machinaroom.objects.get(id=int(machinaroomid))
type=request.POST.get("securitydevicetype","")
uu=Securitydevice(hostname=hostname,model=model,ip=ip,type=type,memo=memo,port_num=port_num,status=status,machinaroom=machinaroom)
uu.save()
return HttpResponseRedirect("add_securitydevice.html")
def edit_securitydevice(request):
if request.method=='GET':
obj=Securitydevice.objects.get(id=int(request.GET.get('id')))
objs=Machinaroom.objects.all()
return render_to_response('edit_securitydevice.html',{'securitydevice':obj,'machinaroomlist':objs})
else:
id=request.POST.get("id")
hostname=request.POST.get("securitydevicehostname","")
model=request.POST.get("securitydevicemodel","")
ip=request.POST.get("securitydeviceip","")
memo=request.POST.get("securitydevicememo","")
status=request.POST.get("securitydevicestatus",0)
port_num=request.POST.get("securitydeviceport_num",0)
machinaroomid=request.POST.get("securitydevicemachinaroom")
machinaroom=Machinaroom.objects.get(id=int(machinaroomid))
type=request.POST.get("securitydevicetype","")
uu=Securitydevice.objects.filter(id=id).update(hostname=hostname,model=model,type=type,ip=ip,port_num=port_num,memo=memo,status=status,machinaroom=machinaroom)
return HttpResponseRedirect("edit_securitydevice.html?id="+id)
def del_securitydevice(request):
id=request.GET.get('id')
iid=int(id)
Securitydevice.objects.filter(id=iid).delete()
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
type=request.GET.get('type','').strip()
status=request.GET.get('status',100)
page=request.GET.get('page','1')
return HttpResponseRedirect('search_securitydevice.html?mname='+mname+"&&page="+page+"&&sname="+sname+"&&ip="+ip+"&&model="+model+"&&type="+type+"&&status="+status)
def batdel_securitydevice(request):
ids=request.GET.get('ids')
b=ids.split(',')
arr = map(int,b)
for aaa in arr:
Securitydevice.objects.filter(id=aaa).delete()
mname=request.GET.get('mname')
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
type=request.GET.get('type','').strip()
status=request.GET.get('status',100)
return HttpResponseRedirect('search_securitydevice.html?mname='+mname+"&&sname="+sname+"&&ip="+ip+"&&model="+model+"&&type="+type+"&&status="+status)
def excel_securitydevice(request):
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
type=request.GET.get('type','').strip()
status=int(request.GET.get('status',100))
if mname=='' and sname=='' and ip=='' and model=='' and type=='' and status==100:
list_obj = Securitydevice.objects.all()
else:
q={}
if mname!='' and sname=='' and ip=='' and model=='' and type=='' and status==100:
a=Machinaroom.objects.filter(name__icontains=mname).values("id")
q['machinaroom__in']=a
if sname!='':
q['hostname__icontains']=sname
if ip!='':
q['ip__icontains']=ip
if model!='':
q['model__icontains']=model
if type!='':
q['type_icontains']=type
if status!=100:
q['status']=status
list_obj = Securitydevice.objects.filter(**q)
if list_obj:
# 创建工作薄
ws = Workbook(encoding='utf-8')
w = ws.add_sheet(u"网络设备清单")
w.write(0, 0, "id")
w.write(0, 1, u"设备名字")
w.write(0, 2, u"制造商/型号")
w.write(0, 3, u"IP")
w.write(0, 4, u"端口数量")
w.write(0,5,u"类型")
w.write(0,6,u"备注")
w.write(0,7,u"状态")
w.write(0,8,u"机房")
# 写入数据
excel_row = 1
for obj in list_obj:
data_id = obj.id
data_hostname = obj.hostname
data_model = obj.model
data_ip = obj.ip
data_port_num = obj.port_num
data_type=obj.type
data_memo=obj.memo
if obj.status == 0:
data_status='在线'
elif obj.status == 1:
data_status='已下线'
elif obj.status == 2:
data_status='未知'
elif obj.status == 3:
data_status='故障'
else:
data_status='备用'
data_machinaroom=obj.machinaroom.name
w.write(excel_row, 0, data_id)
w.write(excel_row, 1, data_hostname)
w.write(excel_row, 2, data_model)
w.write(excel_row, 3, data_ip)
w.write(excel_row, 4, data_port_num)
w.write(excel_row, 5, data_type)
w.write(excel_row, 6, data_memo)
w.write(excel_row, 7, data_status)
w.write(excel_row, 8, data_machinaroom)
excel_row += 1
sio = StringIO.StringIO()
ws.save(sio)
sio.seek(0)
response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=服务器清单-'+mname+sname+ip+'.xls'
response.write(sio.getvalue())
return response
-- coding: utf-8 --
from future import unicode_literals
from django.shortcuts import render,render_to_response
from django.core.paginator import Paginator,InvalidPage,EmptyPage
from cmdbapp.models import *
from django.http import HttpResponse
from django.http import HttpResponseRedirect
from xlwt import *
import StringIO
def search_storagedevice(request):
error = False
each_page = 8
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
status=int(request.GET.get('status',100))
if mname=='' and sname=='' and ip=='' and model=='' and status==100:
record_list = Storagedevice.objects.all()
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_storagedevice.html',{'storagedevicelist':contacts,"mname":mname,"sname":sname,"ip":ip,"model":model,"status":status})
else:
q={}
if mname!='' and sname=='' and ip=='' and model=='' and type=='' and status==100:
a=Machinaroom.objects.filter(name__icontains=mname).values("id")
q['machinaroom__in']=a
if sname!='':
q['hostname__icontains']=sname
if ip!='':
q['ip__icontains']=ip
if model!='':
q['model_icontains']=mode
if status!=100:
q['status']=status
record_list = Storagedevice.objects.filter(**q)
paginator = Paginator(record_list,each_page)
try:
page = int(request.GET.get('page', '1'))
except ValueError:
page = 1
try:
contacts = paginator.page(page)
except (EmptyPage, InvalidPage):
contacts = paginator.page(paginator.num_pages)
return render_to_response('search_storagedevice.html',{'storagedevicelist':contacts,"mname":mname,"sname":sname,"ip":ip,"model":model,"status":status})
def add_storagedevice(request):
if request.method=='GET':
objs=Machinaroom.objects.all()
return render_to_response("add_storagedevice.html",{"machinaroomlist":objs})
else:
hostname=request.POST.get("storagedevicehostname","")
model=request.POST.get("storagedevicemodel","")
ip=request.POST.get("storagedeviceip","")
memo=request.POST.get("storagedevicememo","")
disk=request.POST.get('storagedevicedisk','')
status=request.POST.get("storagedevicestatus",0)
machinaroomid=request.POST.get("storagedevicemachinaroom")
machinaroom=Machinaroom.objects.get(id=int(machinaroomid))
uu=Storagedevice(hostname=hostname,model=model,ip=ip,memo=memo,disk=disk,status=status,machinaroom=machinaroom)
uu.save()
return HttpResponseRedirect("add_storagedevice.html")
def edit_storagedevice(request):
if request.method=='GET':
obj=Storagedevice.objects.get(id=int(request.GET.get('id')))
objs=Machinaroom.objects.all()
return render_to_response('edit_storagedevice.html',{'storagedevice':obj,'machinaroomlist':objs})
else:
id=request.POST.get("id")
hostname=request.POST.get("storagedevicehostname","")
model=request.POST.get("storagedevicemodel","")
ip=request.POST.get("storagedeviceip","")
memo=request.POST.get("storagedevicememo","")
status=request.POST.get("storagedevicestatus",0)
machinaroomid=request.POST.get("storagedevicemachinaroom")
machinaroom=Machinaroom.objects.get(id=int(machinaroomid))
disk=request.POST.get("storagedevicedisk","")
uu=Storagedevice.objects.filter(id=id).update(hostname=hostname,model=model,disk=disk,ip=ip,memo=memo,status=status,machinaroom=machinaroom)
return HttpResponseRedirect("edit_storagedevice.html?id="+id)
def del_storagedevice(request):
id=request.GET.get('id')
iid=int(id)
Storagedevice.objects.filter(id=iid).delete()
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
status=request.GET.get('status',100)
page=request.GET.get('page','1')
return HttpResponseRedirect('search_storagedevice.html?mname='+mname+"&&page="+page+"&&sname="+sname+"&&ip="+ip+"&&model="+model+"&&status="+status)
def batdel_storagedevice(request):
ids=request.GET.get('ids')
b=ids.split(',')
arr = map(int,b)
for aaa in arr:
Storagedevice.objects.filter(id=aaa).delete()
mname=request.GET.get('mname')
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
status=request.GET.get('status',100)
return HttpResponseRedirect('search_storagedevice.html?mname='+mname+"&&sname="+sname+"&&ip="+ip+"&&model="+model+"&&status="+status)
def excel_storagedevice(request):
mname=request.GET.get('mname','').strip()
sname=request.GET.get('sname','').strip()
ip=request.GET.get('ip','').strip()
model=request.GET.get('model','').strip()
status=int(request.GET.get('status',100))
if mname=='' and sname=='' and ip=='' and model=='' and status==100:
list_obj = Storagedevice.objects.all()
else:
q={}
if mname!='' and sname=='' and ip=='' and model=='' and status==100:
a=Machinaroom.objects.filter(name__icontains=mname).values("id")
q['machinaroom__in']=a
if sname!='':
q['hostname__icontains']=sname
if ip!='':
q['ip__icontains']=ip
if model!='':
q['model__icontains']=model
if status!=100:
q['status']=status
list_obj = Storagedevice.objects.filter(**q)
if list_obj:
# 创建工作薄
ws = Workbook(encoding='utf-8')
w = ws.add_sheet(u"网络设备清单")
w.write(0, 0, "id")
w.write(0, 1, u"设备名字")
w.write(0, 2, u"制造商/型号")
w.write(0, 3, u"IP")
w.write(0, 4, u"容量信息")
w.write(0,5,u"备注")
w.write(0,6,u"状态")
w.write(0,7,u"机房")
# 写入数据
excel_row = 1
for obj in list_obj:
data_id = obj.id
data_hostname = obj.hostname
data_model = obj.model
data_ip = obj.ip
data_disk = obj.disk
data_memo=obj.memo
if obj.status == 0:
data_status='在线'
elif obj.status == 1:
data_status='已下线'
elif obj.status == 2:
data_status='未知'
elif obj.status == 3:
data_status='故障'
else:
data_status='备用'
data_machinaroom=obj.machinaroom.name
w.write(excel_row, 0, data_id)
w.write(excel_row, 1, data_hostname)
w.write(excel_row, 2, data_model)
w.write(excel_row, 3, data_ip)
w.write(excel_row, 4, data_disk)
w.write(excel_row, 5, data_memo)
w.write(excel_row, 6, data_status)
w.write(excel_row, 7, data_machinaroom)
excel_row += 1
sio = StringIO.StringIO()
ws.save(sio)
sio.seek(0)
response = HttpResponse(sio.getvalue(), content_type='application/vnd.ms-excel')
response['Content-Disposition'] = 'attachment; filename=服务器清单-'+mname+sname+ip+'.xls'
response.write(sio.getvalue())
return response
修改 models.py
-- coding: utf-8 --
from future import unicode_literals
from django.db import models
class Machinaroom(models.Model):
id=models.AutoField(primary_key=True)
name=models.CharField(max_length=200,default=u'机房')
location=models.CharField(max_length=200,default=u'厦门')
vpnurl=models.URLField(default="")
memo = models.CharField(u'备注', max_length=200,default="")
def unicode(self):
return self.name
class Server(models.Model):
"""
服务器信息
"""
machinaroom= models.ForeignKey(Machinaroom)
hostname = models.CharField(max_length=128, unique=True)
model = models.CharField('制造商/型号', max_length=128, default="")
ip = models.CharField('IP', max_length=128, default="")
os = models.CharField('操作系统', max_length=128, default="")
cpu = models.CharField('CPU', max_length=128, default="")
memory=models.CharField('memory', max_length=128, default="")
disk=models.CharField('硬盘信息',max_length=200, default="")
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
memo = models.CharField(u'备注', max_length=200,default="")
id =models.AutoField(primary_key=True)
class Meta:
verbose_name_plural = "服务器表"
def __str__(self):
return self.hostname
class Networkdevice(models.Model):
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
machinaroom= models.ForeignKey(Machinaroom)
hostname = models.CharField(max_length=128, unique=True)
port_num = models.SmallIntegerField(u'端口个数', default=0)
model = models.CharField(u'型号', max_length=128, default="")
ip = models.CharField(max_length=128, default="")
memo = models.CharField(u'备注', max_length=200,default="")
class Meta:
verbose_name = '网络设备'
verbose_name_plural = "网络设备"
def __str__(self):
return self.hostname
class Securitydevice(models.Model):
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
machinaroom= models.ForeignKey(Machinaroom)
type=models.CharField(u'类型', max_length=128, default="")
hostname = models.CharField(max_length=128, unique=True)
port_num = models.SmallIntegerField(u'端口个数', default=0)
model = models.CharField(u'型号', max_length=128, default="")
memo = models.CharField(u'备注', max_length=200,default="")
ip = models.CharField(max_length=128, default="")
class Meta:
verbose_name = '安全设备'
verbose_name_plural = "安全设备"
def __str__(self):
return self.hostname
class Storagedevice(models.Model):
"""存储设备"""
machinaroom= models.ForeignKey(Machinaroom)
model = models.CharField(u'型号', max_length=128, default="")
id =models.AutoField(primary_key=True)
hostname = models.CharField(max_length=128, unique=True,default="")
ip = models.CharField(max_length=128, default="")
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
disk=models.CharField('容量信息',max_length=200, default="")
memo = models.TextField(u'备注', default="")
class Meta:
verbose_name = '存储设备'
verbose_name_plural = "存储设备"
def __str__(self):
return self.model
class Software(models.Model):
sub_assset_type_choices = (
(0, 'OS'),
(1, '办公\开发软件'),
(2, '业务软件'),
)
sub_asset_type = models.SmallIntegerField(choices=sub_assset_type_choices, verbose_name="服务器类型", default=0)
license_num = models.IntegerField(verbose_name="授权数",default=0)
version = models.CharField(u'软件/系统版本', max_length=64, help_text=u'eg. CentOS release 6.5 (Final)', unique=True)
id =models.AutoField(primary_key=True)
def __str__(self):
return self.version
class Meta:
verbose_name = '软件/系统'
verbose_name_plural = "软件/系统"
class Manufactory(models.Model):
"""厂商"""
id =models.AutoField(primary_key=True)
manufactory = models.CharField(u'厂商名称', max_length=64, unique=True)
support_num = models.CharField(u'支持电话', max_length=30, default="")
memo = models.CharField(u'备注', max_length=128, default="")
def __str__(self):
return self.manufactory
class Meta:
verbose_name = '厂商'
verbose_name_plural = "厂商"
templates/add_networkdevice.html add_securitydevice.html add_storagedevice.html edit_networkdevice.html edit_securitydevice.html edit_storagedevice.html search_networkdevice.html search_securitydevice.html search_storagedevice.html
{% extends 'base.html' %}
{% block title %}
机房名字
设备名字
ip地址
制造商/型号
状态
{% if networkdevicelist.has_previous %}
上一页
{% endif %}
Page {{ networkdevicelist.number }} of {{ networkdevicelist.paginator.num_pages }}.
{% if networkdevicelist.has_next %}
下一页
{% endif %}
{% endblock %}
{% block content %}
设备名字 | 制造商/型号 | IP | 端口数 | 备注 | 状态 | 机房 | 操作 | |
---|---|---|---|---|---|---|---|---|
{{ s.hostname }} | {{ s.model }} | {{ s.ip }} | {{ s.port_num }} | {{ s.memo }} | {% if s.status == 0 %} 在线 {% elif s.status == 1 %} 已下线 {% elif s.status == 2 %} 未知 {% elif s.status == 3 %} 故障 {% elif s.status == 4 %} 备用 {% endif %} | {{ s.machinaroom.name }} | 编辑 删除 |
{% endblock %}
{% extends 'base.html' %}
{% block title %}
机房名字
设备名字
ip地址
制造商/型号
类型
状态
{% if securitydevicelist.has_previous %}
上一页
{% endif %}
Page {{ securitydevicelist.number }} of {{ securitydevicelist.paginator.num_pages }}.
{% if securitydevicelist.has_next %}
下一页
{% endif %}
{% endblock %}
{% block content %}
设备名字 | 制造商/型号 | IP | 端口数 | 类型 | 备注 | 状态 | 机房 | 操作 | |
---|---|---|---|---|---|---|---|---|---|
{{ s.hostname }} | {{ s.model }} | {{ s.ip }} | {{ s.port_num }} | {{ s.type }} | {{ s.memo }} | {% if s.status == 0 %} 在线 {% elif s.status == 1 %} 已下线 {% elif s.status == 2 %} 未知 {% elif s.status == 3 %} 故障 {% elif s.status == 4 %} 备用 {% endif %} | {{ s.machinaroom.name }} | 编辑 删除 |
{% endblock %}
{% extends 'base.html' %}
{% block title %}
机房名字
设备名字
ip地址
制造商/型号
状态
{% if storagedevicelist.has_previous %}
上一页
{% endif %}
Page {{ storagedevicelist.number }} of {{ storagedevicelist.paginator.num_pages }}.
{% if storagedevicelist.has_next %}
下一页
{% endif %}
{% endblock %}
{% block content %}
设备名字 | 制造商/型号 | IP | 容量信息 | 备注 | 状态 | 机房 | 操作 | |
---|---|---|---|---|---|---|---|---|
{{ s.hostname }} | {{ s.model }} | {{ s.ip }} | {{ s.disk }} | {{ s.memo }} | {% if s.status == 0 %} 在线 {% elif s.status == 1 %} 已下线 {% elif s.status == 2 %} 未知 {% elif s.status == 3 %} 故障 {% elif s.status == 4 %} 备用 {% endif %} | {{ s.machinaroom.name }} | 编辑 删除 |
{% endblock %}