Пример #1
0
class asnPool(models.Model):
    name = models.CharField(max_length=50)
    first_asn = ASNField()
    last_asn = ASNField()
    tag = models.CharField(max_length=20, default=None, null=True, blank=True)
    pool_id = models.CharField(max_length=50, unique=True)

    def __str__(self):
        return self.name
class BgpPeering(ChangeLoggedModel):
    site = models.ForeignKey(to="dcim.Site",
                             on_delete=models.SET_NULL,
                             blank=True,
                             null=True)
    device = models.ForeignKey(to="dcim.Device", on_delete=models.PROTECT)
    local_ip = models.ForeignKey(to="ipam.IPAddress", on_delete=models.PROTECT)
    local_as = ASNField(help_text="32-bit ASN used locally")
    remote_ip = IPAddressField(help_text="IPv4 or IPv6 address (with mask)")
    remote_as = ASNField(help_text="32-bit ASN used by peer")
    peer_name = models.CharField(max_length=64, blank=True)
    description = models.CharField(max_length=200, blank=True)
Пример #3
0
class Provider(ChangeLoggedModel, CustomFieldModel):
    """
    Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
    stores information pertinent to the user's relationship with the Provider.
    """
    name = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(max_length=100, unique=True)
    asn = ASNField(blank=True,
                   null=True,
                   verbose_name='ASN',
                   help_text='32-bit autonomous system number')
    account = models.CharField(max_length=30,
                               blank=True,
                               verbose_name='Account number')
    portal_url = models.URLField(blank=True, verbose_name='Portal URL')
    noc_contact = models.TextField(blank=True, verbose_name='NOC contact')
    admin_contact = models.TextField(blank=True, verbose_name='Admin contact')
    comments = models.TextField(blank=True)
    tags = TaggableManager(through=TaggedItem)

    objects = RestrictedQuerySet.as_manager()

    csv_headers = [
        'name',
        'slug',
        'asn',
        'account',
        'portal_url',
        'noc_contact',
        'admin_contact',
        'comments',
    ]
    clone_fields = [
        'asn',
        'account',
        'portal_url',
        'noc_contact',
        'admin_contact',
    ]

    class Meta:
        ordering = ['name']

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('circuits:provider', args=[self.slug])

    def to_csv(self):
        return (
            self.name,
            self.slug,
            self.asn,
            self.account,
            self.portal_url,
            self.noc_contact,
            self.admin_contact,
            self.comments,
        )
Пример #4
0
class Provider(CreatedUpdatedModel):
    """
    Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
    stores information pertinent to the user's relationship with the Provider.
    """
    name = models.CharField(max_length=50, unique=True)
    slug = models.SlugField(unique=True)
    asn = ASNField(blank=True, null=True, verbose_name='ASN')
    account = models.CharField(max_length=30,
                               blank=True,
                               verbose_name='Account number')
    portal_url = models.URLField(blank=True, verbose_name='Portal')
    noc_contact = models.TextField(blank=True, verbose_name='NOC contact')
    admin_contact = models.TextField(blank=True, verbose_name='Admin contact')
    comments = models.TextField(blank=True)

    class Meta:
        ordering = ['name']

    def __unicode__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('circuits:provider', args=[self.slug])

    def to_csv(self):
        return ','.join([
            self.name,
            self.slug,
            str(self.asn) if self.asn else '',
            self.account,
            self.portal_url,
        ])
Пример #5
0
class ASN(PrimaryModel):
    """
    An autonomous system (AS) number is typically used to represent an independent routing domain. A site can have
    one or more ASNs assigned to it.
    """
    asn = ASNField(unique=True,
                   verbose_name='ASN',
                   help_text='32-bit autonomous system number')
    description = models.CharField(max_length=200, blank=True)
    rir = models.ForeignKey(to='ipam.RIR',
                            on_delete=models.PROTECT,
                            related_name='asns',
                            verbose_name='RIR')
    tenant = models.ForeignKey(to='tenancy.Tenant',
                               on_delete=models.PROTECT,
                               related_name='asns',
                               blank=True,
                               null=True)

    class Meta:
        ordering = ['asn']
        verbose_name = 'ASN'
        verbose_name_plural = 'ASNs'

    def __str__(self):
        return f'AS{self.asn}'

    def get_absolute_url(self):
        return reverse('ipam:asn', args=[self.pk])
Пример #6
0
class Provider(ChangeLoggedModel, CustomFieldModel):
    """
    Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
    stores information pertinent to the user's relationship with the Provider.
    """
    name = models.CharField(max_length=50, unique=True)
    slug = models.SlugField(unique=True)
    asn = ASNField(blank=True, null=True, verbose_name='ASN')
    account = models.CharField(max_length=30,
                               blank=True,
                               verbose_name='Account number')
    portal_url = models.URLField(blank=True, verbose_name='Portal')
    noc_contact = models.TextField(blank=True, verbose_name='NOC contact')
    admin_contact = models.TextField(blank=True, verbose_name='Admin contact')
    comments = models.TextField(blank=True)
    custom_field_values = GenericRelation(to='extras.CustomFieldValue',
                                          content_type_field='obj_type',
                                          object_id_field='obj_id')

    tags = TaggableManager(through=TaggedItem)

    csv_headers = [
        'name',
        'slug',
        'asn',
        'account',
        'portal_url',
        'noc_contact',
        'admin_contact',
        'comments',
    ]
    clone_fields = [
        'asn',
        'account',
        'portal_url',
        'noc_contact',
        'admin_contact',
    ]

    class Meta:
        ordering = ['name']

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('circuits:provider', args=[self.slug])

    def to_csv(self):
        return (
            self.name,
            self.slug,
            self.asn,
            self.account,
            self.portal_url,
            self.noc_contact,
            self.admin_contact,
            self.comments,
        )
Пример #7
0
class ASN(PrimaryModel):
    """
    An autonomous system (AS) number is typically used to represent an independent routing domain. A site can have
    one or more ASNs assigned to it.
    """
    asn = ASNField(unique=True,
                   verbose_name='ASN',
                   help_text='32-bit autonomous system number')
    description = models.CharField(max_length=200, blank=True)
    rir = models.ForeignKey(to='ipam.RIR',
                            on_delete=models.PROTECT,
                            related_name='asns',
                            verbose_name='RIR')
    tenant = models.ForeignKey(to='tenancy.Tenant',
                               on_delete=models.PROTECT,
                               related_name='asns',
                               blank=True,
                               null=True)

    class Meta:
        ordering = ['asn']
        verbose_name = 'ASN'
        verbose_name_plural = 'ASNs'

    def __str__(self):
        return f'AS{self.asn_with_asdot}'

    def get_absolute_url(self):
        return reverse('ipam:asn', args=[self.pk])

    @property
    def asn_asdot(self):
        """
        Return ASDOT notation for AS numbers greater than 16 bits.
        """
        if self.asn > 65535:
            return f'{self.asn // 65536}.{self.asn % 65536}'
        return self.asn

    @property
    def asn_with_asdot(self):
        """
        Return both plain and ASDOT notation, where applicable.
        """
        if self.asn > 65535:
            return f'{self.asn} ({self.asn // 65536}.{self.asn % 65536})'
        else:
            return self.asn
Пример #8
0
class Provider(PrimaryModel):
    """
    Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
    stores information pertinent to the user's relationship with the Provider.
    """
    name = models.CharField(max_length=100, unique=True)
    slug = models.SlugField(max_length=100, unique=True)
    asn = ASNField(blank=True,
                   null=True,
                   verbose_name='ASN',
                   help_text='32-bit autonomous system number')
    account = models.CharField(max_length=30,
                               blank=True,
                               verbose_name='Account number')
    portal_url = models.URLField(blank=True, verbose_name='Portal URL')
    noc_contact = models.TextField(blank=True, verbose_name='NOC contact')
    admin_contact = models.TextField(blank=True, verbose_name='Admin contact')
    comments = models.TextField(blank=True)

    # Generic relations
    contacts = GenericRelation(to='tenancy.ContactAssignment')

    clone_fields = [
        'asn',
        'account',
        'portal_url',
        'noc_contact',
        'admin_contact',
    ]

    class Meta:
        ordering = ['name']

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('circuits:provider', args=[self.pk])
Пример #9
0
class Site(PrimaryModel):
    """
    A Site represents a geographic location within a network; typically a building or campus. The optional facility
    field can be used to include an external designation, such as a data center name (e.g. Equinix SV6).
    """
    name = models.CharField(
        max_length=100,
        unique=True
    )
    _name = NaturalOrderingField(
        target_field='name',
        max_length=100,
        blank=True
    )
    slug = models.SlugField(
        max_length=100,
        unique=True
    )
    status = models.CharField(
        max_length=50,
        choices=SiteStatusChoices,
        default=SiteStatusChoices.STATUS_ACTIVE
    )
    region = models.ForeignKey(
        to='dcim.Region',
        on_delete=models.SET_NULL,
        related_name='sites',
        blank=True,
        null=True
    )
    group = models.ForeignKey(
        to='dcim.SiteGroup',
        on_delete=models.SET_NULL,
        related_name='sites',
        blank=True,
        null=True
    )
    tenant = models.ForeignKey(
        to='tenancy.Tenant',
        on_delete=models.PROTECT,
        related_name='sites',
        blank=True,
        null=True
    )
    facility = models.CharField(
        max_length=50,
        blank=True,
        help_text='Local facility ID or description'
    )
    asn = ASNField(
        blank=True,
        null=True,
        verbose_name='ASN',
        help_text='32-bit autonomous system number'
    )
    time_zone = TimeZoneField(
        blank=True
    )
    description = models.CharField(
        max_length=200,
        blank=True
    )
    physical_address = models.CharField(
        max_length=200,
        blank=True
    )
    shipping_address = models.CharField(
        max_length=200,
        blank=True
    )
    latitude = models.DecimalField(
        max_digits=8,
        decimal_places=6,
        blank=True,
        null=True,
        help_text='GPS coordinate (latitude)'
    )
    longitude = models.DecimalField(
        max_digits=9,
        decimal_places=6,
        blank=True,
        null=True,
        help_text='GPS coordinate (longitude)'
    )
    contact_name = models.CharField(
        max_length=50,
        blank=True
    )
    contact_phone = models.CharField(
        max_length=20,
        blank=True
    )
    contact_email = models.EmailField(
        blank=True,
        verbose_name='Contact E-mail'
    )
    comments = models.TextField(
        blank=True
    )
    vlan_groups = GenericRelation(
        to='ipam.VLANGroup',
        content_type_field='scope_type',
        object_id_field='scope_id',
        related_query_name='site'
    )
    images = GenericRelation(
        to='extras.ImageAttachment'
    )

    objects = RestrictedQuerySet.as_manager()

    clone_fields = [
        'status', 'region', 'group', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address',
        'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email',
    ]

    class Meta:
        ordering = ('_name',)

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('dcim:site', args=[self.pk])

    def get_status_class(self):
        return SiteStatusChoices.CSS_CLASSES.get(self.status)
Пример #10
0
class Site(ChangeLoggedModel, CustomFieldModel):
    """
    A Site represents a geographic location within a network; typically a building or campus. The optional facility
    field can be used to include an external designation, such as a data center name (e.g. Equinix SV6).
    """
    name = models.CharField(
        max_length=50,
        unique=True,
        verbose_name='наименование'
    )
    _name = NaturalOrderingField(
        target_field='name',
        max_length=100,
        blank=True
    )
    slug = models.SlugField(
        unique=True
    )
    status = models.CharField(
        max_length=50,
        choices=SiteStatusChoices,
        default=SiteStatusChoices.STATUS_ACTIVE,
        verbose_name='статус'
    )
    region = models.ForeignKey(
        to='dcim.Region',
        on_delete=models.SET_NULL,
        related_name='sites',
        blank=True,
        null=True,
        verbose_name='регион'
    )
    tenant = models.ForeignKey(
        to='tenancy.Tenant',
        on_delete=models.PROTECT,
        related_name='sites',
        blank=True,
        null=True,
        verbose_name='учреждение'
    )
    facility = models.CharField(
        max_length=50,
        blank=True,
        help_text='код региона'
    )
    asn = ASNField(
        blank=True,
        null=True,
        verbose_name='ASN',
        help_text='32-bit автономный номер'
    )
    time_zone = TimeZoneField(
        blank=True,
        verbose_name='часовой пояс'
    )
    description = models.CharField(
        max_length=200,
        blank=True,
        verbose_name='описание'
    )
    physical_address = models.CharField(
        max_length=200,
        blank=True,
        verbose_name='фактический адрес'
    )
    shipping_address = models.CharField(
        max_length=200,
        blank=True,
        verbose_name='адрес доставки'
    )
    latitude = models.DecimalField(
        max_digits=8,
        decimal_places=6,
        blank=True,
        null=True,
        verbose_name='широта',
        help_text='GPS координаты (широта)'
    )
    longitude = models.DecimalField(
        max_digits=9,
        decimal_places=6,
        blank=True,
        null=True,
        verbose_name='долгота',
        help_text='GPS координаты (долгота)'
    )
    contact_name = models.CharField(
        max_length=50,
        blank=True,
        verbose_name='ФИО ответственного'
    )
    contact_phone = models.CharField(
        max_length=20,
        blank=True,
        verbose_name='контактный телефон'
    )
    contact_email = models.EmailField(
        blank=True,
        verbose_name='электронная почта'
    )
    comments = models.TextField(
        blank=True,
        verbose_name='коментарии'
    )
    custom_field_values = GenericRelation(
        to='extras.CustomFieldValue',
        content_type_field='obj_type',
        object_id_field='obj_id'
    )
    images = GenericRelation(
        to='extras.ImageAttachment',
        verbose_name='изображения'
    )
    tags = TaggableManager(through=TaggedItem)

    objects = RestrictedQuerySet.as_manager()

    csv_headers = [
        'name', 'slug', 'status', 'region', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address',
        'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email', 'comments',
    ]
    clone_fields = [
        'status', 'region', 'tenant', 'facility', 'asn', 'time_zone', 'description', 'physical_address',
        'shipping_address', 'latitude', 'longitude', 'contact_name', 'contact_phone', 'contact_email',
    ]

    STATUS_CLASS_MAP = {
        SiteStatusChoices.STATUS_PLANNED: 'info',
        SiteStatusChoices.STATUS_STAGING: 'primary',
        SiteStatusChoices.STATUS_ACTIVE: 'success',
        SiteStatusChoices.STATUS_DECOMMISSIONING: 'warning',
        SiteStatusChoices.STATUS_RETIRED: 'danger',
    }

    class Meta:
        ordering = ('_name',)
        verbose_name = 'адрес'
        verbose_name_plural = 'адреса'

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('dcim:site', args=[self.slug])

    def to_csv(self):
        return (
            self.name,
            self.slug,
            self.get_status_display(),
            self.region.name if self.region else None,
            self.tenant.name if self.tenant else None,
            self.facility,
            self.asn,
            self.time_zone,
            self.description,
            self.physical_address,
            self.shipping_address,
            self.latitude,
            self.longitude,
            self.contact_name,
            self.contact_phone,
            self.contact_email,
            self.comments,
        )

    def get_status_class(self):
        return self.STATUS_CLASS_MAP.get(self.status)
Пример #11
0
class Site(ChangeLoggedModel, CustomFieldModel):
    """
    A Site represents a geographic location within a network; typically a building or campus. The optional facility
    field can be used to include an external designation, such as a data center name (e.g. Equinix SV6).
    """
    name = models.CharField(max_length=50, unique=True)
    _name = NaturalOrderingField(target_field='name',
                                 max_length=100,
                                 blank=True)
    slug = models.SlugField(unique=True)
    status = models.CharField(max_length=50,
                              choices=SiteStatusChoices,
                              default=SiteStatusChoices.STATUS_ACTIVE)
    region = models.ForeignKey(to='dcim.Region',
                               on_delete=models.SET_NULL,
                               related_name='sites',
                               blank=True,
                               null=True)
    tenant = models.ForeignKey(to='tenancy.Tenant',
                               on_delete=models.PROTECT,
                               related_name='sites',
                               blank=True,
                               null=True)
    facility = models.CharField(max_length=50,
                                blank=True,
                                help_text='Local facility ID or description')
    asn = ASNField(blank=True,
                   null=True,
                   verbose_name='ASN',
                   help_text='32-bit autonomous system number')
    time_zone = TimeZoneField(blank=True)
    description = models.CharField(max_length=200, blank=True)
    physical_address = models.CharField(max_length=200, blank=True)
    shipping_address = models.CharField(max_length=200, blank=True)
    latitude = models.DecimalField(max_digits=8,
                                   decimal_places=6,
                                   blank=True,
                                   null=True,
                                   help_text='GPS coordinate (latitude)')
    longitude = models.DecimalField(max_digits=9,
                                    decimal_places=6,
                                    blank=True,
                                    null=True,
                                    help_text='GPS coordinate (longitude)')
    contact_name = models.CharField(max_length=50, blank=True)
    contact_phone = models.CharField(max_length=20, blank=True)
    contact_email = models.EmailField(blank=True,
                                      verbose_name='Contact E-mail')
    comments = models.TextField(blank=True)
    custom_field_values = GenericRelation(to='extras.CustomFieldValue',
                                          content_type_field='obj_type',
                                          object_id_field='obj_id')
    images = GenericRelation(to='extras.ImageAttachment')
    tags = TaggableManager(through=TaggedItem)

    objects = RestrictedQuerySet.as_manager()

    csv_headers = [
        'name',
        'slug',
        'status',
        'region',
        'tenant',
        'facility',
        'asn',
        'time_zone',
        'description',
        'physical_address',
        'shipping_address',
        'latitude',
        'longitude',
        'contact_name',
        'contact_phone',
        'contact_email',
        'comments',
    ]
    clone_fields = [
        'status',
        'region',
        'tenant',
        'facility',
        'asn',
        'time_zone',
        'description',
        'physical_address',
        'shipping_address',
        'latitude',
        'longitude',
        'contact_name',
        'contact_phone',
        'contact_email',
    ]

    STATUS_CLASS_MAP = {
        SiteStatusChoices.STATUS_PLANNED: 'info',
        SiteStatusChoices.STATUS_STAGING: 'primary',
        SiteStatusChoices.STATUS_ACTIVE: 'success',
        SiteStatusChoices.STATUS_DECOMMISSIONING: 'warning',
        SiteStatusChoices.STATUS_RETIRED: 'danger',
    }

    class Meta:
        ordering = ('_name', )

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('dcim:site', args=[self.slug])

    def to_csv(self):
        return (
            self.name,
            self.slug,
            self.get_status_display(),
            self.region.name if self.region else None,
            self.tenant.name if self.tenant else None,
            self.facility,
            self.asn,
            self.time_zone,
            self.description,
            self.physical_address,
            self.shipping_address,
            self.latitude,
            self.longitude,
            self.contact_name,
            self.contact_phone,
            self.contact_email,
            self.comments,
        )

    def get_status_class(self):
        return self.STATUS_CLASS_MAP.get(self.status)