Changeset 6437


Ignore:
Timestamp:
Dec 10, 2008, 11:05:12 PM (16 years ago)
Author:
roland
Message:

First working code for add interlink.

Location:
trunk/exodus
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/admin.py

    r6435 r6437  
    22from django.contrib import admin
    33from django.contrib import databrowse
    4 from django import forms
    5 from exodus.models import *
     4from exodus.models import Location, Node, Network, Interface, Antenna, \
     5        DnsServer, DhcpStatic       
    66from exodus.forms import NodeForm, InterfaceForm
    77from exodus.contrib import ReadOnlyAdminFields
     
    1010plain_admin = AdminSite()
    1111
    12 #class PublicAPInline(admin.TabularInline):
    13 #    model = PublicAP
    14 #    extra = 1
    15 
    16 class InterfaceInline(admin.TabularInline):
    17     model = Interface
    18     form = InterfaceForm
    19     extra = 2
    20     fieldsets = (
    21         (None, {
    22             'classes': ('collapse',),
    23             'fields': ('type', 'iface', 'polar', 'antenna', 'link')
    24         }),
    25     )
    26     #inlines = [ PublicAPInline, ]
    27 
    2812class NodeAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
    2913    readonly = ('masterip', )
    3014    form = NodeForm
    3115    list_display = ('name', 'location','network')
    32     search_fields = ['name']
     16    search_fields = ('name',)
    3317    list_filter = ('network',)
    3418    fieldsets = (
     
    3822    )
    3923
    40     inlines = [InterfaceInline, ]
    41 
    42 class NodeInline(admin.TabularInline):
    43     model = Node
    44     form = NodeForm
    45     extra = 2
    46     fields = ('name', 'status', 'location', 'network')
    47 
    48 class LocationAdmin(admin.ModelAdmin):
    49     search_fields = ['description']
    50     inlines = [ NodeInline, ]
     24class InterfaceAdmin(ReadOnlyAdminFields, admin.ModelAdmin):
     25    #readonly = ('ip', 'netmask', 'mode', 'ssid', 'shortdesc', 'desc')
     26    form = InterfaceForm
     27    list_display = ('node', 'iface', 'type', 'ip', 'channel', 'polar',
     28        'shortdesc', 'link')
     29    search_fields = ('node__name','iface')
     30    list_filter = ('type', 'accesspoint', 'polar', 'node', 'antenna')
     31    ordering =('node',)
    5132
    5233advanced_admin.register(Antenna)
    53 advanced_admin.register(Location, LocationAdmin)
     34advanced_admin.register(Location)
    5435advanced_admin.register(DnsServer)
    5536advanced_admin.register(Network)
    5637advanced_admin.register(Node, NodeAdmin)
    57 advanced_admin.register(Interface)
     38advanced_admin.register(Interface, InterfaceAdmin)
    5839#advanced_admin.register(PublicAP)
    5940advanced_admin.register(DhcpStatic)
  • trunk/exodus/forms.py

    r6434 r6437  
    11from django import forms
    22from exodus.models import Node, Interface
    3 from exodus.wllogic import free_master_ip, free_interlink_ip, add_interlink_ip
    4 from exodus.contrib import ReadOnlyWidget
     3from exodus.wllogic import free_master_ip, link_has_compat_type
    54
    65class NodeForm(forms.ModelForm):
    7     #masterip = forms.IPAddressField(widget=forms.HiddenInput)
    86    class Meta:
    97       model = Node
     
    2927    class Meta:
    3028        model = Interface
     29
     30    def clean_link(self):
     31        import pdb; pdb.set_trace() ;
     32        link = self.cleaned_data.get('link')
     33   
     34        if link:
     35            try:
     36                # if link is to self we don't need to check anything else
     37                if self.instance.pk == link.pk:
     38                    return link
     39                # Link can't be to same node.
     40                if self.instance.node_id == link.node_id:
     41                    raise forms.ValidationError(
     42                        "A link can't be to another interface on the same node")
     43            except Interface.DoesNotExist:
     44                pass
     45            if self.cleaned_data.get('accesspoint') and \
     46                    self.instance.pk != link.pk:
     47                raise forms.ValidationError( "A link can't be made to another interface when this interface has an accesspoint.")
     48
     49            # if link is referenced to itself, link is master and linkable
     50            if link.link.pk == link.pk:
     51                return link
     52
     53            # if we get at this elif, it means that link is in managed mode
     54            # but masterlink and managed can be switched
     55            # And check if that master has only 2, including himself, links
     56            # and is not an accesspoint himself.
     57            elif len(link.link.interface_set.all()) == 2 and not \
     58                    link.link.accesspoint:
     59                import pdb; pdb.set_trace()
     60                # convert master to slave
     61                #XXX: update mode
     62                old_slave = link
     63                old_master = old_slave.link
     64                old_master.link = old_slave
     65                old_slave.link = old_slave
     66                old_slave.save()
     67                old_master.save()
     68                #XXX: do ip address switch stuff
     69                return link
     70
     71            # check if the two links are compatible
     72            type = self.cleaned_data.get('type')
     73            if not link_has_compat_type(link.type, type):
     74                raise forms.ValidationError(
     75                    'Link type %s is not compatible with %s'
     76                    %(link.type, type))
     77               
     78 
     79        return link
     80
  • trunk/exodus/models.py

    r6432 r6437  
    116116    shortdesc = models.CharField(blank=True, max_length=10)
    117117    desc = models.CharField(blank=True, max_length=100)
     118    accesspoint = models.BooleanField()
    118119    link = models.ForeignKey('self', blank=True, null=True)
    119     accesspoint = models.BooleanField()
    120120   
    121121    class Meta:
  • trunk/exodus/wllogic.py

    r6432 r6437  
    154154                return True
    155155
    156 def link_has_compat_type(link1, link2):
    157         # if this is a link to self, the link is always valid
    158         if link1 == link2:
    159                 return True
     156def link_has_compat_type(type1, type2):
    160157        # link types must the same
    161         if link1.type == link2.type:
     158        if type1 == type2:
    162159                return True
    163160        # or link types must be compatible
    164161        compat = ('11b', '11g')
    165         if link1.type in compat and link2.type in compat:
     162        if type1 in compat and type2 in compat:
    166163                return True
    167164
Note: See TracChangeset for help on using the changeset viewer.