2019-01-15

管理系统CMDB

生成app

python manage.py startapp cmdbapp
cd cmdbapp

修改cmdbapp views.py

-- coding: utf-8 --
from future import unicode_literals
from django.shortcuts import render,render_to_response

def main_page(request):
    return render_to_response('main_page.html', {'user':request.user })

注册APP

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

同步数据库

python manage.py makemigrations
python manage.py migrate

你可能感兴趣的:(2019-01-15)