crans_bcfg2/etc/python/common.py
Pierre-Elliott Bécue a5fe3a1778 Admonly remplacé par nonadherent, et ajout de vlan-wif par endroits
Ignore-this: 3bf49fca4dca8c61aa0eb0dc0128e65a
Une machine qui n'est pas sur vlan adhérent peut être sur d'autres vlans, on remplace adm-only par non-vlan-adherent.

On ajoute aussi des trucs pour les machines sur le vlan-wifi.

darcs-hash:20130117223022-afe24-5191157757322bc0718b6b564f4c7ceea86438e5.gz
2013-01-17 23:30:22 +01:00

81 lines
2.1 KiB
Python

# -*- coding: utf-8 -*-
#
# common.py
# ---------
#
# Copyright (C) 2007 Jeremie Dimino <jeremie@dimino.org>
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
'''Fichier inclu par tous les scripts du plugin Python de bcfg2'''
import sys
sys.path.append('/usr/scripts/gestion')
def comment(line):
'''Ecrit un commentaire'''
out(comment_start + " " + line + "\n")
emacs_mode = "conf-unix"
def header(desc=None, mode=None):
'''Ecrit une en-tete de fichier avec un commentaire'''
comment("-*- mode: %s; coding: utf-8 -*-" % (mode or emacs_mode))
comment("")
comment("Fichier gere par BCfg2 (avec le plugin Python)")
comment("")
if desc:
lines = desc.split('\n')
if lines[-1] == "":
lines.pop()
for line in lines:
comment(line)
out("\n")
def var(name, value, doc=None):
'''Ecrit la definition d'une variable'''
if doc: comment(doc)
out("%s = %s\n" % (name, value))
# Le nom d'hote court, la partie avant le premier '.'
hostname = metadata.hostname.split('.',1)[0]
# Le nom d'hote sur le vlan public
pubhostname = hostname + ".crans.org"
# Le nom d'hote sur le vlan adm
admhostname = hostname + ".adm.crans.org"
# Le nom d'hôte sur le vlan wifi
wifihostname = hostname + ".wifi.crans.org"
def has(group):
return group in metadata.groups
def yesno(b):
if b:
return "yes"
else:
return "no"
def onoff(b):
if b:
return "on"
else:
return "off"
def outl(line):
out(line)
out("\n")