Changeset 6325


Ignore:
Timestamp:
Oct 2, 2008, 4:34:21 PM (16 years ago)
Author:
RIck van der Zwet
Message:

Voila, the initial framework is completed, next will be the tweaking and implementing of all logic

Location:
trunk/exodus
Files:
1 added
7 deleted
3 edited
8 moved

Legend:

Unmodified
Added
Removed
  • trunk/exodus/templates/deleteNode.html

    • Property svn:mergeinfo set to
    r6323 r6325  
    1 {% extends "exodus-template.html" %}
    2 
    3 {% block content %}
    4 
    5 <h1>Delete node {{ object.name }}</h1>
    6 
    71Interfaces to be deleted:
    82<ol>
     
    2418{% endfor %}
    2519</ol>
    26 
    27 <form method="post" action=".">
    28 <h3>Are you sure you want to <b>DELETE</b> this data <b>PERMANENTLY</b>?</h3>
    29 <input type="submit" name="cancel" value="NO, cancel">
    30 <input type="submit" name="proceed" value="OK, proceed">
    31 </form>
    32 
    33 {% endblock %}
  • trunk/exodus/templates/exodus-template.html

    r6324 r6325  
    1515          <img width="130" height="97" alt="foto" src="{% url static path="foto.jpg" %}"/><br>
    1616          &nbsp;&nbsp;<A class="menu" href="{% url root %}">Exodus</a><br>
    17           &nbsp;&nbsp;<A class="menu" href="{% url nodelist %}">Node List</a><br>
     17          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.viewNodelist %}">Node List</a><br>
    1818          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.genericLocation "add" "new" %}">Add Location</a><br>
    1919          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.genericNode "add" "new" %}">Add Node</a><br>
  • trunk/exodus/templates/freebsd-5.0/named.conf

    • Property svn:mergeinfo set to
  • trunk/exodus/templates/viewNode.html

    r6324 r6325  
    22
    33{% block content %}
    4 <a href="{% url nodelist %}">Node List</a>
     4<a href="{% url exodus.views.viewNodelist %}">Node List</a>
    55
    66<div style="border:1px solid #000000;">
     
    4747                <li>Long description: {{ interlink.desc }} </li>
    4848                <li>IP: {{ interlink.ip }}/{{ interlink.netmask }} </li>
    49                 <li> Link to Node: <a href="{% url node-detail interlink.node %}">
     49                <li> Link to Node: <a href="{% url exodus.views.viewNode interlink.node %}">
    5050                        {{ interlink.node }}</a> </li>
    5151                </ul>
  • trunk/exodus/templates/viewNodelist.html

    • Property svn:mergeinfo set to
    r6323 r6325  
    55<P class="blue"> Node List </P>
    66
    7 {% if object_list %}
     7{% if nodes %}
    88        <table border="3" cellpadding="1">
    9     {% for object in object_list %}
     9        {% for node in nodes %}
    1010                <tr>
    11                 <td class="list" ><a class="list"href="{% url node-detail object.name %}">{{ object.name }}</a></td>
    12             <td><a href="{% url exodus.views.conf_dhcpd_conf object.name %}">dhcpd.conf</a></td>
    13             <td><a href="{% url exodus.views.conf_named_conf object.name %}">named.conf</a></td>
    14             <td><a href="{% url exodus.views.conf_rc_node_local object.name %}">rc.node.local</a></td>
    15             <td><a href="{% url exodus.views.conf_resolv_conf object.name %}">resolv.conf</a></td>
     11                        <td class="list" ><a class="list"href="{% url exodus.views.viewNode node.name %}">{{ node.name }}</a></td>
     12                        {% for configFile in configFiles %}
     13                                <td><a href="{% url exodus.views.configFile "freebsd-5.0" node.name configFile %}">{{ configFile }}</a></td>
     14                        {% endfor %}
    1615                </tr>
    1716
  • trunk/exodus/urls.py

    r6324 r6325  
    55from os import path as os_path
    66from django.conf import settings
     7from django.views.generic.simple import direct_to_template
    78
    8 ## experimental databrowse code
    9 
     9#
     10# experimental databrowse code
    1011from django.contrib import databrowse
    1112databrowse.site.register(Antenna)
     
    1819databrowse.site.register(DhcpStatic)
    1920
    20 node_dict  = {
    21     'queryset': Node.objects.all(),
    22 }
    23 
    2421urlpatterns = patterns('',
    25 
    26         # databse thingy
    27         (r'^databrowse/(.*)', databrowse.site.root),
    28 
    29         # views
    30         url(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'index.html'}, "root") ,
    31         url(r'^nodelist/$', 'django.views.generic.list_detail.object_list', dict(node_dict, template_name='node-list.html'), "nodelist"),
    32         url(r'^view/node/(?P<node>.+)/$', 'exodus.views.node', {}, "node-detail"),
     22        # generic view
     23        url(r'^$', 'exodus.urls.direct_to_template', {'template': 'index.html'}, "root"),
     24        (r'^view/nodelist/$', 'exodus.views.viewNodelist'),
     25        (r'^view/node/(?P<node>.+)/$', 'exodus.views.viewNode'),
    3326
    3427        # config urls
    35         (r'^config/freebsd-5.0/(?P<object_id>.+)/dhcpd.conf$', 'exodus.views.conf_dhcpd_conf'),
    36         (r'^config/freebsd-5.0/(?P<object_id>.+)/named.conf$', 'exodus.views.conf_named_conf'),
    37         (r'^config/freebsd-5.0/(?P<object_id>.+)/rc.node.local$', 'exodus.views.conf_rc_node_local'),
    38         (r'^config/freebsd-5.0/(?P<object_id>.+)/resolv.conf$', 'exodus.views.conf_resolv_conf'),
    39 
    40 
    41 
    42         (r'^edit/link/(?P<object_id>.+)/$', 'exodus.views.addLink'),
     28        (r'^config/(?P<version>.+)/(?P<node>.+)/(?P<file>.+)$', 'exodus.views.configFile'),
    4329
    4430        # Generic urls
     
    4834        (r'^dhcp/(?P<mode>(add|edit|delete))/(?P<node>.+)/(?P<interface>.+)/(?P<publicAP>.+)/$', 'exodus.views.genericPublicAP'),
    4935
     36        # 3th party/embedded databsse thingy
     37        (r'^databrowse/(.*)', databrowse.site.root),
    5038)
    5139
  • trunk/exodus/views.py

    r6324 r6325  
    1515
    1616
    17 def node(request, node):
    18         object = Node.objects.get(name=node)
    19         return render_to_response('node-detail.html', {'node': object})
    20 
    21 
    22 class addLinkForm(forms.Form):
    23         class Meta:
    24                 model = Node
    25                 exclude = ( 'shortdesc', 'desc' )
    26 
    27 def addLink(request):
    28         if request.POST:
    29                 form = addLinkForm(request.POST)
    30                 if form.is_valid():
    31                         instance = form.save(commit=False)
    32                         # Get this code working and clean it up afterwards
    33                         # check if we have two different ifaces from two different nodes
    34                         # Should add a error message if they are from the same node
    35                         compatibleInterfaces = False
    36                         differentNodes = True
    37                         errorMessage = ""
    38                        
    39                         # check if they have the same mode
    40                         if instance.iface1.node.id == instance.iface2.node.id:
    41                                 differentNodes = False
    42                        
    43                         # Interface check
    44                         # XXX: Make sure interfaces type is defined as beeing a certain type instead of hardcoding
    45                         if instance.iface1.type == instance.iface2.type:
    46                                 compatibleInterfaces = True
    47                         if str(instance.iface1.type) == '11b' and str(instance.iface2.type) == '11g':
    48                                 compatibleInterfaces = True
    49                         if str(instance.iface1.type) == '11g' and str(instance.iface2.type) == '11b':
    50                                 compatibleInterfaces = True
    51                        
    52                         if compatibleInterfaces and differentNodes:
    53                                 instance.save()
    54                                 return HttpResponseRedirect(reverse('nodelist'))
    55                         else:
    56                                 form = addLinkForm(instance = instance)
    57                                 if compatibleInterfaces == False:
    58                                         errorMessage = "Please use compatible interfaces"
    59                                 elif differentNodes == False:
    60                                         errorMessage = "No interlink possible between interfaces on the same node"
    61                                
    62                                 return render_to_response('addinterlink.html',{'form': form, 'error_message' : errorMessage })
    63                         #XXX :if wifi: check master and managed states for existings NICs/Interlinks
    64                         #XXX :check if omni, than Nic must be in master mode
    65                         #Generate SSID
    66                         # add descriptions
    67                         #Generate ips and netmask
    68                         #Save form
    69         else:
    70                 #XXX: Autofetch new IP numbers
    71                 newForm = Link()
    72                 form = addLinkForm(instance = newForm)
    73         return render_to_response('addinterlink.html',{'form': form})
    74 
    75 
    7617class GenericHandler():
    7718        """Conventions used: type has to to the same name as the dependency object, delet template is named delete<type>.html"""
     
    8627               
    8728                if request.POST.has_key('cancel'):
    88                         self.response = HttpResponseRedirect(reverse('node-detail', args=[self.node.name]))
     29                        self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name]))
    8930                elif request.POST.has_key('proceed'):
    9031                        if mode == 'delete':
    9132                                self._deleteete()
    92                                 self.response = HttpResponseRedirect(reverse('node-detail', args=[self.node.name]))
     33                                self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name]))
    9334                        else:
    9435                                # First checking whether form is valid, then add/edit actions
     
    9637                                if self.form.is_valid():
    9738                                        # Set response on forehand, to allow override in procedure
    98                                         self.response = HttpResponseRedirect(reverse('node-detail', args=[self.node.name]))
     39                                        self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name]))
    9940                                        if mode == 'add':
    10041                                                self._add()
     
    266207                self._saveInterface()
    267208                # After adding a location, allow adding a Node with this location
    268                 self.response = HttpResponseRedirect(reverse('exodus.views.genericNode', args=["add", "new"]) + "?location=%i" % self._instance.pk)
     209                self.response = HttpResponseRedirect(
     210                  reverse('exodus.views.genericNode', args=["add", "new"]) + "?location=%i" % self._instance.pk)
    269211
    270212        def _delete(self):
     
    277219
    278220
    279 
    280 
    281 def nodename2id(node):
    282         """Convert node name to ID if found in the database"""
    283         return Node.objects.get(name=node).id
    284 
    285 def conf_generator(node, template):
    286         object_id = nodename2id(node)
    287         object = Node.objects.get(pk=object_id)
    288 
    289         #Some extra values for statictics info
    290         object.name = Node.objects.get(pk=object_id).name
    291         object.host = gethostname()
    292 #       object.nic = object.nic_set.all()
     221#
     222# Views
     223def viewNode(request, node):
     224        node = Node.objects.get(name=node)
     225        return render_to_response('viewNode.html', {'node': node})
     226
     227def viewNodelist(request):
     228        nodes = Node.objects.all()
     229        configFiles = (
     230                'rc.local',
     231                'rc.node.local',
     232                'dhcpd.conf',
     233                'named.conf',
     234                'resolv.conf' )
     235        return render_to_response('viewNodelist.html', {'nodes' : nodes, 'configFiles' : configFiles})
     236
     237def configFile(request, version, node, file):
     238        node = Node.objects.get(name=node)
    293239       
    294         #Used for named.conf
    295         object.domains = Network.objects.all()
    296 
    297         t = loader.get_template(template)
    298         c = Context({'object': object})
    299         return HttpResponse(t.render(c), mimetype='text/plain')
    300 
    301 def conf_dhcpd_conf(request, object_id):
    302         """isc-dhcpd-3-server conf generator"""
    303         return conf_generator(object_id, 'dhcpd.conf')
    304 
    305 def conf_named_conf(request, object_id):
    306         """bind conf generator"""
    307         return conf_generator(object_id, 'named.conf')
    308 
    309 def conf_rc_local(request, object_id):
    310     """5.X legacy rc.local conf generator"""
    311 
    312     object_id = nodename2id(object_id)
    313     object = Node.objects.get(pk=object_id)
    314     object.name = Node.objects.get(pk=object_id).name
    315     object.host = gethostname()
    316 
    317     # check if it is a wireless nic, and add wifimode for wicontrol 
    318     for nic in object:
    319         if nic.ssid:
    320             if nic.mode.mode == 'master':
    321                 nic.wifimode = 6
    322                 nic.wifidesc = 'master mode'
    323             else:
    324                 nic.wifimode = 1
    325                 nic.wifidesc = 'managed mode'
    326     t = loader.get_template('rc-local.txt')
    327     c = Context({'object': object,
    328         })
    329     return HttpResponse(t.render(c), mimetype='text/plain')
    330 
    331 def conf_rc_node_local5X(request, object_id):
    332         """5.X Legacy rc.node.local conf generator"""
    333 
    334         object_id = nodename2id(object_id)
    335 
    336         object.name = Node.objects.get(pk=object_id).name
    337         object.host = gethostname()
    338 
    339         t = loader.get_template('rc-node-local.txt')
    340         c = Context({'object': object,
    341             })
    342         return HttpResponse(t.render(c), mimetype='text/plain')
    343 
    344 def conf_rc_node_local(request, object_id):
    345         """rc.node.local conf generator"""
     240        # Extra statictics information for use of generation
     241        server = {}
     242        server['host'] = gethostname()
    346243       
    347         object_id = nodename2id(object_id)
    348        
    349         object = Node.objects.get(pk=object_id).interface_set.all()
    350         object.name = Node.objects.get(pk=object_id).name
    351         object.host = gethostname()
    352 
    353         t = loader.get_template('rc-node-local.txt')
    354         c = Context({'object': object, })
    355 
    356         print c
    357         return HttpResponse(t.render(c), mimetype='text/plain')
    358 
    359 
    360 def conf_resolv_conf(request, object_id):
    361         """resolv.conf generator"""
    362         return conf_generator(object_id, 'resolv.conf')
    363 
     244        templateFile = version + '/' + file
     245        return render_to_response(templateFile, {'node' : node, 'server' : server},
     246          mimetype='text/plain')
     247
Note: See TracChangeset for help on using the changeset viewer.