X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fpybind%2Fmgr%2Frestful%2Fapi%2Fosd.py;fp=src%2Fceph%2Fsrc%2Fpybind%2Fmgr%2Frestful%2Fapi%2Fosd.py;h=0000000000000000000000000000000000000000;hb=7da45d65be36d36b880cc55c5036e96c24b53f00;hp=b42f33941f1c312b93f9e389834f257b163b1f1d;hpb=691462d09d0987b47e112d6ee8740375df3c51b2;p=stor4nfv.git diff --git a/src/ceph/src/pybind/mgr/restful/api/osd.py b/src/ceph/src/pybind/mgr/restful/api/osd.py deleted file mode 100644 index b42f339..0000000 --- a/src/ceph/src/pybind/mgr/restful/api/osd.py +++ /dev/null @@ -1,135 +0,0 @@ -from pecan import expose, request, response -from pecan.rest import RestController - -from restful import common, module -from restful.decorators import auth - - -class OsdIdCommand(RestController): - def __init__(self, osd_id): - self.osd_id = osd_id - - - @expose(template='json') - @auth - def get(self, **kwargs): - """ - Show implemented commands for the OSD id - """ - osd = module.instance.get_osd_by_id(self.osd_id) - - if not osd: - response.status = 500 - return {'message': 'Failed to identify the OSD id "%d"' % self.osd_id} - - if osd['up']: - return common.OSD_IMPLEMENTED_COMMANDS - else: - return [] - - - @expose(template='json') - @auth - def post(self, **kwargs): - """ - Run the implemented command for the OSD id - """ - command = request.json.get('command', None) - - osd = module.instance.get_osd_by_id(self.osd_id) - - if not osd: - response.status = 500 - return {'message': 'Failed to identify the OSD id "%d"' % self.osd_id} - - if not osd['up'] or command not in common.OSD_IMPLEMENTED_COMMANDS: - response.status = 500 - return {'message': 'Command "%s" not available' % command} - - return module.instance.submit_request([[{ - 'prefix': 'osd ' + command, - 'who': str(self.osd_id) - }]], **kwargs) - - - -class OsdId(RestController): - def __init__(self, osd_id): - self.osd_id = osd_id - self.command = OsdIdCommand(osd_id) - - - @expose(template='json') - @auth - def get(self, **kwargs): - """ - Show the information for the OSD id - """ - osd = module.instance.get_osds(ids=[str(self.osd_id)]) - if len(osd) != 1: - response.status = 500 - return {'message': 'Failed to identify the OSD id "%d"' % self.osd_id} - - return osd[0] - - - @expose(template='json') - @auth - def patch(self, **kwargs): - """ - Modify the state (up, in) of the OSD id or reweight it - """ - args = request.json - - commands = [] - - if 'in' in args: - if args['in']: - commands.append({ - 'prefix': 'osd in', - 'ids': [str(self.osd_id)] - }) - else: - commands.append({ - 'prefix': 'osd out', - 'ids': [str(self.osd_id)] - }) - - if 'up' in args: - if args['up']: - response.status = 500 - return {'message': "It is not valid to set a down OSD to be up"} - else: - commands.append({ - 'prefix': 'osd down', - 'ids': [str(self.osd_id)] - }) - - if 'reweight' in args: - commands.append({ - 'prefix': 'osd reweight', - 'id': self.osd_id, - 'weight': args['reweight'] - }) - - return module.instance.submit_request([commands], **kwargs) - - - -class Osd(RestController): - @expose(template='json') - @auth - def get(self, **kwargs): - """ - Show the information for all the OSDs - """ - # Parse request args - # TODO Filter by ids - pool_id = kwargs.get('pool', None) - - return module.instance.get_osds(pool_id) - - - @expose() - def _lookup(self, osd_id, *remainder): - return OsdId(int(osd_id)), remainder