Import rest of modules.
This commit is contained in:
parent
02fa10f33c
commit
3f225ced9b
39 changed files with 2056 additions and 0 deletions
52
dhcp/files/dhcpdump.py
Executable file
52
dhcp/files/dhcpdump.py
Executable file
|
@ -0,0 +1,52 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import re
|
||||
import sys
|
||||
from subprocess import Popen, PIPE
|
||||
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
print >>sys.stderr, 'Usage: %s <template>' % sys.argv[0]
|
||||
sys.exit(1)
|
||||
|
||||
for template in sys.argv[1:]:
|
||||
template = open(template, 'r')
|
||||
for line in template.readlines():
|
||||
m = re.match('([ \t]*)--(.+)--[ \t]*$', line)
|
||||
if m is not None:
|
||||
indent = m.group(1)
|
||||
for entry in ldapsearch(m.group(2)):
|
||||
print '%s%s' % (indent, entry)
|
||||
else:
|
||||
sys.stdout.write(line)
|
||||
template.close()
|
||||
|
||||
|
||||
def ldapsearch(filter):
|
||||
p = Popen(['ldapsearch', '-x', '-LLL', filter, 'cn', 'macAddress', 'ipHostNumber'],
|
||||
bufsize=1024, stdout=PIPE, close_fds=True)
|
||||
ret = []
|
||||
cur = {}
|
||||
for l in p.stdout.readlines():
|
||||
l = l.strip()
|
||||
if l == '':
|
||||
try:
|
||||
ret.append('host %s { option host-name "%s"; hardware ethernet %s; fixed-address %s; }' % (
|
||||
cur["cn"], cur["cn"].split('.')[0], cur["macAddress"], cur["ipHostNumber"]))
|
||||
except KeyError:
|
||||
print "foo"
|
||||
cur = {}
|
||||
continue
|
||||
l = l.split()
|
||||
if l[0] in ('cn:', 'macAddress:', 'ipHostNumber:'):
|
||||
cur[l[0][0:-1]] = l[1]
|
||||
return ret
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
sys.exit()
|
||||
|
75
dhcp/manifests/init.pp
Normal file
75
dhcp/manifests/init.pp
Normal file
|
@ -0,0 +1,75 @@
|
|||
|
||||
class dhcp::server {
|
||||
|
||||
package { "dhcp":
|
||||
name => $operatingsystem ? {
|
||||
OpenBSD => "isc-dhcp-server",
|
||||
default => "dhcp",
|
||||
},
|
||||
ensure => installed,
|
||||
}
|
||||
|
||||
file { "/usr/local/sbin/dhcpdump.py":
|
||||
ensure => present,
|
||||
source => "puppet:///dhcp/dhcpdump.py",
|
||||
mode => 0755,
|
||||
owner => root,
|
||||
group => $operatingsystem ? {
|
||||
OpenBSD => wheel,
|
||||
default => root,
|
||||
},
|
||||
}
|
||||
|
||||
file { "/etc/dhcpd.conf.in":
|
||||
ensure => present,
|
||||
source => [ "puppet:///files/dhcp/dhcpd.conf.in.${hostname}",
|
||||
"puppet:///files/dhcp/dhcpd.conf.in", ],
|
||||
mode => 0644,
|
||||
owner => root,
|
||||
group => $operatingsystem ? {
|
||||
OpenBSD => wheel,
|
||||
default => root,
|
||||
},
|
||||
require => Package["dhcp"],
|
||||
}
|
||||
|
||||
file { "dhcpd.leases":
|
||||
name => $operatingsystem ? {
|
||||
OpenBSD => "/var/db/dhcpd.leases",
|
||||
default => "/var/lib/dhcpd/dhcpd.leases",
|
||||
},
|
||||
ensure => present,
|
||||
owner => root,
|
||||
group => $operatingsystem ? {
|
||||
OpenBSD => wheel,
|
||||
default => root,
|
||||
},
|
||||
require => Package["dhcp"],
|
||||
before => Service["dhcpd"],
|
||||
}
|
||||
|
||||
service { "dhcpd":
|
||||
ensure => running,
|
||||
enable => true,
|
||||
require => Package["dhcp"],
|
||||
}
|
||||
case $operatingsystem {
|
||||
OpenBSD: {
|
||||
Service["dhcpd"] {
|
||||
name => "isc-dhcpd",
|
||||
binary => "/usr/local/sbin/dhcpd",
|
||||
start => "/usr/local/sbin/dhcpd > /dev/null",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exec { "generate-dhcp-conf":
|
||||
path => "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin",
|
||||
command => "dhcpdump.py /etc/dhcpd.conf.in* > /etc/dhcpd.conf",
|
||||
onlyif => "! dhcpdump.py /etc/dhcpd.conf.in* | diff /etc/dhcpd.conf -",
|
||||
require => [ File["/etc/dhcpd.conf.in"],
|
||||
File["/usr/local/sbin/dhcpdump.py"], ],
|
||||
notify => Service["dhcpd"],
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue