backing up
[vsorcdistro/.git] / ryu / build / lib.linux-armv7l-2.7 / ryu / services / protocols / bgp / operator / commands / show / importmap.py
1 from ryu.services.protocols.bgp.operator.command import Command
2 from ryu.services.protocols.bgp.operator.command import CommandsResponse
3 from ryu.services.protocols.bgp.operator.command import STATUS_ERROR
4 from ryu.services.protocols.bgp.operator.command import STATUS_OK
5 from ryu.services.protocols.bgp.operator.commands.responses import \
6     WrongParamResp
7
8 from ryu.services.protocols.bgp.operator.views.bgp import CoreServiceDetailView
9
10
11 class Importmap(Command):
12     help_msg = 'show importmaps'
13     param_help_msg = 'all | <name>'
14     command = 'importmap'
15
16     def __init__(self, *args, **kwargs):
17         super(Importmap, self).__init__(*args, **kwargs)
18
19     def action(self, params):
20         if len(params) != 1:
21             return WrongParamResp()
22
23         core_service = self.api.get_core_service()
24         core_service_view = CoreServiceDetailView(core_service)
25         importmap_manager = core_service_view.rel('importmap_manager')
26         importmaps_view = importmap_manager.rel('importmaps')
27
28         importmap_name = params[0]
29         if importmap_name == 'all':
30             encoded = importmaps_view.encode()
31         else:
32             encoded = importmaps_view.encode().get(importmap_name)
33             if encoded is None:
34                 return CommandsResponse(
35                     STATUS_ERROR,
36                     'Wrong importmap name.'
37                 )
38
39         return CommandsResponse(
40             STATUS_OK,
41             encoded
42         )