]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/restful/api/osd.py
1 from pecan
import expose
, request
, response
2 from pecan
.rest
import RestController
4 from restful
import common
, context
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
= context
.instance
.get_osd_by_id(self
.osd_id
)
23 return {'message': 'Failed to identify the OSD id "{}"'.format(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
= context
.instance
.get_osd_by_id(self
.osd_id
)
43 return {'message': 'Failed to identify the OSD id "{}"'.format(self
.osd_id
)}
45 if not osd
['up'] or command
not in common
.OSD_IMPLEMENTED_COMMANDS
:
47 return {'message': 'Command "{}" not available'.format(command
)}
49 return context
.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
= context
.instance
.get_osds(ids
=[str(self
.osd_id
)])
71 return {'message': 'Failed to identify the OSD id "{}"'.format(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 context
.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 context
.instance
.get_osds(pool_id
)
134 def _lookup(self
, osd_id
, *remainder
):
135 return OsdId(int(osd_id
)), remainder