]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: Refactor RGW backend 21784/head
authorVolker Theile <vtheile@suse.com>
Wed, 2 May 2018 15:33:24 +0000 (17:33 +0200)
committerVolker Theile <vtheile@suse.com>
Mon, 7 May 2018 09:58:25 +0000 (11:58 +0200)
- Do some polishing in the docs.
- Refactor RgwClient::is_service_online() method. The system is considered as online if the response structure is valid. The response content itself is not validated in this case.
- Relocate NoCredentialsException and derive it from RequestException.

Signed-off-by: Volker Theile <vtheile@suse.com>
doc/mgr/dashboard.rst
src/pybind/mgr/dashboard/exceptions.py
src/pybind/mgr/dashboard/services/rgw_client.py

index 74ee63f9182f609baf3d8564815be843769ac1b6..6c4856b538e936c159afc7b68b3a870f3669919f 100644 (file)
@@ -147,7 +147,7 @@ enabled.
 If you do not have a user which shall be used for providing those credentials,
 you will also need to create one::
 
-  $ radosgw-admin user create --uid=<user id> --display-name=<display-name> \
+  $ radosgw-admin user create --uid=<user_id> --display-name=<display_name> \
       --system
 
 Take note of the keys ``access_key`` and ``secret_key`` in the output of this
@@ -156,7 +156,7 @@ command.
 The credentials of an existing user can also be obtained by using
 `radosgw-admin`::
 
-  $ radosgw-admin user info --uid=<user id>
+  $ radosgw-admin user info --uid=<user_id>
 
 Finally, provide the credentials to the dashboard module::
 
@@ -177,8 +177,8 @@ In addition to the settings mentioned so far, the following settings do also
 exist and you may find yourself in the situation that you have to use them::
 
   $ ceph dashboard set-rgw-api-scheme <scheme>  # http or https
-  $ ceph dashboard set-rgw-api-admin-resource <admin-resource>
-  $ ceph dashboard set-rgw-api-user-id <user-id>
+  $ ceph dashboard set-rgw-api-admin-resource <admin_resource>
+  $ ceph dashboard set-rgw-api-user-id <user_id>
 
 Accessing the dashboard
 ^^^^^^^^^^^^^^^^^^^^^^^
index 8e240951fd53dd410e6e5749d2e2b77dc72bd85a..ff356d303c7732a9108454cc61b4228fb54a4dac 100644 (file)
@@ -2,9 +2,4 @@
 from __future__ import absolute_import
 
 
-class NoCredentialsException(Exception):
-    def __init__(self):
-        super(Exception, self).__init__(
-            'No RGW credentials found, '
-            'please consult the documentation on how to enable RGW for '
-            'the dashboard.')
+# Add generic exceptions here.
index e34fb75edce800d6386b2179993add260573361d..d07c9db4907a293c02d6d29749cbf05b65b3b4fc 100644 (file)
@@ -6,10 +6,17 @@ from ..awsauth import S3Auth
 from ..settings import Settings, Options
 from ..rest_client import RestClient, RequestException
 from ..tools import build_url, dict_contains_path
-from ..exceptions import NoCredentialsException
 from .. import mgr, logger
 
 
+class NoCredentialsException(RequestException):
+    def __init__(self):
+        super(NoCredentialsException, self).__init__(
+            'No RGW credentials found, '
+            'please consult the documentation on how to enable RGW for '
+            'the dashboard.')
+
+
 def _determine_rgw_addr():
     """
     Get a RGW daemon to determine the configured host (IP address) and port.
@@ -83,19 +90,19 @@ class RgwClient(RestClient):
 
     @staticmethod
     def _load_settings():
-        if Settings.RGW_API_SCHEME and Settings.RGW_API_ACCESS_KEY and \
-                Settings.RGW_API_SECRET_KEY:
-            if Options.has_default_value('RGW_API_HOST') and \
-                    Options.has_default_value('RGW_API_PORT'):
-                host, port = _determine_rgw_addr()
-            else:
-                host, port = Settings.RGW_API_HOST, Settings.RGW_API_PORT
-        else:
+        # The API access key and secret key are mandatory for a minimal configuration.
+        if not (Settings.RGW_API_ACCESS_KEY and Settings.RGW_API_SECRET_KEY):
             logger.warning('No credentials found, please consult the '
                            'documentation about how to enable RGW for the '
                            'dashboard.')
             raise NoCredentialsException()
 
+        if Options.has_default_value('RGW_API_HOST') and \
+                Options.has_default_value('RGW_API_PORT'):
+            host, port = _determine_rgw_addr()
+        else:
+            host, port = Settings.RGW_API_HOST, Settings.RGW_API_PORT
+
         RgwClient._host = host
         RgwClient._port = port
         RgwClient._ssl = Settings.RGW_API_SCHEME == 'https'
@@ -103,7 +110,7 @@ class RgwClient(RestClient):
         RgwClient._SYSTEM_USERID = Settings.RGW_API_USER_ID
 
         logger.info("Creating new connection for user: %s",
-                    Settings.RGW_API_USER_ID)
+                    RgwClient._SYSTEM_USERID)
         RgwClient._user_instances[RgwClient._SYSTEM_USERID] = \
             RgwClient(Settings.RGW_API_USER_ID, Settings.RGW_API_ACCESS_KEY,
                       Settings.RGW_API_SECRET_KEY)
@@ -165,10 +172,14 @@ class RgwClient(RestClient):
 
         logger.info("Creating new connection")
 
-    @RestClient.api_get('/', resp_structure='[0] > ID')
+    @RestClient.api_get('/', resp_structure='[0] > (ID & DisplayName)')
     def is_service_online(self, request=None):
-        response = request({'format': 'json'})
-        return response[0]['ID'] == 'online'
+        """
+        Consider the service as online if the response contains the
+        specified keys. Nothing more is checked here.
+        """
+        request({'format': 'json'})
+        return True
 
     @RestClient.api_get('/{admin_path}/metadata/user', resp_structure='[+]')
     def _is_system_user(self, admin_path, request=None):