summaryrefslogtreecommitdiffstats
path: root/src/lib/Server/Plugins/POSIXCompat.py
blob: d2e5304072f3edaf75424710fa82b36761e7eca3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'''
   This plugin provides a compatibility layer which turns new-style
   POSIX entries into old-style entries.
'''
__revision__ = '$Revision$'

import Bcfg2.Server.Plugin

# FIXME: We will need this mapping if we decide to change the
#        specification to use lowercase types for new POSIX entry types
COMPAT_DICT = {'configfile': 'ConfigFile',
               'device': 'device',
               'directory': 'Directory',
               'nonexistent': 'nonexistent',
               'permissions': 'Permissions',
               'symlink': 'SymLink'}

class POSIXCompat(Bcfg2.Server.Plugin.Plugin,
             Bcfg2.Server.Plugin.GoalValidator):
    name = 'POSIXCompat'
    __version__ = '$Id$'
    __author__ = 'bcfg-dev@mcs.anl.gov'

    def __init__(self, core, datastore):
        Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore)
        Bcfg2.Server.Plugin.GoalValidator.__init__(self)

    def validate_goals(self, metadata, goals):
        for goal in goals:
            for entry in goal.getchildren():
                if entry.tag == 'Path' and \
                   entry.get('type') not in ['nonexistent', 'device']:
                    oldentry = entry
                    entry.tag = COMPAT_DICT[entry.get('type')]
                    del entry.attrib['type']
                    # FIXME: use another attribute? old clients only
                    #        know about type=None
                    #entry.set('type', 'POSIXCompat')
                    goal.replace(oldentry, entry)