summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Raffenetti <raffenet@mcs.anl.gov>2006-10-10 15:23:17 +0000
committerKen Raffenetti <raffenet@mcs.anl.gov>2006-10-10 15:23:17 +0000
commit60030f92fbdee28cc06f59c65654cf7a9c6e70f4 (patch)
treee921901db4b747aeb512e7f21db735aa659d0f91
parent11636a6e5ad02928b150676be21f090795374153 (diff)
downloadbcfg2-60030f92fbdee28cc06f59c65654cf7a9c6e70f4.tar.gz
bcfg2-60030f92fbdee28cc06f59c65654cf7a9c6e70f4.tar.bz2
bcfg2-60030f92fbdee28cc06f59c65654cf7a9c6e70f4.zip
minor updates to plugin and templates
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2427 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Server/Hostbase/hostbase/views.py33
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/edit.html3
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/new.html4
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/remove.html88
-rw-r--r--src/lib/Server/Hostbase/settings.py3
-rw-r--r--src/lib/Server/Plugins/Hostbase.py47
6 files changed, 138 insertions, 40 deletions
diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py
index 8da790d5f..b49af90c7 100644
--- a/src/lib/Server/Hostbase/hostbase/views.py
+++ b/src/lib/Server/Hostbase/hostbase/views.py
@@ -10,11 +10,12 @@ from Hostbase.hostbase.models import *
from datetime import date
from django.db import connection
from django.shortcuts import render_to_response
+from Hostbase import settings
import re
attribs = ['hostname', 'whatami', 'netgroup', 'security_class', 'support',
'csi', 'printq', 'primary_user', 'administrator', 'location',
- 'comments', 'status']
+ 'status']
zoneattribs = ['zone', 'admin', 'primary_master', 'expire', 'retry',
'refresh', 'ttl', 'aux']
@@ -180,7 +181,9 @@ def edit(request, host_id):
# likely use a helper fucntion
for attrib in attribs:
if request.POST.has_key(attrib):
- host.__dict__[attrib] = request.POST[attrib]
+ host.__dict__[attrib] = request.POST[attrib].lower()
+ if request.POST.has_key('comments'):
+ host.comments = request.POST['comments']
if len(request.POST['expiration_date'].split("-")) == 3:
(year, month, day) = request.POST['expiration_date'].split("-")
host.expiration_date = date(int(year), int(month), int(day))
@@ -212,7 +215,7 @@ def edit(request, host_id):
name.name = newname
name.save()
if request.POST['%dip_addr' % inter.id]:
- mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX)
if created:
mx.save()
new_ip = IP(interface=inter, num=len(ips),
@@ -243,7 +246,7 @@ def edit(request, host_id):
hdwr_type=request.POST['hdwr_type_new'])
new_inter.save()
if request.POST['mac_addr_new'] and request.POST['ip_addr_new']:
- mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX)
if created:
mx.save()
new_ip = IP(interface=new_inter, num=0,
@@ -268,7 +271,7 @@ def edit(request, host_id):
name.save()
name.mxs.add(mx)
if request.POST['ip_addr_new'] and not request.POST['mac_addr_new']:
- mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX)
if created:
mx.save()
new_inter = Interface(host=host, mac_addr="",
@@ -478,7 +481,7 @@ def new(request):
Data is validated before committed to the database"""
if request.GET.has_key('sub'):
try:
- Host.objects.get(hostname=request.POST['hostname'])
+ Host.objects.get(hostname=request.POST['hostname'].lower())
return render_to_response('errors.html',
{'failures': ['%s already exists in hostbase' % request.POST['hostname']]})
except:
@@ -491,7 +494,9 @@ def new(request):
host.dhcp = request.POST.has_key('dhcp')
for attrib in attribs:
if request.POST.has_key(attrib):
- host.__dict__[attrib] = request.POST[attrib]
+ host.__dict__[attrib] = request.POST[attrib].lower()
+ if request.POST.has_key('comments'):
+ host.comments = request.POST['comments']
if request.POST.has_key('expiration_date'):
host.__dict__['expiration_date'] = date(2000, 1, 1)
host.status = 'active'
@@ -508,7 +513,7 @@ def new(request):
new_ip = IP(interface=new_inter,
num=0, ip_addr=request.POST['ip_addr_new'])
new_ip.save()
- mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX)
if created:
mx.save()
new_name = "-".join([host.hostname.split(".")[0],
@@ -536,7 +541,7 @@ def new(request):
new_ip = IP(interface=new_inter, num=0,
ip_addr=request.POST['ip_addr_new1'])
new_ip.save()
- mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX)
if created:
mx.save()
new_name = "-".join([host.hostname.split(".")[0],
@@ -566,7 +571,7 @@ def new(request):
new_ip = IP(interface=new_inter, num=0,
ip_addr=request.POST['ip_addr_new2'])
new_ip.save()
- mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX)
if created:
mx.save()
new_name = "-".join([host.hostname.split(".")[0],
@@ -595,7 +600,7 @@ def new(request):
new_ip = IP(interface=new_inter, num=0,
ip_addr=request.POST['ip_addr_new2'])
new_ip.save()
- mx, created = MX.objects.get_or_create(priority=30, mx='mailgw.mcs.anl.gov')
+ mx, created = MX.objects.get_or_create(priority=settings.PRIORITY, mx=settings.DEFAULT_MX)
if created:
mx.save()
new_name = "-".join([host.hostname.split(".")[0],
@@ -627,7 +632,7 @@ def new(request):
'WHATAMI_CHOICES': Host.WHATAMI_CHOICES})
def remove(request, host_id):
- host = Host.GET.objects.get(id=host_id)
+ host = Host.objects.get(id=host_id)
if request.has_key('sub'):
for interface in host.interface_set.all():
for ip in interface.ip_set.all():
@@ -637,7 +642,7 @@ def remove(request, host_id):
interface.ip_set.all().delete()
interface.delete()
host.delete()
- return HttpResponseRedirect('/hostbase/%s/' % host_id)
+ return HttpResponseRedirect('/hostbase/')
else:
"""Displays general host information"""
interfaces = []
@@ -678,7 +683,7 @@ def validate(request, new=False, host_id=None):
and request.POST['administrator']):
failures.append('administrator')
- locationregex = re.compile('^[0-9]{3}-[a-z][0-9]{3}$|none|bmr|cave|dsl|evl|mobile|offsite|mural|activespaces')
+ locationregex = re.compile('^[0-9]{3}-[a-zA-Z][0-9]{3}$|none|bmr|cave|dsl|evl|mobile|offsite|mural|activespaces')
if not (request.POST['location']
and locationregex.match(request.POST['location'])):
failures.append('location')
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html
index efc308def..0785b64e8 100644
--- a/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/edit.html
@@ -46,13 +46,12 @@ div#interface{
<form name="hostdata" action="?sub=true" method="post">
<input type="hidden" name="host" value="{{ host.id }}">
-<input type="hidden" name="hostname" value="{{ host.hostname }}">
<table border="0" width="100%">
<colgroup>
<col width="150">
<col width="*">
<tr> <td> <b>hostname</b></td>
- <td> {{ host.hostname }}</td></tr>
+ <td> <input name="hostname" value="{{ host.hostname }}"></td></tr>
<tr> <td> <b>whatami</b></td>
<td>
<select name="whatami">
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
index 949afc611..bcec42404 100644
--- a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
@@ -62,9 +62,9 @@
<td>
<input type="checkbox" name="outbound_smtp"></td></tr>
<tr> <td> <b>primary_user</b></td>
- <td> <input name="primary_user" type="text" size="32" ></td></tr>
+ <td> <input name="primary_user" type="text" size="32" > (email address)</td></tr>
<tr> <td> <b>administrator</b></td>
- <td> <input name="administrator" type="text" size="32" ></td></tr>
+ <td> <input name="administrator" type="text" size="32" > (email address)</td></tr>
<tr> <td> <b>location</b></td>
<td> <input name="location" type="text" ></td></tr>
<tr> <td> <b>expiration_date</b></td>
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/remove.html b/src/lib/Server/Hostbase/hostbase/webtemplates/remove.html
new file mode 100644
index 000000000..19c73b4f9
--- /dev/null
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/remove.html
@@ -0,0 +1,88 @@
+{% extends "base.html" %}
+
+{% block pagebanner %}
+ <div class="header">
+ <h2>Are you sure you want to remove {{ host.hostname }}?</h2>
+ </div>
+ <br/>
+{% endblock %}
+
+{% block sidebar %}
+{% include "navbar" %}
+<ul class="sidebar">
+ <li><a href="dns/" class="sidebar">detailed dns info</a></li>
+ <li><a href="edit/" class="sidebar">edit host info</a></li>
+ <li><a href="dns/edit/" class="sidebar">edit dns info</a></li>
+</ul>
+{% endblock %}
+
+{% block content %}
+
+<table border="0" width="100%">
+ <colgroup>
+ <col width="150">
+ <col width="*">
+ <tr> <td> <b>hostname</b></td>
+ <td> {{ host.hostname }}</td></tr>
+ <tr> <td> <b>whatami</b></td>
+ <td> {{ host.whatami }}</td></tr>
+ <tr> <td> <b>netgroup</b></td>
+ <td> {{ host.netgroup }}</td></tr>
+ <tr> <td> <b>class</b></td>
+ <td> {{ host.security_class }}</td></tr>
+ <tr> <td> <b>support</b></td>
+ <td> {{ host.support }}</td></tr>
+ <tr> <td> <b>csi</b></td>
+ <td> {{ host.csi }}</td></tr>
+ <tr> <td> <b>printq</b></td>
+ <td> {{ host.printq }}</td></tr>
+ <tr> <td> <b>dhcp</b></td>
+ {% if host.dhcp %}
+ <td> y </td></tr>
+ {% else %}
+ <td> n </td></tr>
+ {% endif %}
+ <tr> <td> <b>outbound_smtp</b></td>
+ {% if host.outbound_smtp %}
+ <td> y </td></tr>
+ {% else %}
+ <td> n </td></tr>
+ {% endif %}
+ <tr> <td> <b>primary_user</b></td>
+ <td> {{ host.primary_user }}</td></tr>
+ <tr> <td> <b>administrator</b></td>
+ <td> {{ host.administrator }}</td></tr>
+ <tr> <td> <b>location</b></td>
+ <td> {{ host.location }}</td></tr>
+ <tr> <td> <b>expiration_date</b></td>
+ <td> {{ host.expiration_date }}</td></tr>
+ {% for interface in interfaces %}
+ <tr> <td><br><b>Interface</b></td>
+ {% ifnotequal interface.0.hdwr_type 'no' %}
+ <td><br>{{ interface.0.hdwr_type }}</td></tr>
+ {% endifnotequal %}
+ <tr> <td> <b>mac_addr</b></td>
+ <td> {{ interface.0.mac_addr }}</b></td></tr>
+ {% for ip in interface.1 %}
+ <tr> <td> <b>ip_addr</b></td>
+ <td> {{ ip.ip_addr }}</td></tr>
+ {% endfor %}
+ {% endfor %}
+ <tr> <td valign="top"> <b>comments</b></td>
+ <td>
+ {{ host.comments|linebreaksbr }}<br>
+ </td></tr>
+
+</table>
+<a style="font-size:75%" href="/hostbase/{{ host.id }}/dns/">see detailed DNS information for this host</a>
+<br><br>
+this host is {{ host.status }}<br>
+last update on {{ host.last }}<br>
+
+<form name="input" action="remove.html?sub=true" method="post">
+<input type="submit" value="remove">
+<input type="reset" value="cancel" onclick="history.back()">
+</form>
+
+{% endblock %}
+
diff --git a/src/lib/Server/Hostbase/settings.py b/src/lib/Server/Hostbase/settings.py
index 2ca589bd8..5176167fe 100644
--- a/src/lib/Server/Hostbase/settings.py
+++ b/src/lib/Server/Hostbase/settings.py
@@ -77,3 +77,6 @@ INSTALLED_APPS = (
'django.contrib.sites',
'Hostbase.hostbase',
)
+
+DEFAULT_MX = 'mailgw.mcs.anl.gov'
+PRIORITY = 30
diff --git a/src/lib/Server/Plugins/Hostbase.py b/src/lib/Server/Plugins/Hostbase.py
index f4381d4b9..83c7a1e3a 100644
--- a/src/lib/Server/Plugins/Hostbase.py
+++ b/src/lib/Server/Plugins/Hostbase.py
@@ -33,7 +33,7 @@ import re
## def rebuildState(self, event):
## '''This function is called when underlying data has changed'''
## pass
-
+
class Hostbase(Plugin):
'''The Hostbase plugin handles host/network info'''
__name__ = 'Hostbase'
@@ -45,18 +45,19 @@ class Hostbase(Plugin):
self.ready = False
Plugin.__init__(self, core, datastore)
- sys.path.append(self.data)
- os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
+ files = ['zone.tmpl', 'reversesoa.tmpl', 'named.tmpl', 'reverseappend.tmpl',
+ 'dhcpd.tmpl', 'hosts.tmpl', 'hostsappend.tmpl']
+ os.environ['DJANGO_SETTINGS_MODULE'] = 'Hostbase.settings'
from django.template import loader
## try:
-## DataNexus.__init__(self, datastore + '/Hostbase/data',
-## files, self.core.fam)
+## self.repository = DataNexus(self.data + '/templates/',
+## files, self.core.fam)
## except:
## self.LogError("Failed to load data directory")
## raise PluginInitError
self.filedata = {}
self.dnsservers = []
- self.dhcpservers = ['scotty']
+ self.dhcpservers = []
self.templates = {'zone':Template(open(self.data + '/templates/' + 'zone.tmpl').read()),
'reversesoa':Template(open(self.data + '/templates/' + 'reversesoa.tmpl').read()),
'named':Template(open(self.data + '/templates/' + 'named.tmpl').read()),
@@ -279,22 +280,23 @@ class Hostbase(Plugin):
count = 0
hosts = []
hostdata = [dhcphosts[0][0], dhcphosts[0][1], dhcphosts[0][2]]
- for x in range(1, len(cursor.fetchall())):
- # if an interface has 2 or more ip addresses
- # adds the ip to the current interface
- if hostdata[0].split(".")[0] == dhcphosts[x][0].split(".")[0] and hostdata[1] == dhcphosts[x][1]:
- hostdata[2] = ", ".join([hostdata[2], dhcphosts[x][2]])
- # if a host has 2 or more interfaces
- # writes the current one and grabs the next
- elif hostdata[0].split(".")[0] == dhcphosts[x][0].split(".")[0]:
- hosts.append(hostdata)
- count += 1
- hostdata = ["-".join([dhcphosts[x][0], str(count)]), dhcphosts[x][1], dhcphosts[x][2]]
- # new host found, writes current data to the template
- else:
- hosts.append(hostdata)
- count = 0
- hostdata = [dhcphosts[x][0], dhcphosts[x][1], dhcphosts[x][2]]
+ if len(dhcphosts) > 1:
+ for x in range(1, len(cursor.fetchall())):
+ # if an interface has 2 or more ip addresses
+ # adds the ip to the current interface
+ if hostdata[0].split(".")[0] == dhcphosts[x][0].split(".")[0] and hostdata[1] == dhcphosts[x][1]:
+ hostdata[2] = ", ".join([hostdata[2], dhcphosts[x][2]])
+ # if a host has 2 or more interfaces
+ # writes the current one and grabs the next
+ elif hostdata[0].split(".")[0] == dhcphosts[x][0].split(".")[0]:
+ hosts.append(hostdata)
+ count += 1
+ hostdata = ["-".join([dhcphosts[x][0], str(count)]), dhcphosts[x][1], dhcphosts[x][2]]
+ # new host found, writes current data to the template
+ else:
+ hosts.append(hostdata)
+ count = 0
+ hostdata = [dhcphosts[x][0], dhcphosts[x][1], dhcphosts[x][2]]
#makes sure the last of the data gets written out
if hostdata not in hosts:
hosts.append(hostdata)
@@ -434,6 +436,7 @@ Name Room User Type
from django.db import connection
+ # this header needs to be changed to be more generic
header = """+@machines
+@all-machines
achilles.ctd.anl.gov