<s> from django . db import models <EOL> from django . core . exceptions import ValidationError <EOL> from systems . models import System <EOL> import mozdns <EOL> from core . keyvalue . models import KeyValue <EOL> from core . keyvalue . utils import AuxAttr <EOL> from core . validation import validate_mac <EOL> from mozdns . address_record . models import BaseAddressRecord <EOL> from mozdns . domain . models import Domain <EOL> from mozdns . ip . utils import ip_to_dns_form <EOL> import re <EOL> from gettext import gettext as _ <EOL> class StaticInterface ( BaseAddressRecord ) : <EOL> """<STR_LIT>""" <EOL> id = models . AutoField ( primary_key = True ) <EOL> mac = models . CharField ( max_length = <NUM_LIT> , validators = [ validate_mac ] , <EOL> help_text = "<STR_LIT>" ) <EOL> reverse_domain = models . ForeignKey ( Domain , null = True , blank = True , <EOL> related_name = "<STR_LIT>" ) <EOL> system = models . ForeignKey ( System , null = True , blank = True , <EOL> help_text = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> dhcp_enabled = models . BooleanField ( default = True , <EOL> help_text = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> dns_enabled = models . BooleanField ( default = True , <EOL> help_text = "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> attrs = None <EOL> search_fields = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> def update_attrs ( self ) : <EOL> self . attrs = AuxAttr ( StaticIntrKeyValue , self ) <EOL> def details ( self ) : <EOL> return ( <EOL> ( "<STR_LIT:Name>" , self . fqdn ) , <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ( "<STR_LIT>" , self . ip_str ) , <EOL> ) <EOL> class Meta : <EOL> db_table = "<STR_LIT>" <EOL> unique_together = ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:label>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> @ classmethod <EOL> def get_api_fields ( cls ) : <EOL> return super ( StaticInterface , cls ) . get_api_fields ( ) + [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> @ property <EOL> def rdtype ( self ) : <EOL> return '<STR_LIT>' <EOL> def get_edit_url ( self ) : <EOL> return "<STR_LIT>" . format ( self . pk ) <EOL> def get_delete_url ( self ) : <EOL> return "<STR_LIT>" . format ( self . pk ) <EOL> def get_absolute_url ( self ) : <EOL> return "<STR_LIT>" . format ( self . system . pk ) <EOL> def interface_name ( self ) : <EOL> self . update_attrs ( ) <EOL> try : <EOL> itype , primary , alias = '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' <EOL> itype = self . attrs . interface_type <EOL> primary = self . attrs . primary <EOL> alias = self . attrs . alias <EOL> except AttributeError : <EOL> pass <EOL> if itype == '<STR_LIT>' or primary == '<STR_LIT>' : <EOL> return "<STR_LIT:None>" <EOL> elif alias == '<STR_LIT>' : <EOL> return "<STR_LIT>" . format ( itype , primary ) <EOL> else : <EOL> return "<STR_LIT>" . format ( itype , primary , alias ) <EOL> def clean ( self , * args , ** kwargs ) : <EOL> self . mac = self . mac . lower ( ) <EOL> if not self . system : <EOL> raise ValidationError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> from mozdns . ptr . models import PTR <EOL> from mozdns . address_record . models import AddressRecord <EOL> if PTR . objects . filter ( ip_str = self . ip_str , name = self . fqdn ) . exists ( ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if AddressRecord . objects . filter ( ip_str = self . ip_str , fqdn = self . fqdn <EOL> ) . exists ( ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> if kwargs . pop ( "<STR_LIT>" , True ) : <EOL> self . check_glue_status ( ) <EOL> self . update_reverse_domain ( ) <EOL> self . check_no_ns_soa_condition ( self . reverse_domain ) <EOL> super ( StaticInterface , self ) . clean ( validate_glue = False , <EOL> ignore_interface = True ) <EOL> def check_glue_status ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . pk is None : <EOL> return <EOL> db_self = StaticInterface . objects . get ( pk = self . pk ) <EOL> if db_self . label == self . label and db_self . domain == self . domain : <EOL> return <EOL> Nameserver = mozdns . nameserver . models . Nameserver <EOL> if Nameserver . objects . filter ( intr_glue = self ) . exists ( ) : <EOL> raise ValidationError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> A_template = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> PTR_template = _ ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def bind_render_record ( self , pk = False , ** kwargs ) : <EOL> self . rdtype_clob = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if kwargs . pop ( '<STR_LIT>' , False ) : <EOL> self . template = self . PTR_template <EOL> self . dns_ip = ip_to_dns_form ( self . ip_str ) <EOL> else : <EOL> self . template = self . A_template <EOL> return super ( StaticInterface , self ) . bind_render_record ( pk = pk , ** kwargs ) <EOL> def record_type ( self ) : <EOL> return "<STR_LIT>" <EOL> def delete ( self , * args , ** kwargs ) : <EOL> if kwargs . pop ( "<STR_LIT>" , True ) : <EOL> if self . intrnameserver_set . exists ( ) : <EOL> raise ValidationError ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" . format ( self . record_type ( ) ) ) <EOL> check_cname = kwargs . pop ( "<STR_LIT>" , True ) <EOL> super ( StaticInterface , self ) . delete ( validate_glue = False , <EOL> check_cname = check_cname ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" . format ( str ( self ) ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" . format ( self . ip_str , <EOL> self . fqdn ) <EOL> is_eth = re . compile ( "<STR_LIT>" ) <EOL> is_mgmt = re . compile ( "<STR_LIT>" ) <EOL> class StaticIntrKeyValue ( KeyValue ) : <EOL> obj = models . ForeignKey ( <EOL> StaticInterface , related_name = '<STR_LIT>' , null = False <EOL> ) <EOL> class Meta : <EOL> db_table = "<STR_LIT>" <EOL> unique_together = ( "<STR_LIT:key>" , "<STR_LIT:value>" , "<STR_LIT>" ) <EOL> def _aa_primary ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . value . isdigit ( ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def _aa_alias ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . value . isdigit ( ) : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def _aa_hostname ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . value : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def _aa_domain_name_servers ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . value : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def _aa_domain_name ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . value : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def _aa_filename ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . value : <EOL> raise ValidationError ( "<STR_LIT>" ) <EOL> def _aa_interface_type ( self ) : <EOL> """<STR_LIT>""" <EOL> if not ( is_eth . match ( self . value ) or is_mgmt . match ( self . value ) ) : <EOL> raise ValidationError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) </s>
