summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKen Raffenetti <raffenet@mcs.anl.gov>2006-09-21 21:57:44 +0000
committerKen Raffenetti <raffenet@mcs.anl.gov>2006-09-21 21:57:44 +0000
commitec7999775cc74f3eee97b84eb4e4ef9341da594b (patch)
treef67c8f956a03010badd88b775446d3e92eb0621e
parent1e2efbb211c375d384a17f4ff7bccba366202076 (diff)
downloadbcfg2-ec7999775cc74f3eee97b84eb4e4ef9341da594b.tar.gz
bcfg2-ec7999775cc74f3eee97b84eb4e4ef9341da594b.tar.bz2
bcfg2-ec7999775cc74f3eee97b84eb4e4ef9341da594b.zip
tweaks to dhcp generation
git-svn-id: https://svn.mcs.anl.gov/repos/bcfg/trunk/bcfg2@2297 ce84e21b-d406-0410-9b95-82705330c041
-rw-r--r--src/lib/Server/Hostbase/hostbase/views.py8
-rw-r--r--src/lib/Server/Hostbase/hostbase/webtemplates/new.html4
-rw-r--r--src/lib/Server/Hostbase/settings.py4
-rw-r--r--src/lib/Server/Hostbase/templates/dhcpd.tmpl508
-rw-r--r--src/lib/Server/Plugins/Hostbase.py14
5 files changed, 25 insertions, 513 deletions
diff --git a/src/lib/Server/Hostbase/hostbase/views.py b/src/lib/Server/Hostbase/hostbase/views.py
index c45f187d8..8d7fd3d3a 100644
--- a/src/lib/Server/Hostbase/hostbase/views.py
+++ b/src/lib/Server/Hostbase/hostbase/views.py
@@ -450,6 +450,12 @@ def new(request):
"""Function for creating a new host in hostbase
Data is validated before committed to the database"""
if request.GET.has_key('sub'):
+ try:
+ Host.objects.get(hostname=request.POST['hostname'])
+ return render_to_response('errors.html',
+ {'failures': ['%s already exists in hostbase' % request.POST['hostname']]})
+ except:
+ pass
if not validate(request, True):
host = Host()
# this is the stuff that validate() should take care of
@@ -459,6 +465,8 @@ def new(request):
for attrib in attribs:
if request.POST.has_key(attrib):
host.__dict__[attrib] = request.POST[attrib]
+ if request.POST.has_key('expiration_date'):
+ host.__dict__['expiration_date'] = date(2000, 1, 1)
host.status = 'active'
host.save()
else:
diff --git a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
index fd57e2c8e..949afc611 100644
--- a/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
+++ b/src/lib/Server/Hostbase/hostbase/webtemplates/new.html
@@ -8,9 +8,7 @@
{% endblock %}
{% block sidebar %}
-<ul class="sidebar">
- <li><a href="/hostbase/" class="sidebar">search hostbase</a></li>
-</ul>
+<a href="/hostbase/" class="sidebar">search hostbase</a>
{% endblock %}
{% block content %}
diff --git a/src/lib/Server/Hostbase/settings.py b/src/lib/Server/Hostbase/settings.py
index a7ef0dfbe..2ca589bd8 100644
--- a/src/lib/Server/Hostbase/settings.py
+++ b/src/lib/Server/Hostbase/settings.py
@@ -63,7 +63,9 @@ TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates".
# Always use forward slashes, even on Windows.
'/usr/lib/python2.3/site-packages/Hostbase/hostbase/webtemplates',
- '/usr/lib/python2.4/site-packages/Hostbase/hostbase/webtemplates'
+ '/usr/lib/python2.4/site-packages/Hostbase/hostbase/webtemplates',
+ '/usr/lib/python2.3/site-packages/Hostbase/templates',
+ '/usr/lib/python2.4/site-packages/Hostbase/templates',
)
diff --git a/src/lib/Server/Hostbase/templates/dhcpd.tmpl b/src/lib/Server/Hostbase/templates/dhcpd.tmpl
index 3784ae792..d4fd29447 100644
--- a/src/lib/Server/Hostbase/templates/dhcpd.tmpl
+++ b/src/lib/Server/Hostbase/templates/dhcpd.tmpl
@@ -2,514 +2,16 @@
# This file is automatically generated.
# DO NOT EDIT IT BY HAND!
#
-# This file contains $numips IP addresses
-# Generated on: $timecreated
+# This file contains {{ numips }} IP addresses
+# Generated on: {{ timecreated }}
#
-#
-#
-# dhcpd.conf
-#
-# Configuration file for ISC dhcpd
-#
-
-server-identifier thwap.mcs.anl.gov;
-
-# option definitions common to all supported networks...
-option domain-name "mcs.anl.gov";
-option domain-name-servers adc.mcs.anl.gov, antares-9.mcs.anl.gov, t1dns2.anl.gov, t1dns1.anl.gov;
-option option-140 code 140 = text;
-default-lease-time 28800;
-max-lease-time 28800;
-server-name "adc.mcs.anl.gov";
-next-server 140.221.8.10;
-filename "startrom.com";
-ddns-update-style none;
-authoritative;
-log-facility local7;
-option option-140 "140.221.9.24";
-
-subnet 10.140.222.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 10.140.222.255;
- option routers 10.140.222.1;
- option option-140 "140.221.9.24";
- default-lease-time 3600;
- max-lease-time 3600;
-}
-
-shared-network "SystemsNet" {
-
- subnet 140.221.2.0 netmask 255.255.255.0 {
- server-identifier 140.221.9.112;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.2.255;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option routers 140.221.2.1;
- option option-140 "140.221.9.24";
- default-lease-time 28800;
- max-lease-time 28800;
- deny unknown-clients;
- }
-
- subnet 140.221.127.0 netmask 255.255.255.0 {
- pool {
- range 140.221.127.10 140.221.127.199;
- server-identifier 140.221.9.112;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.127.255;
- option routers 140.221.127.1;
- deny unknown-clients;
- default-lease-time 3600;
- max-lease-time 3600;
- }
- }
-
- subnet 10.0.2.0 netmask 255.255.255.0 {
- pool {
- range 10.0.2.10 10.0.2.199;
- allow unknown-clients;
- option subnet-mask 255.255.255.0;
- option broadcast-address 10.0.2.255;
- option netbios-name-servers 10.0.2.1;
- option routers 10.0.2.1;
- option domain-name "guest.mcs.anl.gov";
- option domain-name-servers 10.0.2.1;
- server-identifier 10.0.2.1;
- default-lease-time 60;
- max-lease-time 60;
- }
- }
-
-} # End systems vlan
-
-shared-network "Wireless" {
-
- subnet 140.221.56.0 netmask 255.255.254.0 {
- option subnet-mask 255.255.254.0;
- option routers 140.221.57.253;
- server-identifier 140.221.9.112;
- option broadcast-address 140.221.57.255;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option option-140 "140.221.9.24";
- default-lease-time 28800;
- max-lease-time 28800;
- deny unknown-clients;
- }
-
- subnet 140.221.119.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option routers 140.221.119.1;
- option broadcast-address 140.221.119.255;
- default-lease-time 28800;
- max-lease-time 28800;
- deny unknown-clients;
- }
-
- subnet 140.221.120.0 netmask 255.255.255.0 {
- pool {
- range 140.221.120.10 140.221.120.199;
- server-identifier 140.221.9.112;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.120.255;
- option routers 140.221.120.1;
- deny unknown-clients;
- default-lease-time 3600;
- max-lease-time 3600;
- }
- }
-
- subnet 10.0.16.0 netmask 255.255.255.0 {
- pool {
- range 10.0.16.10 10.0.16.199;
- allow unknown-clients;
- option subnet-mask 255.255.255.0;
- option broadcast-address 10.0.16.255;
- option netbios-name-servers 10.0.16.1;
- option routers 10.0.16.1;
- option domain-name "guest.mcs.anl.gov";
- option domain-name-servers 10.0.16.1;
- server-identifier 10.0.16.1;
- default-lease-time 60;
- max-lease-time 60;
- }
- }
-
-} # End Wireless vlan
-
-shared-network "I2U2" {
-
- subnet 192.5.186.64 netmask 255.255.255.192 {
- option subnet-mask 255.255.255.192;
- option routers 192.5.186.65;
- option domain-name "i2u2.org";
- option domain-name-servers 140.221.9.6, 130.202.101.37, 130.202.101.6;
- server-identifier 140.221.9.112;
- option broadcast-address 192.5.186.127;
- default-lease-time 28800;
- max-lease-time 28800;
- deny unknown-clients;
- }
-
- subnet 10.5.186.64 netmask 255.255.255.192 {
- pool {
- range 10.5.186.70 10.5.186.90;
- allow unknown-clients;
- option subnet-mask 255.255.255.192;
- option broadcast-address 10.5.186.127;
- option netbios-name-servers 10.5.186.66;
- option routers 10.5.186.65;
- option domain-name "guest.i2u2.org";
- option domain-name-servers 10.5.186.66;
- server-identifier 10.5.186.66;
- default-lease-time 60;
- max-lease-time 60;
- }
- }
-
-} # End I2U2 vlan
-
-# Subnet 338 for CPH folk
-subnet 140.221.12.0 netmask 255.255.255.0 {
- server-identifier 140.221.9.112;
- range 140.221.12.200 140.221.12.210;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.12.255;
- option routers 140.221.12.1;
- option netbios-name-servers 146.137.96.90, 146.137.162.86;
- default-lease-time 28800;
- max-lease-time 28800;
-}
-# Subnet 338 for CPH printers
-subnet 140.221.14.0 netmask 255.255.255.192 {
- server-identifier 140.221.9.112;
- option subnet-mask 255.255.255.192;
- option broadcast-address 140.221.14.63;
- option routers 140.221.14.1;
- option netbios-name-servers 146.137.96.90, 146.137.162.86;
- default-lease-time 28800;
- max-lease-time 28800;
-}
-
-# vlan85 - nmpdr
-subnet 192.5.200.0 netmask 255.255.255.128 {
- server-identifier 140.221.9.112;
- option subnet-mask 255.255.255.128;
- option broadcast-address 192.5.200.127;
- option domain-name-servers 140.221.9.6, 130.202.101.37, 130.202.101.6;
- option routers 192.5.200.1;
- default-lease-time 28800;
- max-lease-time 28800;
-}
-
-
-shared-network "BorgNet" {
-subnet 140.221.8.0 netmask 255.255.252.0 {
- option subnet-mask 255.255.252.0;
- option broadcast-address 140.221.11.255;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option routers 140.221.11.253;
- option option-140 "140.221.9.24";
- deny unknown-clients;
-}
-
-subnet 140.221.5.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.5.255;
- option routers 140.221.5.1;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option routers 140.221.5.1;
- deny unknown-clients;
-}
-
- subnet 140.221.123.0 netmask 255.255.255.0 {
- range 140.221.123.10 140.221.123.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.123.255;
- option routers 140.221.123.1;
-}
-} # End of borg vlan
-
-#shared-network "WirelessNet" {
-# subnet 140.221.56.0 netmask 255.255.254.0 {
-# option subnet-mask 255.255.254.0;
-# # option broadcast-address 140.221.57.255;
-# option routers 140.221.57.253;
-#}
-# subnet 140.221.120.0 netmask 255.255.255.0 {
-# range 140.221.120.10 140.221.120.199;
-# option subnet-mask 255.255.255.0;
-# option broadcast-address 140.221.120.255;
-# option routers 140.221.120.1;
-#}
-#} # end "WirelessNet"
-
-subnet 140.221.1.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.1.255;
- option routers 140.221.1.1;
-}
-
-subnet 140.221.3.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.3.255;
- option routers 140.221.3.1;
-}
-
-subnet 140.221.4.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.4.255;
- option routers 140.221.4.1;
-}
-
-subnet 140.221.6.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.6.255;
- option routers 140.221.6.1;
-}
-
-subnet 140.221.7.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.7.255;
- option routers 140.221.7.1;
-}
-
-subnet 140.221.13.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.13.255;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option routers 140.221.13.1;
-}
-
-subnet 140.221.15.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.15.255;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option routers 140.221.10.253;
-}
-
-subnet 140.221.16.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.16.255;
- option routers 140.221.16.253;
-}
-
-subnet 140.221.20.0 netmask 255.255.255.224 {
- range 140.221.20.16 140.221.20.16;
- range 140.221.20.17 140.221.20.17;
- range 140.221.20.18 140.221.20.18;
- range 140.221.20.19 140.221.20.19;
- range 140.221.20.20 140.221.20.20;
- range 140.221.20.21 140.221.20.21;
- range 140.221.20.22 140.221.20.22;
- range 140.221.20.23 140.221.20.23;
- range 140.221.20.24 140.221.20.24;
- range 140.221.20.25 140.221.20.25;
- range 140.221.20.26 140.221.20.26;
- range 140.221.20.27 140.221.20.27;
- range 140.221.20.28 140.221.20.28;
- option subnet-mask 255.255.255.224;
- option broadcast-address 140.221.20.31;
- option routers 140.221.20.1;
-}
-
-subnet 140.221.20.32 netmask 255.255.255.224 {
- range 140.221.20.36 140.221.20.36;
- range 140.221.20.37 140.221.20.37;
- range 140.221.20.38 140.221.20.38;
- range 140.221.20.39 140.221.20.39;
- range 140.221.20.40 140.221.20.40;
- option subnet-mask 255.255.255.224;
- option broadcast-address 140.221.20.63;
- option routers 140.221.20.33;
-}
-
-subnet 140.221.32.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.32.255;
- option routers 140.221.32.253;
-}
-
-subnet 140.221.34.0 netmask 255.255.255.240 {
- range 140.221.34.6 140.221.34.6;
- range 140.221.34.12 140.221.34.12;
- option subnet-mask 255.255.255.240;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option routers 140.221.34.13;
-}
-
-subnet 140.221.34.64 netmask 255.255.255.192 {
- range 140.221.34.77 140.221.34.77;
- range 140.221.34.80 140.221.34.80;
- range 140.221.34.82 140.221.34.82;
- range 140.221.34.91 140.221.34.95;
- range 140.221.34.121 140.221.34.125;
- option subnet-mask 255.255.255.192;
- option netbios-name-servers 140.221.9.66;
- option netbios-node-type 8;
- option routers 140.221.34.65;
- option option-140 "140.221.9.24";
-}
-
-subnet 140.221.35.32 netmask 255.255.255.224 {
- option subnet-mask 255.255.255.224;
- option broadcast-address 141.221.35.63;
- option routers 140.221.35.33;
-}
-
-subnet 140.221.36.0 netmask 255.255.255.192 {
- option subnet-mask 255.255.255.192;
- option broadcast-address 141.221.36.63;
- option routers 140.221.36.1;
- }
-
-
-subnet 140.221.37.0 netmask 255.255.255.128 {
- option subnet-mask 255.255.255.128;
- option domain-name-servers antares-9.mcs.anl.gov, t1dns2.anl.gov;
- option netbios-name-servers 140.221.37.41;
- option routers 140.221.37.1;
-}
-
-subnet 140.221.47.144 netmask 255.255.255.252 {
- option subnet-mask 255.255.255.252;
- # option broadcast-address 140.221.32.255;
- option routers 140.221.47.145;
-}
-
-subnet 140.221.48.96 netmask 255.255.255.240 {
- option subnet-mask 255.255.255.240;
- # option broadcast-address 140.221.32.255;
- option routers 140.221.48.97;
-}
-
-subnet 140.221.58.128 netmask 255.255.255.128 {
- option subnet-mask 255.255.255.240;
- option broadcast-address 140.221.58.143;
- option routers 140.221.58.129;
-}
-
-subnet 140.221.64.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- # option broadcast-address 140.221.64.255;
- option routers 140.221.64.253;
-}
-
-subnet 140.221.70.0 netmask 255.255.255.0 {
- option subnet-mask 255.255.255.0;
- # option broadcast-address 140.221.70.255;
- option routers 140.221.70.253, 140.221.70.1;
-}
-
-#subnet 146.137.172.0 netmask 255.255.254.0 {
-# option subnet-mask 255.255.254.0;
-# # option broadcast-address 146.137.173.255;
-# option routers 146.137.172.125;
-#}
-
- subnet 140.221.126.0 netmask 255.255.255.0 {
- range 140.221.126.10 140.221.126.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.126.255;
- option routers 140.221.126.1;
-}
-
- subnet 140.221.125.0 netmask 255.255.255.0 {
- range 140.221.125.10 140.221.125.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.125.255;
- option routers 140.221.125.1;
-}
-
- subnet 140.221.124.0 netmask 255.255.255.0 {
- range 140.221.124.10 140.221.124.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.124.255;
- option routers 140.221.124.1;
-}
-
- subnet 140.221.122.0 netmask 255.255.255.0 {
- range 140.221.122.10 140.221.122.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.122.255;
- option routers 140.221.122.1;
-}
-
- subnet 140.221.121.0 netmask 255.255.255.0 {
- range 140.221.121.10 140.221.121.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.121.255;
- option routers 140.221.121.1;
-}
-
-
- subnet 140.221.119.0 netmask 255.255.255.0 {
- range 140.221.119.10 140.221.119.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.119.255;
- option routers 140.221.119.1;
-}
-
- subnet 140.221.118.0 netmask 255.255.255.0 {
- range 140.221.118.10 140.221.118.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.118.255;
- option routers 140.221.118.1;
-}
-
- subnet 140.221.117.0 netmask 255.255.255.0 {
- range 140.221.117.10 140.221.117.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.117.255;
- option routers 140.221.117.1;
-}
-
- subnet 140.221.116.0 netmask 255.255.255.0 {
- range 140.221.116.10 140.221.116.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.116.255;
- option routers 140.221.116.1;
-}
-
- subnet 140.221.115.0 netmask 255.255.255.0 {
- range 140.221.115.10 140.221.115.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.115.255;
- option routers 140.221.115.1;
-}
-
- subnet 140.221.114.0 netmask 255.255.255.0 {
- range 140.221.114.10 140.221.114.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.114.255;
- option routers 140.221.114.1;
-}
-
- subnet 140.221.113.0 netmask 255.255.255.0 {
- range 140.221.113.10 140.221.113.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.113.255;
- option routers 140.221.113.1;
-}
- subnet 140.221.112.0 netmask 255.255.255.0 {
- range 140.221.112.10 140.221.112.199;
- option subnet-mask 255.255.255.0;
- option broadcast-address 140.221.112.255;
- option routers 140.221.112.1;
-}
+{% include "dhcpd.conf.head" %}
# Hosts which require special configuration options can be listed in
# host statements. If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration.
-#for $host in $hosts
-host $host[0] {hardware ethernet $host[1];fixed-address $host[2];}
-#end for
+{% for host in hosts %}host {{ host.0 }} {hardware ethernet {{ host.1 }};fixed-address {{ host.2 }};}
+{% endfor %}
diff --git a/src/lib/Server/Plugins/Hostbase.py b/src/lib/Server/Plugins/Hostbase.py
index bc5468926..36d2a348d 100644
--- a/src/lib/Server/Plugins/Hostbase.py
+++ b/src/lib/Server/Plugins/Hostbase.py
@@ -9,7 +9,7 @@ from Bcfg2.Server.Plugin import Plugin, PluginExecutionError, PluginInitError, D
from time import strftime
from sets import Set
import re
-
+from django.template import loader, Context
## class DataNexus(DirectoryBacked):
## '''DataNexus is an object that watches multiple files and
@@ -61,7 +61,7 @@ class Hostbase(Plugin):
'reversesoa':Template(open(self.data + '/templates/' + 'reversesoa.tmpl').read()),
'named':Template(open(self.data + '/templates/' + 'named.tmpl').read()),
'reverseapp':Template(open(self.data + '/templates/' + 'reverseappend.tmpl').read()),
- 'dhcp':Template(open(self.data + '/templates/' + 'dhcpd.tmpl').read()),
+ 'dhcp':loader.get_template('dhcpd.tmpl'),
'hosts':Template(open(self.data + '/templates/' + 'hosts.tmpl').read()),
'hostsapp':Template(open(self.data + '/templates/' + 'hostsappend.tmpl').read()),
}
@@ -300,11 +300,13 @@ class Hostbase(Plugin):
if hostdata not in hosts:
hosts.append(hostdata)
- self.templates['dhcp'].hosts = hosts
- self.templates['dhcp'].numips = len(hosts)
- self.templates['dhcp'].timecreated = strftime("%a %b %d %H:%M:%S %Z %Y")
+ context = Context({
+ 'hosts': hosts,
+ 'numips': len(hosts),
+ 'timecreated': strftime("%a %b %d %H:%M:%S %Z %Y"),
+ })
- self.filedata['dhcpd.conf'] = str(self.templates['dhcp'])
+ self.filedata['dhcpd.conf'] = self.templates['dhcp'].render(context)
self.Entries['ConfigFile']['/etc/dhcpd.conf'] = self.FetchFile