From: John Spray Date: Tue, 4 Oct 2016 13:49:16 +0000 (+0100) Subject: pybind: clean up mgr stuff for flake8 X-Git-Tag: v11.1.0~483^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c6a7d48fc951b4be4c5cbc28a839f949f42774ef;p=ceph.git pybind: clean up mgr stuff for flake8 Signed-off-by: John Spray --- diff --git a/src/pybind/mgr/fsstatus/__init__.py b/src/pybind/mgr/fsstatus/__init__.py index bd1113bf1b24..79f5b86fd504 100644 --- a/src/pybind/mgr/fsstatus/__init__.py +++ b/src/pybind/mgr/fsstatus/__init__.py @@ -1,2 +1,2 @@ -from module import * +from module import * # NOQA diff --git a/src/pybind/mgr/fsstatus/module.py b/src/pybind/mgr/fsstatus/module.py index f9bc0d87109f..f137a5466b0b 100644 --- a/src/pybind/mgr/fsstatus/module.py +++ b/src/pybind/mgr/fsstatus/module.py @@ -1,12 +1,9 @@ """ -High level status display for CephFS +High level status display commands """ -from collections import defaultdict -import logging -import logging.config -import json +from collections import defaultdict from prettytable import PrettyTable import prettytable @@ -242,7 +239,6 @@ class Module(MgrModule): osdmap = self.get("osd_map") # Build dict of OSD ID to stats - #return 0, "", json.dumps(self.get("osd_stats")) osd_stats = dict([(o['osd'], o) for o in self.get("osd_stats")['osd_stats']]) for osd in osdmap['osds']: diff --git a/src/pybind/mgr/rest/__init__.py b/src/pybind/mgr/rest/__init__.py index 622a611b6099..e87777b46fe8 100644 --- a/src/pybind/mgr/rest/__init__.py +++ b/src/pybind/mgr/rest/__init__.py @@ -1,3 +1,3 @@ -from module import * +from module import * # NOQA diff --git a/src/pybind/mgr/rest/app/management/commands/api_docs.py b/src/pybind/mgr/rest/app/management/commands/api_docs.py index 398732bb6795..6d36d9646c18 100644 --- a/src/pybind/mgr/rest/app/management/commands/api_docs.py +++ b/src/pybind/mgr/rest/app/management/commands/api_docs.py @@ -33,7 +33,7 @@ class ceph_state: sys.modules["ceph_state"] = ceph_state # Needed to avoid weird import loops -from rest.module import global_instance +from rest.module import global_instance # NOQA from rest.app.serializers.v2 import ValidatingSerializer diff --git a/src/pybind/mgr/rest/app/serializers/v2.py b/src/pybind/mgr/rest/app/serializers/v2.py index dc9cf65f7e5d..d1fa7869ec71 100644 --- a/src/pybind/mgr/rest/app/serializers/v2.py +++ b/src/pybind/mgr/rest/app/serializers/v2.py @@ -6,7 +6,7 @@ from rest_framework import serializers import rest.app.serializers.fields as fields from rest.app.types import CRUSH_RULE_TYPE_REPLICATED, \ CRUSH_RULE_TYPE_ERASURE, USER_REQUEST_COMPLETE, \ - USER_REQUEST_SUBMITTED, OSD_FLAGS, severity_str, SEVERITIES + USER_REQUEST_SUBMITTED, OSD_FLAGS class ValidatingSerializer(serializers.Serializer): diff --git a/src/pybind/mgr/rest/app/views/exceptions.py b/src/pybind/mgr/rest/app/views/exceptions.py deleted file mode 100644 index 9279d2c383fc..000000000000 --- a/src/pybind/mgr/rest/app/views/exceptions.py +++ /dev/null @@ -1,13 +0,0 @@ - -""" -Convenience classes for raising HTTP status codes as exceptions, -in addition to rest_framework's builtin exception classes -""" - -from rest_framework import status -from rest_framework.exceptions import APIException - - -class ServiceUnavailable(APIException): - status_code = status.HTTP_503_SERVICE_UNAVAILABLE - default_detail = "Service unavailable" diff --git a/src/pybind/mgr/rest/app/views/rpc_view.py b/src/pybind/mgr/rest/app/views/rpc_view.py index 0bceef6a974e..82cd263f946d 100644 --- a/src/pybind/mgr/rest/app/views/rpc_view.py +++ b/src/pybind/mgr/rest/app/views/rpc_view.py @@ -2,21 +2,18 @@ """ Helpers for writing django views and rest_framework ViewSets that get -their data from cthulhu with zeroRPC +their data from calls into the C++ side of ceph-mgr """ -from rest.app.manager.osd_request_factory import OsdRequestFactory -from rest.app.manager.pool_request_factory import PoolRequestFactory - from rest_framework import viewsets, status from rest_framework.views import APIView from rest_framework.response import Response -from rest.app.types import OsdMap, SYNC_OBJECT_STR_TYPE, OSD, OSD_MAP, POOL, CLUSTER, CRUSH_RULE, ServiceId,\ - NotFound, SERVER - +from rest.app.manager.osd_request_factory import OsdRequestFactory +from rest.app.manager.pool_request_factory import PoolRequestFactory +from rest.app.types import OsdMap, OSD, OSD_MAP, POOL, CRUSH_RULE, NotFound from rest.module import global_instance as rest_plugin from rest.logger import logger @@ -203,7 +200,6 @@ class MgrClient(object): Create and submit UserRequest for an apply, create, update or delete. """ - # nosleep during preparation phase (may touch ClusterMonitor/ServerMonitor state) request_factory = self.get_request_factory(obj_type) request = getattr(request_factory, method)(*args, **kwargs) @@ -232,7 +228,7 @@ class IsRoleAllowed(BasePermission): return True # TODO: reinstate read vs. read/write limitations on API keys - has_permission = False + # has_permission = False # if request.user.groups.filter(name='readonly').exists(): # has_permission = request.method in SAFE_METHODS # view.headers['Allow'] = ', '.join(SAFE_METHODS) @@ -243,6 +239,7 @@ class IsRoleAllowed(BasePermission): # # return has_permission + class RPCView(APIView): serializer_class = None log = log diff --git a/src/pybind/mgr/rest/app/views/v2.py b/src/pybind/mgr/rest/app/views/v2.py index 7c588efdbbf4..b69682c4490a 100644 --- a/src/pybind/mgr/rest/app/views/v2.py +++ b/src/pybind/mgr/rest/app/views/v2.py @@ -1,34 +1,26 @@ from collections import defaultdict -import json -import logging -import shlex from distutils.version import StrictVersion from django.http import Http404 import rest_framework -from rest_framework.exceptions import ParseError, APIException, PermissionDenied +from rest_framework.exceptions import ParseError from rest_framework.response import Response -from rest_framework.decorators import api_view -from rest_framework import status -from django.contrib.auth.decorators import login_required +from rest_framework import status from rest.app.serializers.v2 import PoolSerializer, CrushRuleSetSerializer, \ CrushRuleSerializer, ServerSerializer, RequestSerializer, OsdSerializer, \ ConfigSettingSerializer, MonSerializer, OsdConfigSerializer -from rest.app.views.exceptions import ServiceUnavailable from rest.app.views.rpc_view import RPCViewSet, DataObject from rest.app.types import CRUSH_RULE, POOL, OSD, USER_REQUEST_COMPLETE, \ - USER_REQUEST_SUBMITTED, OSD_IMPLEMENTED_COMMANDS, MON, OSD_MAP, \ - SYNC_OBJECT_TYPES, ServiceId, severity_from_str, SEVERITIES, \ - OsdMap, Config, MonMap, MonStatus, SYNC_OBJECT_STR_TYPE + USER_REQUEST_SUBMITTED, OSD_IMPLEMENTED_COMMANDS, OSD_MAP, \ + SYNC_OBJECT_TYPES, OsdMap, Config, MonMap, MonStatus, SYNC_OBJECT_STR_TYPE from rest.logger import logger log = logger() -#class RequestViewSet(RPCViewSet, PaginatedMixin): class RequestViewSet(RPCViewSet): """ Calamari server requests, tracking long-running operations on the Calamari server. Some @@ -398,10 +390,9 @@ Filtering is available on this resource: osd_metadata = self.client.get_sync_object(OsdMap, ['osd_metadata']) osd_id_to_hostname = dict( - [(int(osd_id), osd_meta["hostname"]) for osd_id, osd_meta in + [(int(oid), osd_meta["hostname"]) for oid, osd_meta in osd_metadata.items()]) - osd['server'] = osd_id_to_hostname.get(osd['osd'], None) pools = self.client.get_sync_object(OsdMap, ['osd_pools', int(osd_id)]) diff --git a/src/pybind/mgr/rest/module.py b/src/pybind/mgr/rest/module.py index e3d5ed36e7fe..f72b7ce30e4b 100644 --- a/src/pybind/mgr/rest/module.py +++ b/src/pybind/mgr/rest/module.py @@ -144,7 +144,7 @@ class Module(MgrModule): obj = obj[part] else: obj = getattr(obj, part) - except (AttributeError, KeyError) as e: + except (AttributeError, KeyError): raise NotFound(object_type, path) return obj