Django 搭建CMDB系统完整[4](主菜单、资产数据库表)

修改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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 213,558评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,002评论 3 387
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,036评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,024评论 1 285
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,144评论 6 385
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,255评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,295评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,068评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,478评论 1 305
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,789评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,965评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,649评论 4 336
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,267评论 3 318
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,982评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,223评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,800评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,847评论 2 351

推荐阅读更多精彩内容