修改main_page主菜单
data = [{"accessPath":"","checked":false,"delFlag":0,"parentID":1,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":3,"resourceName":"资产","resourceOrder":0,"resourceType":""},
{"accessPath":"house_list.html","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":31,"resourceName":"机房","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":32,"resourceName":"物理服务器","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":33,"resourceName":"虚拟机","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":34,"resourceName":"网络设备","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":35,"resourceName":"安全设备","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":36,"resourceName":"存储设备","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":37,"resourceName":"软件资产","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":3,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":38,"resourceName":"厂商","resourceOrder":0,"resourceType":""}, {"accessPath":"","checked":false,"delFlag":0,"parentID":1,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":4,"resourceName":"配置管理","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":4,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":41,"resourceName":"配置","resourceOrder":0,"resourceType":""},
{"accessPath":"","checked":false,"delFlag":0,"parentID":4,"resourceCode":"","resourceDesc":"","resourceGrade":2,"resourceID":42,"resourceName":"脚本","resourceOrder":0,"resourceType":""}];
生成app
python manage.py startapp cmdbapp
cd cmdbapp
修改cmdbapp views.py
vi views.py
-- coding: utf-8 --
from future import unicode_literals
from django.shortcuts import render,render_to_response
Create your views here.
def main_page(request):
return render_to_response('main_page.html', {'user':request.user })
注册app
vi /dj/cmdb/settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cmdbapp',
]
修改url
from cmdbapp import views
设计数据库表:机房、物理服务器、虚拟机、网络设备、安全设备、存储设备、软件资产、厂商
设计机房表
-- 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()
def __unicode__(self):
return self.name
class Server(models.Model):
"""
服务器信息
"""
machinaroom= models.ForeignKey(Machinaroom)
hostname = models.CharField(max_length=128, unique=True)
sn = models.CharField('SN号', max_length=64,null=True,blank=True)
manufacturer = models.CharField(verbose_name='制造商', max_length=64, null=True, blank=True)
model = models.CharField('型号', max_length=64, null=True, blank=True)
manage_ip = models.GenericIPAddressField('管理IP', null=True, blank=True)
other_ip = models.GenericIPAddressField('其他IP', null=True, blank=True)
os_platform = models.CharField('系统', max_length=16, null=True, blank=True)
os_version = models.CharField('系统版本', max_length=16, null=True, blank=True)
cpu_count = models.IntegerField('CPU个数', null=True, blank=True)
cpu_physical_count = models.IntegerField('CPU物理个数', null=True, blank=True)
cpu_model = models.CharField('CPU型号', max_length=128, null=True, blank=True)
memory_model=models.CharField('memory型号', max_length=128, null=True, blank=True)
memory_size=models.CharField('memory大小',max_length=128, null=True, blank=True)
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
class Meta:
verbose_name_plural = "服务器表"
def __str__(self):
return self.hostname
class VirtualMachina(models.Model):
"""虚拟机信息"""
server= models.ForeignKey(Server)
hostname = models.CharField(max_length=128, unique=True)
manage_ip = models.GenericIPAddressField('管理IP', null=True, blank=True)
other_ip = models.GenericIPAddressField('其他IP', null=True, blank=True)
os_platform = models.CharField('系统', max_length=16, null=True, blank=True)
os_version = models.CharField('系统版本', max_length=16, null=True, blank=True)
cpu_memo = models.CharField('CPU信息',max_length=128, null=True, blank=True)
memory_size=models.CharField('memory大小',max_length=128, null=True, blank=True)
disk_count=models.CharField('硬盘信息',max_length=200, null=True, blank=True)
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
id =models.AutoField(primary_key=True)
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'端口个数', null=True, blank=True)
device_detail = models.TextField(u'设置详细配置', null=True, blank=True)
model = models.CharField(u'型号', max_length=128, null=True, blank=True)
manage_ip = models.GenericIPAddressField('管理IP', null=True, blank=True)
other_ip = models.GenericIPAddressField('其他IP', null=True, blank=True)
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)
hostname = models.CharField(max_length=128, unique=True)
port_num = models.SmallIntegerField(u'端口个数', null=True, blank=True)
device_detail = models.TextField(u'设置详细配置', null=True, blank=True)
model = models.CharField(u'型号', max_length=128, null=True, blank=True)
manage_ip = models.GenericIPAddressField('管理IP', null=True, blank=True)
other_ip = models.GenericIPAddressField('其他IP', null=True, blank=True)
class Meta:
verbose_name = '安全设备'
verbose_name_plural = "安全设备"
def __str__(self):
return self.hostname
class StorageDevice(models.Model):
"""存储设备"""
model = models.CharField(u'型号', max_length=128, null=True, blank=True)
machinaroom= models.ForeignKey(Machinaroom)
id =models.AutoField(primary_key=True)
manage_ip = models.GenericIPAddressField('管理IP', null=True, blank=True)
status_choices = ((0, '在线'),
(1, '已下线'),
(2, '未知'),
(3, '故障'),
(4, '备用'),
)
status = models.SmallIntegerField(choices=status_choices, default=0)
disk_memo=models.CharField('容量信息',max_length=200, null=True, blank=True)
memo = models.TextField(u'备注', blank=True, null=True)
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="授权数")
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, blank=True)
memo = models.CharField(u'备注', max_length=128, blank=True)
def __str__(self):
return self.manufactory
class Meta:
verbose_name = '厂商'
verbose_name_plural = "厂商"
同步数据库
python manage.py makemigrations
python manage.py migrate