From 806d38bbb2b0a33dc307dcc95159ab468becfa41 Mon Sep 17 00:00:00 2001 From: yumaojun03 <719118794@qq.com> Date: Sun, 11 Dec 2016 20:50:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E6=95=B0=E6=8D=AE=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/models/ansible.py | 18 ++++++++++++++++++ apps/ops/models/sudo.py | 5 ++++- apps/ops/models/utils.py | 11 +++++++++++ apps/ops/templates/sudo/list.html | 24 +++++++++++------------- 4 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 apps/ops/models/utils.py diff --git a/apps/ops/models/ansible.py b/apps/ops/models/ansible.py index c3043cd50..052463749 100644 --- a/apps/ops/models/ansible.py +++ b/apps/ops/models/ansible.py @@ -29,6 +29,24 @@ class Tasker(models.Model): def total_hosts(self): return self.hosts.split(',') + @classmethod + def generate_fake(cls, count=100): + from random import seed + import forgery_py + from django.db import IntegrityError + + seed() + for i in range(count): + group = cls(name=forgery_py.name.full_name(), + comment=forgery_py.lorem_ipsum.sentence(), + created_by='Fake') + try: + group.save() + logger.debug('Generate fake asset group: %s' % group.name) + except IntegrityError: + print('Error continue') + continue + class AnsiblePlay(models.Model): tasker = models.ForeignKey(Tasker, related_name='plays', blank=True, null=True) diff --git a/apps/ops/models/sudo.py b/apps/ops/models/sudo.py index af5368a26..48e6b6fc7 100644 --- a/apps/ops/models/sudo.py +++ b/apps/ops/models/sudo.py @@ -78,11 +78,14 @@ class Sudo(models.Model): :param privileges: [(user, host, runas, command, nopassword),] """ + name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'), + help_text=_('Name for this sudo')) + created_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by'), + help_text=_('The create time of this sudo')) assets = models.ManyToManyField(Asset, blank=True, related_name='sudos') asset_groups = models.ManyToManyField(AssetGroup, blank=True, related_name='sudos') extra_lines = models.ManyToManyField(Extra_conf, related_name='sudos', blank=True) privilege_items = models.ManyToManyField(Privilege, related_name='sudos', blank=True) - created_by = models.CharField(max_length=32, blank=True, verbose_name=_('Created by')) @property def all_assets(self): diff --git a/apps/ops/models/utils.py b/apps/ops/models/utils.py new file mode 100644 index 000000000..98dd8e65a --- /dev/null +++ b/apps/ops/models/utils.py @@ -0,0 +1,11 @@ +# ~*~ coding: utf-8 ~*~ +from __future__ import unicode_literals + +from ansible import * +from cron import * +from sudo import * + + +def generate_fake(): + for cls in (AssetGroup, IDC, AdminUser, SystemUser, Asset): + cls.generate_fake() \ No newline at end of file diff --git a/apps/ops/templates/sudo/list.html b/apps/ops/templates/sudo/list.html index f408d8c71..141fd8710 100644 --- a/apps/ops/templates/sudo/list.html +++ b/apps/ops/templates/sudo/list.html @@ -5,7 +5,7 @@ {% block table_container %}
{% trans "Create user" %}
{% trans "Import user" %}
- +
- - - - - + + + @@ -46,7 +44,7 @@
@@ -13,11 +13,9 @@ {% trans 'Name' %}{% trans 'Username' %}{% trans 'Role' %}{% trans 'User group' %}{% trans 'Active' %}{% trans 'Action' %}{% trans 'Privileges' %}{% trans 'Extra Lines' %}{% trans 'Created' %}