Changeset 6317 for trunk


Ignore:
Timestamp:
Sep 29, 2008, 10:07:42 PM (16 years ago)
Author:
RIck van der Zwet
Message:

First attempt of embedding public accesspoints

Location:
trunk/exodus
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/exodus/models.py

    r6288 r6317  
    109109                return "Alias %s" % (self.iface)
    110110
     111#
     112# XXX: Needs rethinking, dhcp[start|stop] could be removed if whole publicAP is
     113# going to be activated as DHCP range, or only number of fixed clients needs to
     114# be defined, all other could be calculated on the fly if needed
    111115class PublicAP(models.Model):
    112     iface = models.ForeignKey(Interface)
     116    iface = models.ForeignKey(Interface,related_name='ap')
    113117    ip = models.IPAddressField(unique=True)
    114     netmask = models.IntegerField(default=30)
     118    netmask = models.IntegerField(default=28)
    115119    dhcpstart = models.IPAddressField()
    116120    dhcpstop = models.IPAddressField()
  • trunk/exodus/templates/addomni.html

    r6206 r6317  
    22
    33{% block content %}
    4 <h1>Add an Omni</h1>
     4<h1>Add an public access point</h1>
    55
    66<form method="post" action=".">
  • trunk/exodus/templates/exodus-template.html

    r6287 r6317  
    1717          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addLocation %}">Add Location</a><br>
    1818          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addNode %}">Add Node</a><br>
    19           &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addInterface %}">Add Interface</a><br>
    20           &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addPublicAP %}">Add PublicAP</a><br>
    21           &nbsp;<p>
    2219        </td>
    2320        <td valign="top" class="right">
  • trunk/exodus/templates/node-detail.html

    r6315 r6317  
    1717
    1818<h2>Interfaces</h2>
    19 <a href="{% url exodus.views.addInterface %}?node={{ object.name }}">Add new interface</a>
     19<a href="{% url exodus.views.addInterface %}?node={{ object.name }}">Add new interface</a><p />
    2020
    2121{% for nic in object.interface_set.all %}
    22         <p>
    2322        <div style="border:1px solid #000000;">
    2423        <h3>iface: {{ nic.iface }} </h3>
     24        <a href="{% url exodus.views.addPublicAP %}?iface={{ nic }}">Add new public access point</a><p />
    2525        type: {{ nic.type }} <br>
    2626        description: {{ nic.shortdesc }} <br>
     
    3535        {% endifnotequal %}
    3636        <a href="{% url exodus.views.editInterface nic %}">EDIT</a>
     37        <a href="{% url exodus.views.delInterface nic %}">DELETE</a>
    3738        </div>
    3839
     
    5152        {% endfor %}
    5253       
    53        
    54         {% for omni in nic.omni.all %}
    55                 <ul>
    56                 <li>DHCP {{ omni.dhcpstart }}-{{ omni.dhcpstop }}</li>
    57                 {% for dhcp in omni.dhcpstatic.all %}
     54        <ul>
     55        {% for accessPoint in nic.ap.all %}
     56                <div style="border:1px solid #000000;">
     57                <p />
     58                <li>Public Access Point: {{ accessPoint.ip}}/{{accessPoint.netmask }}
     59                {% for dhcp in accessPoint.dhcpstatic.all %}
    5860                        <ul>
    5961                            <li>Hostname: {{ dhcp.hostname }} </li>
     
    6163                        </ul>
    6264                {% endfor %}
    63                 </ul>
     65        </li>
     66                <p />
     67                </div>
    6468        {% endfor %}
     69        </ul>
    6570{% endfor %}
    6671
  • trunk/exodus/views.py

    r6315 r6317  
    1111
    1212from exodus.models import *
    13 from exodus.wllogic import freeMasterIP, newSSIDName, addInterlinkIP, freeInterlinkIP
     13from exodus.wllogic import freeMasterIP, newSSIDName, addInterlinkIP, freeInterlinkIP, freePublicAPIP
    1414
    1515class AddLocationForm(forms.ModelForm):
     
    203203        class Meta:
    204204                model = PublicAP
    205                 exclude = ('shortdesc', 'desc')
     205                exclude = ('shortdesc', 'desc', 'ip', 'dhcpstart', 'dhcpstop')
    206206
    207207def addPublicAP(request):
     
    210210                if form.is_valid():
    211211                        instance = form.save(commit=False)
     212                        # Find IP range inside interface range with disired size/subnet
     213                        instance.ip = freePublicAPIP(instance.iface, instance.netmask)
     214                        instance.dhcpstart = 1
     215                        instance.dhcpstop = 2
     216                        # If wireless generate ssid name
    212217                        instance.ssid = newSSIDName(instance.iface.node, instance.iface, 'omni')
    213218                        instance.save()
    214                         return HttpResponseRedirect(reverse('nodelist'))
    215         else:
    216                 form = addPublicAPForm()
     219                        nodeName = instance.iface.node
     220                        return HttpResponseRedirect(reverse('node-detail', args=[nodeName]))
     221        else:
     222                #XXX: Link, master interfaces only
     223                if 'iface' in request.GET:
     224                        nodeName, interfaceName = request.GET['iface'].split(':')
     225                        newPublicAP = PublicAP()
     226                        newPublicAP.iface = Interface.objects.get(iface=interfaceName, node=nodename2id(nodeName))
     227                        form = addPublicAPForm(instance=newPublicAP)
     228                else:
     229                        form = addPublicAPForm()
    217230        return render_to_response('addomni.html', {'form': form })
    218231
  • trunk/exodus/wllogic.py

    r6313 r6317  
    11# (c) Roland van Laar
    22
    3 from exodus.models import Node, Interface
     3from exodus.models import Node, Interface, PublicAP
    44
    55def newSSIDName(node, nic, desc):
     
    6666        return showaddr(i)
    6767
     68#
     69# XXX: Needs merging with freeInterlinkIP as interface could have both AP, interlink difined on one link
     70def freePublicAPIP(masterLink, netmask):
     71        taken = {}
     72
     73        for interface in Interface.objects.filter(link=masterLink):
     74                #Grr, needs all interfaces which are master requires a bit of a hack
     75                addr = network(interface.ip, interface.netmask)
     76                addrMax = broadcast(interface.ip, interface.netmask)
     77                while addr < addrMax:
     78                        taken[addr] = 1
     79                        addr = addr + 1
     80
     81        for accessPoint in PublicAP.objects.filter(iface=masterLink):
     82                #Grr, needs all interfaces which are master requires a bit of a hack
     83                addr = network(accessPoint.ip, accessPoint.netmask)
     84                addrMax = broadcast(accessPoint.ip, accessPoint.netmask)
     85                while addr < addrMax:
     86                        taken[addr] = 1
     87                        addr = addr + 1
     88
     89        #Should be dynamic based on the number of hosts in here
     90        size = netmask
     91        numaddrs = 1 << (32 - size)
     92        i = network(masterLink.ip,masterLink.netmask)
     93        while taken.has_key(i):
     94                i = i + numaddrs
     95       
     96        return showaddr(i)
     97
    6898def freeInterlinkIP(masterLink):
    6999        taken = {}
Note: See TracChangeset for help on using the changeset viewer.