2018-03-23 11:46:46 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
|
|
|
|
import uuid
|
2018-03-25 13:47:29 +00:00
|
|
|
import random
|
|
|
|
|
2018-03-23 11:46:46 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
2018-07-12 16:00:35 +00:00
|
|
|
from orgs.mixins import OrgModelMixin
|
2018-03-23 11:46:46 +00:00
|
|
|
from .base import AssetUser
|
|
|
|
|
|
|
|
__all__ = ['Domain', 'Gateway']
|
|
|
|
|
|
|
|
|
2018-07-12 16:00:35 +00:00
|
|
|
class Domain(OrgModelMixin):
|
2018-03-23 11:46:46 +00:00
|
|
|
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
|
|
|
|
name = models.CharField(max_length=128, unique=True, verbose_name=_('Name'))
|
|
|
|
comment = models.TextField(blank=True, verbose_name=_('Comment'))
|
|
|
|
date_created = models.DateTimeField(auto_now_add=True, null=True,
|
|
|
|
verbose_name=_('Date created'))
|
|
|
|
|
2018-09-03 03:24:25 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("Domain")
|
|
|
|
|
2018-03-23 11:46:46 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2018-03-25 13:47:29 +00:00
|
|
|
def has_gateway(self):
|
|
|
|
return self.gateway_set.filter(is_active=True).exists()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def gateways(self):
|
|
|
|
return self.gateway_set.filter(is_active=True)
|
|
|
|
|
|
|
|
def random_gateway(self):
|
|
|
|
return random.choice(self.gateways)
|
|
|
|
|
2018-03-23 11:46:46 +00:00
|
|
|
|
2018-07-20 02:54:16 +00:00
|
|
|
class Gateway(AssetUser):
|
2018-03-23 11:46:46 +00:00
|
|
|
SSH_PROTOCOL = 'ssh'
|
|
|
|
RDP_PROTOCOL = 'rdp'
|
|
|
|
PROTOCOL_CHOICES = (
|
|
|
|
(SSH_PROTOCOL, 'ssh'),
|
|
|
|
(RDP_PROTOCOL, 'rdp'),
|
|
|
|
)
|
|
|
|
ip = models.GenericIPAddressField(max_length=32, verbose_name=_('IP'), db_index=True)
|
|
|
|
port = models.IntegerField(default=22, verbose_name=_('Port'))
|
|
|
|
protocol = models.CharField(choices=PROTOCOL_CHOICES, max_length=16, default=SSH_PROTOCOL, verbose_name=_("Protocol"))
|
2018-07-25 03:21:12 +00:00
|
|
|
domain = models.ForeignKey(Domain, on_delete=models.CASCADE, verbose_name=_("Domain"))
|
2018-03-23 11:46:46 +00:00
|
|
|
comment = models.CharField(max_length=128, blank=True, null=True, verbose_name=_("Comment"))
|
|
|
|
is_active = models.BooleanField(default=True, verbose_name=_("Is active"))
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
2018-03-25 13:47:29 +00:00
|
|
|
|
2018-07-17 09:09:36 +00:00
|
|
|
class Meta:
|
2018-07-20 02:54:16 +00:00
|
|
|
unique_together = [('name', 'org_id')]
|
2018-09-03 03:24:25 +00:00
|
|
|
verbose_name = _("Gateway")
|