crans_bcfg2/Python/etc/network/interfaces
Pierre-Elliott Bécue d10a8a0672 [Bcfg2] Nouveau paquet, nouvelle config
Ignore-this: 67cdee8f32d7581493d12617ddc97bc2
Bcfg2 a subi deux releases, qui ont pas mal changé les "normes".

Les balises suivntes sont remplacées :

<ConfigFile> ---------------------------> <Path type="file">
<Directory>  ---------------------------> <Path type="directory">
<SymLink>    ---------------------------> <Path type="symlink">
etc

Pour les fichiers python, désormais, on utilise plus
<ConfigFile>, mais <Python>

darcs-hash:20121211100127-b6762-f146f4460e9713cb59a25c33a08b551c5280f3b2.gz
2012-12-11 11:01:27 +01:00

184 lines
5.4 KiB
Python

# -*- coding: utf-8; mode: python -*-
include("ip")
include("arpwatch")
info["owner"] = "root"
info["group"] = "root"
info["perms"] = 0644
header("""
Les modifications locales sont a mettre dans le fichier /etc/network/interfaces.local
Voir http://wiki.crans.org/CransTechnique/Bcfg2/... pour plus d'explications.
""")
configured_ifaces=[]
def dev(interface, mode, additionnals=[]):
"""Generation de la conf d'une interface:
- additionnals contient des lignes a mettre en plus a la definition"""
configured_ifaces.append(interface)
if mode == "pub":
print """auto %(interface)s
iface %(interface)s inet static
address %(ip)s
network 138.231.136.0
netmask 255.255.248.0
broadcast 138.231.143.255
gateway 138.231.136.4
dns-nameservers 138.231.136.98 138.231.136.9
dns-search crans.org""" % { 'interface': interface, 'ip': pubip() }
if not has('vlan-wifi'):
print """ post-up ip r add 138.231.144.0/21 dev %(interface)s via 138.231.136.247 src %(ip)s""" % { 'interface': interface, 'ip': pubip() }
for line in additionnals:
print " ", line
print
pub6(interface)
elif mode == "wifi":
print """auto %(interface)s
iface %(interface)s inet static
address %(ip)s
network 138.231.144.0
netmask 255.255.248.0
broadcast 138.231.148.255
dns-nameservers 138.231.148.1
dns-search wifi.crans.org""" % { 'interface': interface, 'ip': wifiip() }
for line in additionnals:
print " ", line
print
elif mode == "adm":
print """auto %(interface)s
iface %(interface)s inet static
address %(ip)s
network 10.231.136.0
netmask 255.255.255.0
broadcast 10.231.136.255
mtu 1496
dns-nameservers 10.231.136.98 138.231.136.9
dns-search adm.crans.org""" % { 'interface': interface, 'ip': admip() }
for line in additionnals:
print " ", line
print
adm6(interface)
elif mode == "radin":
print """auto %(interface)s
iface %(interface)s inet static
address %(ip)s
network 10.42.0.0
netmask 255.255.0.0
broadcast 10.42.255.255
mtu 1496""" % { 'interface': interface, 'ip': radinip() }
elif mode == "accueil":
print """auto %(interface)s
iface %(interface)s inet static
address %(ip)s
network 10.51.0.0
netmask 255.255.0.0
broadcast 10.51.255.255
mtu 1496""" % { 'interface': interface, 'ip': accueilip() }
elif mode == "ens":
print """auto %(interface)s
iface %(interface)s inet static
address %(ip)s
network 10.2.9.0
netmask 255.255.255.0
broadcast 10.2.9.255
mtu 1496""" % { 'interface': interface, 'ip': appt_ens_ip() }
elif mode == "isolement":
print """auto %(interface)s
iface %(interface)s inet static
address %(ip)s
network 10.52.0.0
netmask 255.255.0.0
broadcast 10.52.255.255
mtu 1496""" % { 'interface': interface, 'ip': isolementip() }
elif mode == "manuel":
print """auto %(interface)s
iface %(interface)s inet static""" % { 'interface': interface }
elif mode == "vide":
try:
iface, vlan = interface.split('.')
except ValueError:
vlan = None
if vlan:
print """auto %(interface)s
iface %(interface)s inet manual
pre-up vconfig add %(iface)s %(vlan)s
post-down vconfig rem %(iface)s.%(vlan)s
up ip l set %(interface)s up
down ip l set %(interface)s down""" % { 'interface': interface, 'iface':iface,'vlan':vlan }
else:
print """auto %(interface)s
iface %(interface)s inet manual
up ip l set %(interface)s up
down ip l set %(interface)s down""" % { 'interface': interface }
else:
raise NotImplementedError, "Mode de reseau inconnu : %s" % mode
if mode != "pub" and mode != "adm":
for line in additionnals:
print " ", line
print
# Definitions communes
print """auto lo
iface lo inet loopback
"""
# Pour arpwatch, on surveille nos réseaux
def otherlisteners():
print "#Interfaces d'ecoute restantes pour arpwatch "
for vlan in watched_vlans:
if vlan == 1:
iface = 'eth0'
else:
iface = 'eth0.%d' % vlan
if not iface in configured_ifaces:
dev(iface,'vide')
def pubip6(If):
return "2a01:240:fe3d:4:" + If_Mac[If]
def admip6(If):
return "2a01:240:fe3d:c804:" + If_Mac[If]
def pub6(interface, mode = 'serveur'):
""" fonction permettant d'ajouter une adressse ipv6 a l'interface donnee en argument.
Le mode permet de faire la distinction entre les simples serveurs et les routeurs.
En effet, il est assez peu fortuit de rajouter une route par defaut qui va faire une boucle."""
print """iface %(interface)s inet6 static
address %(ip6)s
netmask 64""" % { 'interface': interface, 'ip6': pubip6(interface) }
if mode == 'serveur':
print ' gateway fe80::219:bbff:fe31:3b80'
elif mode == 'routeur':
print ' up ip r add dev %s 2a01:240:fe3d:f7::/64 via 2a01:240:fe3d:4:20f:1fff:fe66:e0e8' % interface
print
def adm6(interface):
print """iface %(interface)s inet6 static
address %(ip6)s
netmask 64""" % { 'interface': interface, 'ip6': admip6(interface) }
print
Probe_Mac = metadata.Probes["mac"].split('\n')
If_Mac = dict(zip(Probe_Mac[:-1:2], Probe_Mac[1::2]))
exec(str(metadata.Probes["interfaces_local"]))