jumpserver/apps/assets/models/idc.py

70 lines
2.4 KiB
Python
Raw Normal View History

2016-12-20 16:43:52 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2017-03-06 13:05:00 +00:00
#
2016-12-20 16:43:52 +00:00
from __future__ import unicode_literals
import logging
2017-03-06 13:05:00 +00:00
from django.db import models
2016-12-20 16:43:52 +00:00
from django.utils.translation import ugettext_lazy as _
__all__ = ['IDC']
logger = logging.getLogger(__name__)
class IDC(models.Model):
name = models.CharField(max_length=32, verbose_name=_('Name'))
2017-03-06 13:05:00 +00:00
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"))
2016-12-20 16:43:52 +00:00
intranet = models.TextField(blank=True, verbose_name=_('Intranet'))
extranet = models.TextField(blank=True, verbose_name=_('Extranet'))
2017-03-06 13:05:00 +00:00
date_created = models.DateTimeField(
2017-04-07 08:59:09 +00:00
auto_now_add=True, null=True, verbose_name=_('Date created'))
2017-03-06 13:05:00 +00:00
operator = models.CharField(
max_length=32, blank=True, verbose_name=_('Operator'))
created_by = models.CharField(
max_length=32, blank=True, verbose_name=_('Created by'))
2016-12-20 16:43:52 +00:00
comment = models.TextField(blank=True, verbose_name=_('Comment'))
def __unicode__(self):
return self.name
2017-04-08 16:45:28 +00:00
__str__ = __unicode__
2016-12-20 16:43:52 +00:00
@classmethod
def initial(cls):
return cls.objects.get_or_create(name=_('Default'), created_by=_('System'), comment=_('Default IDC'))[0]
class Meta:
ordering = ['name']
2016-12-20 16:43:52 +00:00
@classmethod
2017-03-22 15:36:43 +00:00
def generate_fake(cls, count=5):
2016-12-20 16:43:52 +00:00
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