Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / pybind / mgr / restful / api / mon.py
1 from pecan import expose, response
2 from pecan.rest import RestController
3
4 from restful import module
5 from restful.decorators import auth
6
7
8 class MonName(RestController):
9     def __init__(self, name):
10         self.name = name
11
12
13     @expose(template='json')
14     @auth
15     def get(self, **kwargs):
16         """
17         Show the information for the monitor name
18         """
19         mon = filter(
20             lambda x: x['name'] == self.name,
21             module.instance.get_mons()
22         )
23
24         if len(mon) != 1:
25             response.status = 500
26             return {'message': 'Failed to identify the monitor node "%s"' % self.name}
27
28         return mon[0]
29
30
31
32 class Mon(RestController):
33     @expose(template='json')
34     @auth
35     def get(self, **kwargs):
36         """
37         Show the information for all the monitors
38         """
39         return module.instance.get_mons()
40
41
42     @expose()
43     def _lookup(self, name, *remainder):
44         return MonName(name), remainder