jumpserver/jasset/models.py

111 lines
4.8 KiB
Python
Raw Normal View History

2015-10-27 12:13:23 +00:00
# coding: utf-8
2015-04-20 02:12:11 +00:00
import datetime
from django.db import models
2015-08-26 16:08:20 +00:00
from juser.models import User, UserGroup
2015-04-20 02:12:11 +00:00
2015-11-08 14:39:30 +00:00
ASSET_ENV = (
(1, U'生产环境'),
(2, U'测试环境')
2015-11-03 15:53:12 +00:00
)
ASSET_STATUS = (
2015-11-08 14:39:30 +00:00
(1, u"已使用"),
(2, u"未使用"),
(3, u"报废")
2015-11-03 15:53:12 +00:00
)
ASSET_TYPE = (
2015-11-26 15:42:58 +00:00
(1, u"物理机"),
(2, u"虚拟机"),
(3, u"交换机"),
(4, u"路由器"),
(5, u"防火墙"),
(6, u"Docker"),
(7, u"其他")
2015-11-03 15:53:12 +00:00
)
2015-04-20 02:12:11 +00:00
2015-09-08 16:19:17 +00:00
class AssetGroup(models.Model):
2015-04-20 02:12:11 +00:00
GROUP_TYPE = (
('P', 'PRIVATE'),
('A', 'ASSET'),
)
name = models.CharField(max_length=80, unique=True)
comment = models.CharField(max_length=160, blank=True, null=True)
def __unicode__(self):
return self.name
2015-10-31 01:23:10 +00:00
class IDC(models.Model):
name = models.CharField(max_length=32, verbose_name=u'机房名称')
bandwidth = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机房带宽')
2015-11-17 15:34:13 +00:00
linkman = models.CharField(max_length=16, blank=True, null=True, verbose_name=u'联系人')
phone = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'联系电话')
2015-10-31 01:23:10 +00:00
address = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"机房地址")
network = models.TextField(blank=True, null=True, verbose_name=u"IP地址段")
2015-11-15 15:30:37 +00:00
date_added = models.DateField(auto_now=True, null=True)
2015-11-21 10:28:25 +00:00
operator = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"运营商")
2015-11-12 16:03:51 +00:00
comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"备注")
2015-10-27 12:13:23 +00:00
def __unicode__(self):
return self.name
class Meta:
2015-10-31 01:23:10 +00:00
verbose_name = u"IDC机房"
2015-10-27 12:13:23 +00:00
verbose_name_plural = verbose_name
2015-08-20 15:42:27 +00:00
2015-04-20 02:12:11 +00:00
class Asset(models.Model):
2015-10-27 12:13:23 +00:00
"""
asset modle
"""
2015-11-23 15:55:19 +00:00
ip = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"主机IP")
2015-11-08 14:39:30 +00:00
other_ip = models.CharField(max_length=255, blank=True, null=True, verbose_name=u"其他IP")
2015-11-21 10:28:25 +00:00
hostname = models.CharField(unique=True, max_length=128, verbose_name=u"主机名")
port = models.IntegerField(blank=True, null=True, verbose_name=u"端口号")
2015-11-16 05:49:39 +00:00
group = models.ManyToManyField(AssetGroup, blank=True, verbose_name=u"所属主机组")
2015-10-27 12:13:23 +00:00
username = models.CharField(max_length=16, blank=True, null=True, verbose_name=u"管理用户名")
password = models.CharField(max_length=64, blank=True, null=True, verbose_name=u"密码")
use_default_auth = models.BooleanField(default=True, verbose_name=u"使用默认管理账号")
idc = models.ForeignKey(IDC, blank=True, null=True, on_delete=models.SET_NULL, verbose_name=u'机房')
mac = models.CharField(max_length=20, blank=True, null=True, verbose_name=u"MAC地址")
2015-11-21 10:28:25 +00:00
remote_ip = models.CharField(max_length=16, blank=True, null=True, verbose_name=u'远控卡IP')
2015-10-27 12:13:23 +00:00
brand = models.CharField(max_length=64, blank=True, null=True, verbose_name=u'硬件厂商型号')
cpu = models.CharField(max_length=64, blank=True, null=True, verbose_name=u'CPU')
memory = models.CharField(max_length=128, blank=True, null=True, verbose_name=u'内存')
disk = models.CharField(max_length=128, blank=True, null=True, verbose_name=u'硬盘')
system_type = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"系统类型")
2015-11-22 15:53:25 +00:00
system_version = models.CharField(max_length=8, blank=True, null=True, verbose_name=u"系统版本号")
2015-10-27 12:13:23 +00:00
cabinet = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机柜号')
2015-11-16 05:49:39 +00:00
position = models.IntegerField(blank=True, null=True, verbose_name=u'机器位置')
2015-10-27 12:13:23 +00:00
number = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'资产编号')
2015-11-16 05:49:39 +00:00
status = models.IntegerField(choices=ASSET_STATUS, blank=True, null=True, default=1, verbose_name=u"机器状态")
asset_type = models.IntegerField(choices=ASSET_TYPE, blank=True, null=True, verbose_name=u"主机类型")
env = models.IntegerField(choices=ASSET_ENV, blank=True, null=True, verbose_name=u"运行环境")
2015-11-14 15:09:13 +00:00
sn = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"SN编号")
2015-11-15 15:30:37 +00:00
date_added = models.DateTimeField(auto_now=True, null=True)
2015-10-27 12:13:23 +00:00
is_active = models.BooleanField(default=True, verbose_name=u"是否激活")
comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"备注")
2015-04-20 02:12:11 +00:00
def __unicode__(self):
return self.ip
2015-11-08 14:39:30 +00:00
class AssetRecord(models.Model):
asset = models.ForeignKey(Asset)
username = models.CharField(max_length=30, null=True)
alert_time = models.DateTimeField(auto_now_add=True)
content = models.TextField(null=True, blank=True)
comment = models.TextField(null=True, blank=True)
2015-08-20 15:42:27 +00:00
2015-04-20 02:12:11 +00:00
class AssetAlias(models.Model):
user = models.ForeignKey(User)
2015-06-09 15:06:32 +00:00
asset = models.ForeignKey(Asset)
2015-04-20 02:12:11 +00:00
alias = models.CharField(max_length=100, blank=True, null=True)
def __unicode__(self):
2015-11-15 11:57:25 +00:00
return self.alias