backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / operator / commands / set.py
1 import logging
2
3 from ryu.services.protocols.bgp.operator.command import Command
4 from ryu.services.protocols.bgp.operator.command import CommandsResponse
5 from ryu.services.protocols.bgp.operator.command import STATUS_OK
6 from ryu.services.protocols.bgp.operator.command import STATUS_ERROR
7 from ryu.services.protocols.bgp.operator.commands.responses import \
8     WrongParamResp
9
10
11 class LoggingCmd(Command):
12     command = 'logging'
13     help_msg = 'turn on/off logging at current level'
14
15     def __init__(self, *args, **kwargs):
16         super(LoggingCmd, self).__init__(*args, **kwargs)
17         self.subcommands = {
18             'on': self.On,
19             'off': self.Off,
20             'level': self.Level
21         }
22
23     def action(self, params):
24         return CommandsResponse(STATUS_ERROR, 'Command incomplete')
25
26     class On(Command):
27         command = 'on'
28         help_msg = 'turn-on the logging at the current level'
29
30         def action(self, params):
31             logging.getLogger('bgpspeaker').addHandler(self.api.log_handler)
32             return CommandsResponse(STATUS_OK, True)
33
34     class Off(Command):
35         command = 'off'
36         help_msg = 'turn-off the logging'
37
38         def action(self, params):
39             logging.getLogger('bgpspeaker').removeHandler(self.api.log_handler)
40             return CommandsResponse(STATUS_OK, True)
41
42     class Level(Command):
43         command = 'level'
44         help_msg = 'set logging level'
45         param_help_msg = '[debug/info/error]'
46
47         def action(self, params):
48             lvls = {
49                 'debug': logging.DEBUG,
50                 'error': logging.ERROR,
51                 'info': logging.INFO
52             }
53             if len(params) == 1 and params[0] in lvls:
54                 self.api.log_handler.setLevel(
55                     lvls.get(params[0], logging.ERROR)
56                 )
57                 return CommandsResponse(STATUS_OK, True)
58             else:
59                 return WrongParamResp()
60
61
62 class SetCmd(Command):
63     help_msg = 'set runtime settings'
64     command = 'set'
65
66     subcommands = {'logging': LoggingCmd}
67
68     def action(self, params):
69         return CommandsResponse(STATUS_ERROR, 'Command incomplete')