mirror of https://github.com/jumpserver/jumpserver
parent
32fd9bb42f
commit
27a1849b1d
@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
__all__ = ['Cluster']
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Cluster(models.Model):
|
||||
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
||||
name = models.CharField(max_length=32, verbose_name=_('Name'))
|
||||
bandwidth = models.CharField(max_length=32, blank=True, verbose_name=_('Bandwidth'))
|
||||
contact = models.CharField(max_length=128, blank=True, verbose_name=_('Contact'))
|
||||
phone = models.CharField(max_length=32, blank=True, verbose_name=_('Phone'))
|
||||
address = models.CharField(max_length=128, blank=True, verbose_name=_("Address"))
|
||||
intranet = models.TextField(blank=True, verbose_name=_('Intranet'))
|
||||
extranet = models.TextField(blank=True, verbose_name=_('Extranet'))
|
||||
date_created = models.DateTimeField(auto_now_add=True, null=True, verbose_name=_('Date created'))
|
||||
operator = models.CharField(max_length=32, blank=True, verbose_name=_('Operator'))
|
||||
created_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by'))
|
||||
comment = models.TextField(blank=True, verbose_name=_('Comment'))
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
@classmethod
|
||||
def initial(cls):
|
||||
return cls.objects.get_or_create(name=_('Default'), created_by=_('System'), comment=_('Default Cluster'))[0]
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
|
||||
@classmethod
|
||||
def generate_fake(cls, count=5):
|
||||
from random import seed, choice
|
||||
import forgery_py
|
||||
from django.db import IntegrityError
|
||||
|
||||
seed()
|
||||
for i in range(count):
|
||||
cluster = cls(name=forgery_py.name.full_name(),
|
||||
bandwidth='200M',
|
||||
contact=forgery_py.name.full_name(),
|
||||
phone=forgery_py.address.phone(),
|
||||
address=forgery_py.address.city() + forgery_py.address.street_address(),
|
||||
operator=choice(['北京联通', '北京电信', 'BGP全网通']),
|
||||
comment=forgery_py.lorem_ipsum.sentence(),
|
||||
created_by='Fake')
|
||||
try:
|
||||
cluster.save()
|
||||
logger.debug('Generate fake asset group: %s' % cluster.name)
|
||||
except IntegrityError:
|
||||
print('Error continue')
|
||||
continue
|
@ -1,71 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import logging
|
||||
import uuid
|
||||
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
__all__ = ['IDC']
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IDC(models.Model):
|
||||
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
||||
name = models.CharField(max_length=32, verbose_name=_('Name'))
|
||||
bandwidth = models.CharField(
|
||||
max_length=32, blank=True, verbose_name=_('Bandwidth'))
|
||||
contact = models.CharField(
|
||||
max_length=128, blank=True, verbose_name=_('Contact'))
|
||||
phone = models.CharField(max_length=32, blank=True,
|
||||
verbose_name=_('Phone'))
|
||||
address = models.CharField(
|
||||
max_length=128, blank=True, verbose_name=_("Address"))
|
||||
intranet = models.TextField(blank=True, verbose_name=_('Intranet'))
|
||||
extranet = models.TextField(blank=True, verbose_name=_('Extranet'))
|
||||
date_created = models.DateTimeField(
|
||||
auto_now_add=True, null=True, verbose_name=_('Date created'))
|
||||
operator = models.CharField(
|
||||
max_length=32, blank=True, verbose_name=_('Operator'))
|
||||
created_by = models.CharField(
|
||||
max_length=32, blank=True, verbose_name=_('Created by'))
|
||||
comment = models.TextField(blank=True, verbose_name=_('Comment'))
|
||||
|
||||
def __unicode__(self):
|
||||
return self.name
|
||||
__str__ = __unicode__
|
||||
|
||||
@classmethod
|
||||
def initial(cls):
|
||||
return cls.objects.get_or_create(name=_('Default'), created_by=_('System'), comment=_('Default IDC'))[0]
|
||||
|
||||
class Meta:
|
||||
ordering = ['name']
|
||||
|
||||
@classmethod
|
||||
def generate_fake(cls, count=5):
|
||||
from random import seed, choice
|
||||
import forgery_py
|
||||
from django.db import IntegrityError
|
||||
|
||||
seed()
|
||||
for i in range(count):
|
||||
idc = cls(name=forgery_py.name.full_name(),
|
||||
bandwidth='200M',
|
||||
contact=forgery_py.name.full_name(),
|
||||
phone=forgery_py.address.phone(),
|
||||
address=forgery_py.address.city() + forgery_py.address.street_address(),
|
||||
operator=choice(['北京联通', '北京电信', 'BGP全网通']),
|
||||
comment=forgery_py.lorem_ipsum.sentence(),
|
||||
created_by='Fake')
|
||||
try:
|
||||
idc.save()
|
||||
logger.debug('Generate fake asset group: %s' % idc.name)
|
||||
except IntegrityError:
|
||||
print('Error continue')
|
||||
continue
|
@ -1,7 +1,7 @@
|
||||
# coding:utf-8
|
||||
from .asset import *
|
||||
from .group import *
|
||||
from .idc import *
|
||||
from .cluster import *
|
||||
from .system_user import *
|
||||
from .admin_user import *
|
||||
|
||||
|
@ -0,0 +1,101 @@
|
||||
# coding:utf-8
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import TemplateView, ListView, View
|
||||
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin
|
||||
from .. import forms
|
||||
from ..models import Asset, AssetGroup, AdminUser, Cluster, SystemUser
|
||||
from ..hands import AdminUserRequiredMixin
|
||||
|
||||
|
||||
__all__ = ['ClusterListView', 'ClusterCreateView', 'ClusterUpdateView',
|
||||
'ClusterDetailView', 'ClusterDeleteView', 'ClusterAssetsView']
|
||||
|
||||
|
||||
class ClusterListView(AdminUserRequiredMixin, TemplateView):
|
||||
template_name = 'assets/cluster_list.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('Cluster list'),
|
||||
# 'keyword': self.request.GET.get('keyword', '')
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(ClusterListView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
class ClusterCreateView(AdminUserRequiredMixin, CreateView):
|
||||
model = Cluster
|
||||
form_class = forms.ClusterForm
|
||||
template_name = 'assets/cluster_create_update.html'
|
||||
success_url = reverse_lazy('assets:cluster-list')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
'app': _('assets'),
|
||||
'action': _('Create Cluster'),
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(ClusterCreateView, self).get_context_data(**kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
cluster = form.save(commit=False)
|
||||
cluster.created_by = self.request.user.username or 'System'
|
||||
cluster.save()
|
||||
return super(ClusterCreateView, self).form_valid(form)
|
||||
|
||||
|
||||
class ClusterUpdateView(AdminUserRequiredMixin, UpdateView):
|
||||
model = Cluster
|
||||
form_class = forms.ClusterForm
|
||||
template_name = 'assets/cluster_create_update.html'
|
||||
context_object_name = 'cluster'
|
||||
success_url = reverse_lazy('assets:cluster-list')
|
||||
|
||||
def form_valid(self, form):
|
||||
cluster = form.save(commit=False)
|
||||
cluster.save()
|
||||
return super(ClusterUpdateView, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
'app': _('assets'),
|
||||
'action': _('Update Cluster'),
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(ClusterUpdateView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
class ClusterDetailView(AdminUserRequiredMixin, DetailView):
|
||||
model = Cluster
|
||||
template_name = 'assets/cluster_detail.html'
|
||||
context_object_name = 'cluster'
|
||||
|
||||
|
||||
class ClusterAssetsView(AdminUserRequiredMixin, DetailView):
|
||||
model = Cluster
|
||||
template_name = 'assets/cluster_assets.html'
|
||||
context_object_name = 'cluster'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
assets_remain = Asset.objects.exclude(id__in=self.object.assets.all())
|
||||
|
||||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('Asset detail'),
|
||||
'groups': AssetGroup.objects.all(),
|
||||
'system_users': SystemUser.objects.all(),
|
||||
'assets_remain': assets_remain,
|
||||
'assets': [asset for asset in Asset.objects.all() if asset not in assets_remain],
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(ClusterAssetsView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
class ClusterDeleteView(AdminUserRequiredMixin, DeleteView):
|
||||
model = Cluster
|
||||
template_name = 'assets/delete_confirm.html'
|
||||
success_url = reverse_lazy('assets:cluster-list')
|
@ -1,101 +0,0 @@
|
||||
# coding:utf-8
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import TemplateView, ListView, View
|
||||
from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateView
|
||||
from django.urls import reverse_lazy
|
||||
from django.views.generic.detail import DetailView, SingleObjectMixin
|
||||
from .. import forms
|
||||
from ..models import Asset, AssetGroup, AdminUser, IDC, SystemUser
|
||||
from ..hands import AdminUserRequiredMixin
|
||||
|
||||
|
||||
__all__ = ['IDCListView', 'IDCCreateView', 'IDCUpdateView',
|
||||
'IDCDetailView', 'IDCDeleteView', 'IDCAssetsView']
|
||||
|
||||
|
||||
class IDCListView(AdminUserRequiredMixin, TemplateView):
|
||||
template_name = 'assets/idc_list.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('IDC list'),
|
||||
# 'keyword': self.request.GET.get('keyword', '')
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(IDCListView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
class IDCCreateView(AdminUserRequiredMixin, CreateView):
|
||||
model = IDC
|
||||
form_class = forms.IDCForm
|
||||
template_name = 'assets/idc_create_update.html'
|
||||
success_url = reverse_lazy('assets:idc-list')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
'app': _('assets'),
|
||||
'action': _('Create IDC'),
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(IDCCreateView, self).get_context_data(**kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
idc = form.save(commit=False)
|
||||
idc.created_by = self.request.user.username or 'System'
|
||||
idc.save()
|
||||
return super(IDCCreateView, self).form_valid(form)
|
||||
|
||||
|
||||
class IDCUpdateView(AdminUserRequiredMixin, UpdateView):
|
||||
model = IDC
|
||||
form_class = forms.IDCForm
|
||||
template_name = 'assets/idc_create_update.html'
|
||||
context_object_name = 'idc'
|
||||
success_url = reverse_lazy('assets:idc-list')
|
||||
|
||||
def form_valid(self, form):
|
||||
idc = form.save(commit=False)
|
||||
idc.save()
|
||||
return super(IDCUpdateView, self).form_valid(form)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
'app': _('assets'),
|
||||
'action': _('Update IDC'),
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(IDCUpdateView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
class IDCDetailView(AdminUserRequiredMixin, DetailView):
|
||||
model = IDC
|
||||
template_name = 'assets/idc_detail.html'
|
||||
context_object_name = 'idc'
|
||||
|
||||
|
||||
class IDCAssetsView(AdminUserRequiredMixin, DetailView):
|
||||
model = IDC
|
||||
template_name = 'assets/idc_assets.html'
|
||||
context_object_name = 'idc'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
assets_remain = Asset.objects.exclude(id__in=self.object.assets.all())
|
||||
|
||||
context = {
|
||||
'app': _('Assets'),
|
||||
'action': _('Asset detail'),
|
||||
'groups': AssetGroup.objects.all(),
|
||||
'system_users': SystemUser.objects.all(),
|
||||
'assets_remain': assets_remain,
|
||||
'assets': [asset for asset in Asset.objects.all() if asset not in assets_remain],
|
||||
}
|
||||
kwargs.update(context)
|
||||
return super(IDCAssetsView, self).get_context_data(**kwargs)
|
||||
|
||||
|
||||
class IDCDeleteView(AdminUserRequiredMixin, DeleteView):
|
||||
model = IDC
|
||||
template_name = 'assets/delete_confirm.html'
|
||||
success_url = reverse_lazy('assets:idc-list')
|
File diff suppressed because one or more lines are too long
@ -1 +1 @@
|
||||
[{"model": "users.usergroup", "pk": "0460a32e-59c9-42cc-81a5-7e0a13fc0085", "fields": {"is_discard": false, "discard_time": null, "name": "Default", "comment": "Default user group", "date_created": "2017-11-23T03:59:09.875Z", "created_by": "System"}}, {"model": "assets.idc", "pk": "937922e3-e2b7-42aa-b460-6b276901f53a", "fields": {"name": "Default", "bandwidth": "", "contact": "", "phone": "", "address": "", "intranet": "", "extranet": "", "date_created": "2017-11-23T03:59:09.882Z", "operator": "", "created_by": "System", "comment": "Default IDC"}}, {"model": "assets.assetgroup", "pk": "f758dc94-b979-4edf-9afc-f9171f9d2d6a", "fields": {"name": "Default", "created_by": "", "date_created": "2017-11-23T03:59:09.883Z", "comment": "Default asset group", "system_users": []}}, {"model": "users.user", "pk": "bb318c48-4f50-483e-a165-89d7f18e9e95", "fields": {"password": "pbkdf2_sha256$36000$kHqN5uCVaAk9$SXWzKLwBg68/2W8NLSNJIaVBJc60F26p8RO9E3oSskI=", "last_login": null, "first_name": "", "last_name": "", "is_active": true, "date_joined": "2017-11-23T03:59:09.828Z", "username": "admin", "name": "Administrator", "email": "admin@jumpserver.org", "role": "Admin", "avatar": "", "wechat": "", "phone": null, "enable_otp": false, "secret_key_otp": "", "_private_key": "", "_public_key": "", "comment": "Administrator is the super user of system", "is_first_login": false, "date_expired": "2087-11-06T03:59:09.829Z", "created_by": "System", "user_permissions": [], "groups": ["0460a32e-59c9-42cc-81a5-7e0a13fc0085"]}}]
|
||||
[{"model": "users.usergroup", "pk": "2e0b2a25-b32f-44a0-b087-f0f17de66e26", "fields": {"is_discard": false, "discard_time": null, "name": "Default", "comment": "Default user group", "date_created": "2017-12-07T08:20:09.593Z", "created_by": "System"}}, {"model": "assets.cluster", "pk": "c0df1aa0-bde7-4226-a69a-d02976888456", "fields": {"name": "Default", "bandwidth": "", "contact": "", "phone": "", "address": "", "intranet": "", "extranet": "", "date_created": "2017-12-07T08:20:09.606Z", "operator": "", "created_by": "System", "comment": "Default Cluster"}}, {"model": "assets.assetgroup", "pk": "881a0460-7989-42af-a588-957efe57fb8e", "fields": {"name": "Default", "created_by": "", "date_created": "2017-12-07T08:20:09.610Z", "comment": "Default asset group", "system_users": []}}, {"model": "users.user", "pk": "edc529d5-0377-4456-831f-ec42cf5b34d2", "fields": {"password": "pbkdf2_sha256$36000$3VcSL8Ap6zHd$14Y4+uZHRU8gwFgEXdIEZZ2+NWV15sRBV2YWgWbdyhY=", "last_login": null, "first_name": "", "last_name": "", "is_active": true, "date_joined": "2017-12-07T08:20:09.494Z", "username": "admin", "name": "Administrator", "email": "admin@jumpserver.org", "role": "Admin", "avatar": "", "wechat": "", "phone": null, "enable_otp": false, "secret_key_otp": "", "_private_key": "", "_public_key": "", "comment": "Administrator is the super user of system", "is_first_login": false, "date_expired": "2087-11-20T08:20:09.494Z", "created_by": "System", "user_permissions": [], "groups": ["2e0b2a25-b32f-44a0-b087-f0f17de66e26"]}}]
|
Loading…
Reference in new issue