backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / operator / commands / show / count.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_ERROR
6 from ryu.services.protocols.bgp.operator.command import STATUS_OK
7 from ryu.services.protocols.bgp.operator.commands.responses import \
8     WrongParamResp
9
10 LOG = logging.getLogger('bgpspeaker.operator.commands.show.count')
11
12
13 class Count(Command):
14     help_msg = 'show counters'
15     param_help_msg = '<vpn-name> <route-family>{ipv4, ipv6}'
16     command = 'count'
17     cli_resp_line_template = 'BGP route count for VPN {0} is {1}\n'
18
19     def __init__(self, *args, **kwargs):
20         super(Count, self).__init__(*args, **kwargs)
21         self.subcommands = {
22             'all': self.All
23         }
24
25     def action(self, params):
26         if len(params) < 1:
27             return CommandsResponse(STATUS_ERROR, 'Not enough params')
28         else:
29             vrf_name = params[0]
30             if len(params) == 2:
31                 vrf_rf = params[1]
32             else:
33                 vrf_rf = 'ipv4'
34
35             from ryu.services.protocols.bgp.operator.internal_api import \
36                 WrongParamError
37             try:
38                 return CommandsResponse(
39                     STATUS_OK,
40                     self.api.count_single_vrf_routes(vrf_name, vrf_rf)
41                 )
42             except WrongParamError as e:
43                 return WrongParamResp(e)
44
45     class All(Command):
46         help_msg = 'shows number of routes for all VRFs'
47         command = 'all'
48         cli_resp_line_template = 'BGP route count for VPN {0} is {1}\n'
49
50         def action(self, params):
51             if len(params) > 0:
52                 return WrongParamResp()
53             return CommandsResponse(STATUS_OK, self.api.count_all_vrf_routes())