Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nautilus: mgr: Update the restful module in nautilus #28291

Merged
merged 3 commits into from
Jun 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions qa/workunits/rest/test_mgr_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@
('get', '/request?page=0', {}),
('delete', '/request', {}),
('get', '/request', {}),
('patch', '/pool/1', {'pg_num': 128}),
('patch', '/pool/1', {'pgp_num': 128}),
('patch', '/pool/1', {'pg_num': 128}),
('patch', '/pool/1', {'pgp_num': 128}),
('get', '/perf?daemon=.*', {}),
]

for method, endpoint, args in screenplay:
Expand Down
2 changes: 2 additions & 0 deletions src/pybind/mgr/restful/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .mon import Mon
from .osd import Osd
from .pool import Pool
from .perf import Perf
from .request import Request
from .server import Server

Expand All @@ -17,6 +18,7 @@ class Root(RestController):
doc = Doc()
mon = Mon()
osd = Osd()
perf = Perf()
pool = Pool()
request = Request()
server = Server()
Expand Down
8 changes: 2 additions & 6 deletions src/pybind/mgr/restful/api/mon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@ def get(self, **kwargs):
"""
Show the information for the monitor name
"""
mon = filter(
lambda x: x['name'] == self.name,
context.instance.get_mons()
)

mon = [x for x in context.instance.get_mons()
if x['name'] == self.name]
if len(mon) != 1:
response.status = 500
return {'message': 'Failed to identify the monitor node "{}"'.format(self.name)}

return mon[0]


Expand Down
27 changes: 27 additions & 0 deletions src/pybind/mgr/restful/api/perf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from pecan import expose, request, response
from pecan.rest import RestController

from restful import context
from restful.decorators import auth, lock, paginate

import re

class Perf(RestController):
@expose(template='json')
@paginate
@auth
def get(self, **kwargs):
"""
List all the available performance counters

Options:
- 'daemon' -- filter by daemon, accepts Python regexp
"""

counters = context.instance.get_all_perf_counters()

if 'daemon' in kwargs:
_re = re.compile(kwargs['daemon'])
counters = {k: v for k, v in counters.items() if _re.match(k)}

return counters
23 changes: 8 additions & 15 deletions src/pybind/mgr/restful/api/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@ def get(self, **kwargs):
"""
Show the information for the request id
"""
request = filter(
lambda x: x.id == self.request_id,
context.instance.requests
)

request = [x for x in context.instance.requests
if x.id == self.request_id]
if len(request) != 1:
response.status = 500
return {'message': 'Unknown request id "{}"'.format(self.request_id)}

request = request[0]
return request
return request[0]


@expose(template='json')
Expand Down Expand Up @@ -66,15 +61,13 @@ def delete(self, **kwargs):
"""
num_requests = len(context.instance.requests)

context.instance.requests = filter(
lambda x: not x.is_finished(),
context.instance.requests
)

context.instance.requests = [x for x in context.instance.requests
if not x.is_finished()]
remaining = len(context.instance.requests)
# Return the job statistics
return {
'cleaned': num_requests - len(context.instance.requests),
'remaining': len(context.instance.requests),
'cleaned': num_requests - remaining,
'remaining': remaining,
}


Expand Down
6 changes: 3 additions & 3 deletions src/pybind/mgr/restful/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,16 @@ def run(self, commands):

# Gather the results (in parallel)
results = []
for index in range(len(commands)):
for index, command in enumerate(commands):
tag = '%s:%s:%d' % (__name__, self.id, index)

# Store the result
result = CommandResult(tag)
result.command = common.humanify_command(commands[index])
result.command = common.humanify_command(command)
results.append(result)

# Run the command
context.instance.send_command(result, 'mon', '', json.dumps(commands[index]), tag)
context.instance.send_command(result, 'mon', '', json.dumps(command), tag)

return results

Expand Down