1 from pecan import expose, request, response
2 from pecan.rest import RestController
4 from restful import common, module
5 from restful.decorators import auth
8 class OsdIdCommand(RestController):
9 def __init__(self, osd_id):
13 @expose(template='json')
15 def get(self, **kwargs):
17 Show implemented commands for the OSD id
19 osd = module.instance.get_osd_by_id(self.osd_id)
23 return {'message': 'Failed to identify the OSD id "%d"' % self.osd_id}
26 return common.OSD_IMPLEMENTED_COMMANDS
31 @expose(template='json')
33 def post(self, **kwargs):
35 Run the implemented command for the OSD id
37 command = request.json.get('command', None)
39 osd = module.instance.get_osd_by_id(self.osd_id)
43 return {'message': 'Failed to identify the OSD id "%d"' % self.osd_id}
45 if not osd['up'] or command not in common.OSD_IMPLEMENTED_COMMANDS:
47 return {'message': 'Command "%s" not available' % command}
49 return module.instance.submit_request([[{
50 'prefix': 'osd ' + command,
51 'who': str(self.osd_id)
56 class OsdId(RestController):
57 def __init__(self, osd_id):
59 self.command = OsdIdCommand(osd_id)
62 @expose(template='json')
64 def get(self, **kwargs):
66 Show the information for the OSD id
68 osd = module.instance.get_osds(ids=[str(self.osd_id)])
71 return {'message': 'Failed to identify the OSD id "%d"' % self.osd_id}
76 @expose(template='json')
78 def patch(self, **kwargs):
80 Modify the state (up, in) of the OSD id or reweight it
90 'ids': [str(self.osd_id)]
95 'ids': [str(self.osd_id)]
100 response.status = 500
101 return {'message': "It is not valid to set a down OSD to be up"}
104 'prefix': 'osd down',
105 'ids': [str(self.osd_id)]
108 if 'reweight' in args:
110 'prefix': 'osd reweight',
112 'weight': args['reweight']
115 return module.instance.submit_request([commands], **kwargs)
119 class Osd(RestController):
120 @expose(template='json')
122 def get(self, **kwargs):
124 Show the information for all the OSDs
128 pool_id = kwargs.get('pool', None)
130 return module.instance.get_osds(pool_id)
134 def _lookup(self, osd_id, *remainder):
135 return OsdId(int(osd_id)), remainder