diff --git a/jasset/forms.py b/jasset/forms.py new file mode 100644 index 000000000..648390600 --- /dev/null +++ b/jasset/forms.py @@ -0,0 +1,14 @@ +# coding:utf-8 +from django import forms + +from jasset.models import IDC, Asset, AssetGroup + + +class AssetForm(forms.ModelForm): + class Meta: + model = Asset + fields = [ + "ip", "second_ip", "hostname", "port", "group", "username", "password", "use_default_auth", + "idc", "mac", "remote_ip", "brand", "cpu", "memory", "disk", "system_type", "system_version", + "cabinet", "position", "number", "status", "asset_type", "env", "sn", "is_active", "comment" + ] \ No newline at end of file diff --git a/jasset/models.py b/jasset/models.py index 3d7b5e774..76757d448 100644 --- a/jasset/models.py +++ b/jasset/models.py @@ -1,4 +1,3 @@ -# coding=utf-8 # coding: utf-8 import datetime @@ -61,45 +60,22 @@ class AssetGroup(models.Model): return False -class AssetType(models.Model): - name = models.CharField(max_length=16, verbose_name=u"机器类型名") - comment = models.CharField(max_length=16, blank=True, null=True, verbose_name=u"备注") +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'机房带宽') + linkman = models.CharField(max_length=16, null=True, verbose_name=u'联系人') + phone = models.CharField(max_length=32, verbose_name=u'联系电话') + address = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"机房地址") + network = models.TextField(blank=True, null=True, verbose_name=u"IP地址段") + date_added = models.DateField(auto_now=True, default=datetime.datetime.now(), null=True) + operator = models.IntegerField(max_length=32, blank=True, null=True, verbose_name=u"运营商") + comment = models.TextField(blank=True, null=True, verbose_name=u"备注") def __unicode__(self): return self.name class Meta: - verbose_name = u"机器类型" - verbose_name_plural = verbose_name - - -class Project(models.Model): - name = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'项目名') - manager = models.CharField(max_length=16, blank=True, null=True, verbose_name=u'项目负责人') - comment = models.TextField(blank=True, null=True, verbose_name=u'项目说明') - - def __unicode__(self): - return self.name - - class Meta: - verbose_name = u"项目" - verbose_name_plural = verbose_name - - -class Service(models.Model): - """ - 服务,如nginx, haproxy, php.... - """ - name = models.CharField(max_length=32, null=True, blank=True, verbose_name=u"服务名称") - port = models.IntegerField(null=True, blank=True, verbose_name=u"端口") - path = models.CharField(max_length=64, null=True, blank=True, verbose_name=u"程序路径") - comment = models.TextField(null=True, blank=True, verbose_name=u"备注") - - def __unicode__(self): - return self.name - - class Meta: - verbose_name = u"服务" + verbose_name = u"IDC机房" verbose_name_plural = verbose_name @@ -116,7 +92,13 @@ class Asset(models.Model): (1, u"未使用"), (2, u"报废") ) - ip = models.IPAddressField(unique=True, verbose_name=u"IP1") + ASSET_TYPE = ( + (0, u"服务器"), + (2, u"网络设备"), + (3, u"其他") + ) + + ip = models.IPAddressField(unique=True, verbose_name=u"主机IP") second_ip = models.IPAddressField(unique=True, blank=True, null=True, verbose_name=u"IP2") hostname = models.CharField(max_length=64, blank=True, null=True, verbose_name=u"主机名") port = models.IntegerField(max_length=6, verbose_name=u"端口号") @@ -133,19 +115,13 @@ class Asset(models.Model): 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"系统类型") system_version = models.CharField(max_length=8, blank=True, null=True, verbose_name=u"版本号") - guarantee_date = models.DateField(blank=True, null=True, verbose_name=u'保修时间') cabinet = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'机柜号') position = models.IntegerField(max_length=2, blank=True, null=True, verbose_name=u'机器位置') number = models.CharField(max_length=32, blank=True, null=True, verbose_name=u'资产编号') - project = models.ManyToManyField(Project, blank=True, null=True, verbose_name=u'所属项目') - service = models.ManyToManyField(Service, blank=True, null=True, verbose_name=u'运行服务') status = models.IntegerField(max_length=2, choices=SERVER_STATUS, default=1, verbose_name=u"机器状态") - parent = models.ForeignKey("self", blank=True, null=True, verbose_name=u"虚拟机父主机") - type = models.ManyToManyField(AssetType, blank=True, null=True, verbose_name=u"主机类型") - service_code = models.CharField(max_length=16, blank=True, null=True, verbose_name=u"快速服务编码") + asset_type = models.IntegerField(max_length=2, choices=ASSET_TYPE, blank=True, null=True, verbose_name=u"主机类型") env = models.CharField(max_length=32, choices=ENVIRONMENT, blank=True, null=True, verbose_name=u"运行环境") sn = models.CharField(max_length=32, blank=True, null=True, verbose_name=u"SN编号") - switch_port = models.CharField(max_length=12, blank=True, null=True, verbose_name=u"交换机端口号") date_added = models.DateTimeField(auto_now=True, default=datetime.datetime.now(), null=True) is_active = models.BooleanField(default=True, verbose_name=u"是否激活") comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"备注") @@ -170,25 +146,6 @@ class Asset(models.Model): return user_permed_list -class IDC(models.Model): - name = models.CharField(max_length=64, verbose_name=u'机房名称') - bandwidth = models.CharField(max_length=64, blank=True, null=True, verbose_name=u'机房带宽') - linkman = models.CharField(max_length=32, null=True, verbose_name=u'联系人') - phone = models.CharField(max_length=32, verbose_name=u'联系电话') - address = models.CharField(max_length=128, blank=True, null=True, verbose_name=u"机房地址") - network = models.TextField(blank=True, null=True, verbose_name=u"IP地址段") - create_time = models.DateField(auto_now=True) - operator = models.IntegerField(max_length=32 ,blank=True, null=True, verbose_name=u"运营商") - comment = models.TextField(blank=True, null=True, verbose_name=u"备注") - - def __unicode__(self): - return self.name - - class Meta: - verbose_name = u"IDC机房" - verbose_name_plural = verbose_name - - class AssetAlias(models.Model): user = models.ForeignKey(User) asset = models.ForeignKey(Asset) diff --git a/jasset/views.py b/jasset/views.py index 259a7357d..d10448b4c 100644 --- a/jasset/views.py +++ b/jasset/views.py @@ -8,6 +8,7 @@ from django.shortcuts import get_object_or_404 from jasset.asset_api import * from jumpserver.api import * +from jasset.forms import AssetForm @require_role('admin') @@ -85,6 +86,7 @@ def asset_add(request): """ header_title, path1, path2 = u'添加资产', u'资产管理', u'添加资产' asset_group_all = AssetGroup.objects.all() + af = AssetForm() if request.method == 'POST': ip = request.POST.get('ip') port = request.POST.get('port') diff --git a/jumpserver/settings.py b/jumpserver/settings.py index ce4d7e8b5..f6afa68f7 100644 --- a/jumpserver/settings.py +++ b/jumpserver/settings.py @@ -54,6 +54,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', + "bootstrapform", 'jumpserver', 'juser', 'jasset', @@ -129,4 +130,6 @@ USE_TZ = False STATIC_URL = '/static/' +BOOTSTRAP_COLUMN_COUNT = 10 + diff --git a/templates/jasset/asset_add.html b/templates/jasset/asset_add.html index bbf8b196f..53c153740 100644 --- a/templates/jasset/asset_add.html +++ b/templates/jasset/asset_add.html @@ -1,5 +1,6 @@ {% extends 'base.html' %} {% load mytags %} +{% load bootstrap %} {% block content %} {% include 'nav_cat_bar.html' %}
@@ -39,9 +40,10 @@
{{ msg }}
{% endif %}
-
-
-
+ + + + {{ af.ip|bootstrap_horizontal }}