Commit 426c3c40 authored by wangyong's avatar wangyong

add asset amdin|sys user model

parent d96ac564
...@@ -22,7 +22,8 @@ class IDCSerializer(serializers.ModelSerializer): ...@@ -22,7 +22,8 @@ class IDCSerializer(serializers.ModelSerializer):
class Meta: class Meta:
model = IDC model = IDC
#fields = ('id', 'title', 'code', 'linenos', 'language', 'style') #fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
class AssetGroupViewSet(viewsets.ModelViewSet): class AssetGroupViewSet(viewsets.ModelViewSet):
""" """
API endpoint that allows AssetGroup to be viewed or edited. API endpoint that allows AssetGroup to be viewed or edited.
...@@ -30,6 +31,7 @@ class AssetGroupViewSet(viewsets.ModelViewSet): ...@@ -30,6 +31,7 @@ class AssetGroupViewSet(viewsets.ModelViewSet):
queryset = AssetGroup.objects.all() queryset = AssetGroup.objects.all()
serializer_class = AssetGroupSerializer serializer_class = AssetGroupSerializer
class AssetViewSet(viewsets.ModelViewSet): class AssetViewSet(viewsets.ModelViewSet):
""" """
API endpoint that allows Asset to be viewed or edited. API endpoint that allows Asset to be viewed or edited.
...@@ -37,6 +39,7 @@ class AssetViewSet(viewsets.ModelViewSet): ...@@ -37,6 +39,7 @@ class AssetViewSet(viewsets.ModelViewSet):
queryset = Asset.objects.all() queryset = Asset.objects.all()
serializer_class = AssetSerializer serializer_class = AssetSerializer
class IDCViewSet(viewsets.ModelViewSet): class IDCViewSet(viewsets.ModelViewSet):
""" """
API endpoint that allows IDC to be viewed or edited. API endpoint that allows IDC to be viewed or edited.
......
...@@ -10,8 +10,8 @@ class AssetForm(forms.ModelForm): ...@@ -10,8 +10,8 @@ class AssetForm(forms.ModelForm):
model = Asset model = Asset
fields = [ fields = [
"ip", "other_ip", "hostname", "port", "group", "username", "password", "idc", "mac_addr", "ip", "other_ip", "remote_card_ip", "hostname", "port", "group", "username", "password",
"remote_card_ip", "brand", "cpu", "memory", "disk", "os", "cabinet_no", "cabinet_pos", "idc", "mac_addr", "brand", "cpu", "memory", "disk", "os", "cabinet_no", "cabinet_pos",
"number", "status", "type", "env", "sn", "is_active", "comment" "number", "status", "type", "env", "sn", "is_active", "comment"
] ]
......
...@@ -33,44 +33,54 @@ class IDC(models.Model): ...@@ -33,44 +33,54 @@ class IDC(models.Model):
class Meta: class Meta:
db_table = 'idc' db_table = 'idc'
verbose_name = u"IDC机房"
verbose_name_plural = verbose_name
class AssetExtend(models.Model): class AssetExtend(models.Model):
pass key = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'key')
value = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'value')
created_by = models.CharField(max_length=32, blank=True, verbose_name=u"创建者")
date_added = models.DateTimeField(auto_now=True, null=True, blank=True)
comment = models.CharField(max_length=128, blank=True, verbose_name=u"备注")
def __unicode__(self):
return self.name
class Meta:
db_table = 'assetextend'
class Asset(models.Model): class Asset(models.Model):
ip = models.CharField(max_length=32, blank=True, verbose_name="资产IP") ip = models.CharField(max_length=32, null=True, blank=True, verbose_name="资产IP")
other_ip = models.CharField(max_length=255, blank=True, verbose_name="其他IP") other_ip = models.CharField(max_length=255, null=True, blank=True, verbose_name="其他IP")
remote_card_ip = models.CharField(max_length=16, blank=True, verbose_name=u'远控卡IP') remote_card_ip = models.CharField(max_length=16, null=True, blank=True, verbose_name=u'远控卡IP')
hostname = models.CharField(max_length=128, unique=True, blank=True, verbose_name=u"主机名") hostname = models.CharField(max_length=128, unique=True, null=True, blank=True, verbose_name=u"主机名")
port = models.IntegerField(blank=True, verbose_name=u"端口") port = models.IntegerField(null=True, blank=True, verbose_name=u"端口")
group = models.ManyToManyField(AssetGroup, blank=True, verbose_name=u"所属主机组") group = models.ManyToManyField(AssetGroup, null=True, blank=True, verbose_name=u"所属主机组")
username = models.CharField(max_length=16, blank=True, verbose_name=u"管理用户名") admin_user = models.ForeignKey(AdminUser, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=u'管理用户')
password = models.CharField(max_length=256, blank=True, verbose_name=u"密码") sys_user = models.ManyToManyField(AssetExtend, null=True, blank=True, verbose_name="系统用户")
idc = models.ForeignKey(IDC, blank=True, null=True, on_delete=models.SET_NULL, verbose_name=u'机房') username = models.CharField(max_length=16, null=True, blank=True, verbose_name=u"管理用户名")
mac_addr = models.CharField(max_length=20, blank=True, unique=True, verbose_name=u"MAC地址") password = models.CharField(max_length=256, null=True, blank=True, verbose_name=u"密码")
brand = models.CharField(max_length=64, blank=True, verbose_name=u'硬件厂商型号') idc = models.ForeignKey(IDC, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=u'机房')
cpu = models.CharField(max_length=64, blank=True, verbose_name=u'CPU') mac_addr = models.CharField(max_length=20, null=True, blank=True, verbose_name=u"MAC地址")
memory = models.CharField(max_length=128, blank=True, verbose_name=u'内存') brand = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'硬件厂商型号')
disk = models.CharField(max_length=1024, blank=True, verbose_name=u'硬盘') cpu = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'CPU')
os = models.CharField(max_length=128, blank=True, verbose_name=u'系统信息') memory = models.CharField(max_length=128, null=True, blank=True, verbose_name=u'内存')
cabinet_no = models.CharField(max_length=32, blank=True, verbose_name=u'机柜号') disk = models.CharField(max_length=1024, null=True, blank=True, verbose_name=u'硬盘')
os = models.CharField(max_length=128, null=True, blank=True, verbose_name=u'系统信息')
cabinet_no = models.CharField(max_length=32, null=True, blank=True, verbose_name=u'机柜号')
cabinet_pos = models.IntegerField(null=True, blank=True, verbose_name=u'资产位置') cabinet_pos = models.IntegerField(null=True, blank=True, verbose_name=u'资产位置')
number = models.CharField(max_length=32, blank=True, unique=True, verbose_name=u'资产编号') number = models.CharField(max_length=32, null=True, blank=True, verbose_name=u'资产编号')
status = models.ManyToManyField(AssetExtend, blank=True, status = models.ManyToManyField(AssetExtend, null=True, blank=True,
related_name="asset_status_extend", verbose_name="资产状态") related_name="asset_status_extend", verbose_name="资产状态")
type = models.ManyToManyField(AssetExtend, blank=True, type = models.ManyToManyField(AssetExtend, null=True, blank=True,
related_name="asset_type_extend", verbose_name="资产类型") related_name="asset_type_extend", verbose_name="资产类型")
env = models.ManyToManyField(AssetExtend, blank=True, env = models.ManyToManyField(AssetExtend, null=True, blank=True,
related_name="asset_env_extend", verbose_name="所属主机组环境") related_name="asset_env_extend", verbose_name="资产环境")
sn = models.CharField(max_length=128, blank=True, unique=True, verbose_name=u"SN编号") sn = models.CharField(max_length=128, null=True, blank=True, verbose_name=u"SN编号")
created_by = models.CharField(max_length=32, blank=True, verbose_name=u"创建者") created_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=u"创建者")
is_active = models.BooleanField(default=True, verbose_name=u"是否激活") is_active = models.BooleanField(default=True, verbose_name=u"是否激活")
date_added = models.DateTimeField(auto_now=True, null=True) date_added = models.DateTimeField(auto_now=True, null=True, blank=True)
comment = models.CharField(max_length=128, blank=True, verbose_name=u"备注") comment = models.CharField(max_length=128, null=True, blank=True, verbose_name=u"备注")
def __unicode__(self): def __unicode__(self):
return self.ip return self.ip
...@@ -79,12 +89,59 @@ class Asset(models.Model): ...@@ -79,12 +89,59 @@ class Asset(models.Model):
db_table = 'asset' db_table = 'asset'
class Label(models.Model):
key = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'key')
value = models.CharField(max_length=64, null=True, blank=True, verbose_name=u'value')
asset = models.ForeignKey(Asset, null=True, blank=True, on_delete=models.SET_NULL, verbose_name=u'label')
created_by = models.CharField(max_length=32, blank=True, verbose_name=u"创建者")
date_added = models.DateTimeField(auto_now=True, null=True, blank=True)
comment = models.CharField(max_length=128, blank=True, verbose_name=u"备注")
def __unicode__(self):
return self.name
class Meta:
db_table = 'label'
class AdminUser(models.Model):
name = models.CharField(max_length=128, unique=True, null=True, blank=True, verbose_name=u"用户名称")
username = models.CharField(max_length=16, null=True, blank=True, verbose_name=u"用户名")
password = models.CharField(max_length=256, null=True, blank=True, verbose_name=u"密码")
private_key = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"私钥")
is_default = models.BooleanField(default=True, verbose_name=u"是否默认")
auto_update = models.BooleanField(default=True, verbose_name=u"自动更新")
date_added = models.DateTimeField(auto_now=True, null=True, blank=True)
create_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=u"创建者")
comment = models.CharField(max_length=128, blank=True, verbose_name=u"备注")
def __unicode__(self):
return self.name
class Meta:
db_table = 'adminuser'
class SysUser(models.Model):
name = models.CharField(max_length=128, unique=True, null=True, blank=True, verbose_name=u"用户名称")
username = models.CharField(max_length=16, null=True, blank=True, verbose_name=u"用户名")
password = models.CharField(max_length=256, null=True, blank=True, verbose_name=u"密码")
protocol = models.CharField(max_length=16, null=True, blank=True, verbose_name=u"协议")
private_key = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"私钥")
public_key = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"公钥")
is_default = models.BooleanField(default=True, verbose_name=u"是否显示")
auto_push = models.BooleanField(default=True, verbose_name=u"自动推送")
auto_update = models.BooleanField(default=True, verbose_name=u"自动更新")
sudo = models.CharField(max_length=4096, null=True, blank=True, verbose_name=u"私钥")
shell = models.CharField(max_length=64, null=True, blank=True, verbose_name=u"shell环境")
home = models.CharField(max_length=64, null=True, blank=True, verbose_name=u"home目录")
uid = models.IntegerField(null=True, blank=True, verbose_name=u"uid")
date_added = models.DateTimeField(auto_now=True, null=True, blank=True)
create_by = models.CharField(max_length=32, null=True, blank=True, verbose_name=u"创建者")
comment = models.CharField(max_length=128, blank=True, verbose_name=u"备注")
def __unicode__(self):
return self.name
class Meta:
db_table = 'sysuser'
This diff is collapsed.
# coding:utf-8 # coding:utf-8
from django.conf.urls import url,include from django.conf.urls import url, include
from .views import * from .views import *
from .api import ( # from .api import (
AssetGroupViewSet,AssetViewSet,IDCViewSet # AssetGroupViewSet, AssetViewSet, IDCViewSet
) # )
from rest_framework import routers # from rest_framework import routers
router = routers.DefaultRouter() # router = routers.DefaultRouter()
router.register(r'assetgroup', AssetGroupViewSet) # router.register(r'assetgroup', AssetGroupViewSet)
router.register(r'asset', AssetViewSet) # router.register(r'asset', AssetViewSet)
router.register(r'idc', IDCViewSet) # router.register(r'idc', IDCViewSet)
app_name = 'assets' app_name = 'assets'
urlpatterns = [ urlpatterns = [
url(r'^add/$', AssetAddView.as_view(), name='asset-add'), url(r'^assets/add/$', AssetAddView.as_view(), name='asset-add'),
url(r'^$', AssetListView.as_view(), name='asset-list'), url(r'^$', AssetListView.as_view(), name='asset-list'),
url(r'^(?P<pk>[0-9]+)/delete/$', AssetDeleteView.as_view(), name='asset-list'), url(r'^(?P<pk>[0-9]+)/delete/$', AssetDeleteView.as_view(), name='asset-delete'),
url(r'^(?P<pk>[0-9]+)/detail/$', AssetDetailView.as_view(), name='asset-detail'), url(r'^(?P<pk>[0-9]+)/detail/$', AssetDetailView.as_view(), name='asset-detail'),
url(r'^api/v1.0/', include(router.urls)), # url(r'^api/v1.0/', include(router.urls)),
] ]
# ~*~ coding: utf-8 ~*~ # ~*~ coding: utf-8 ~*~
# #
from django.contrib.auth.mixins import UserPassesTestMixin
from django.urls import reverse_lazy
from common.tasks import send_mail_async
from common.utils import reverse
from users.models import User
try:
import cStringIO as StringIO
except ImportError:
import StringIO
class AdminUserRequiredMixin(UserPassesTestMixin):
login_url = reverse_lazy('users:login')
def test_func(self):
return self.request.user.is_staff
from django.views.generic import ( from django.views.generic import TemplateView, ListView
TemplateView, ListView
)
from django.urls import reverse_lazy from django.urls import reverse_lazy
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
from django.views.generic.detail import DetailView
from .models import Asset, AssetGroup, IDC, AssetExtend
from .forms import AssetForm
from .utils import AdminUserRequiredMixin
from django.views.generic.edit import (
CreateView, DeleteView, FormView, UpdateView
)
from django.views.generic.detail import (
DetailView
)
from .models import (
Asset, AssetGroup, IDC, AssetExtend
)
class AssetAddView(AdminUserRequiredMixin, CreateView):
from .forms import (
AssetForm,
)
class AssetAddView(CreateView):
model = Asset model = Asset
form_class = AssetForm form_class = AssetForm
template_name = 'assets/asset_add.html' template_name = 'assets/asset_add.html'
success_url = reverse_lazy('assets:asset-list') success_url = reverse_lazy('assets:asset-list')
def form_invalid(self, form):
print(form.errors)
return super(AssetAddView, self).form_invalid(form)
class AssetEdit(): class AssetEditView():
pass pass
......
...@@ -130,7 +130,7 @@ else: ...@@ -130,7 +130,7 @@ else:
# Password validation # Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
#
AUTH_PASSWORD_VALIDATORS = [ AUTH_PASSWORD_VALIDATORS = [
{ {
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
......
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-21 09:54
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0003_auto_20160814_1758'),
]
operations = [
migrations.AlterField(
model_name='user',
name='email',
field=models.EmailField(max_length=30, unique=True, verbose_name='\u90ae\u4ef6'),
),
migrations.AlterField(
model_name='user',
name='groups',
field=models.ManyToManyField(to='users.UserGroup', verbose_name='\u7528\u6237\u7ec4'),
),
migrations.AlterField(
model_name='user',
name='name',
field=models.CharField(max_length=20, verbose_name='\u59d3\u540d'),
),
migrations.AlterField(
model_name='user',
name='username',
field=models.CharField(max_length=20, unique=True, verbose_name='\u7528\u6237\u540d'),
),
]
...@@ -19,8 +19,8 @@ apps_dir = os.path.join(BASE_DIR, 'apps') ...@@ -19,8 +19,8 @@ apps_dir = os.path.join(BASE_DIR, 'apps')
def start_django(): def start_django():
http_host = CONFIG.HTTP_BIND_HOST or 'locahost' http_host = CONFIG.HTTP_LISTEN_HOST or 'locahost'
http_port = CONFIG.HTTP_LISTEN_HOST or '8080' http_port = CONFIG.HTTP_LISTEN_PORT or '8080'
os.chdir(apps_dir) os.chdir(apps_dir)
print('start django') print('start django')
subprocess.call('python ./manage.py runserver %s:%s' % (http_host, http_port), shell=True) subprocess.call('python ./manage.py runserver %s:%s' % (http_host, http_port), shell=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment