summaryrefslogtreecommitdiffstats
path: root/src/sbin/bcfg2-server
blob: 1c28d97f641feae8ce4f4dcdaeb78fea017aef16 (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
40
41
42
43
44
#!/usr/bin/env python

"""The XML-RPC Bcfg2 server."""

import sys
import logging
import Bcfg2.Options
from Bcfg2.Server.Core import CoreInitError


class BackendAction(Bcfg2.Options.ComponentAction):
    islist = False
    bases = ['Bcfg2.Server']


class CLI(object):
    options = [Bcfg2.Options.Option(
            cf=('server', 'backend'), help='Server Backend',
            default='Builtin', type=lambda b: b.title() + "Core",
            action=BackendAction)]

    def __init__(self):
        parser = Bcfg2.Options.get_parser("Bcfg2 server", components=[self])
        parser.parse()
        self.logger = logging.getLogger(parser.prog)

    def run(self):
        try:
            core = Bcfg2.Options.setup.backend()
            core.run()
        except CoreInitError:
            self.logger.error(sys.exc_info()[1])
            return 1
        except TypeError:
            self.logger.error("Failed to load %s server backend: %s" %
                              (Bcfg2.Options.setup.backend.__name__,
                               sys.exc_info()[1]))
            raise
        except KeyboardInterrupt:
            return 1


if __name__ == '__main__':
    sys.exit(CLI().run())