summaryrefslogtreecommitdiff
path: root/swift/common/base_storage_server.py
diff options
context:
space:
mode:
authorMahati Chamarthy <mahati.chamarthy@gmail.com>2014-12-08 23:28:48 +0530
committerMahati Chamarthy <mahati.chamarthy@gmail.com>2015-01-21 21:21:12 +0530
commitc6fde6de79278cbff7af243ae3bf538b88769fa9 (patch)
tree39726fd1f83dbb828453647a0f56db8b78b9ddeb /swift/common/base_storage_server.py
parentcc2f0f4ed6f12554b7d8e8cb61e14f2b103445a0 (diff)
downloadswift-c6fde6de79278cbff7af243ae3bf538b88769fa9.tar.gz
Implement OPTIONS verb for storage nodes.
Many times new deployers get mysterious errors after first setting up their Swift clusters. Most of the time, the errors are because the values in the ring are incorrect (e.g. a bad port number). OPTIONS will be used in a ring checker (which is WIP) that validates values in the ring. This patch includes OPTIONS for storage nodes and respective tests. Change-Id: Ia0033756d070bef11d921180e8d32a1ab2b88acf
Diffstat (limited to 'swift/common/base_storage_server.py')
-rw-r--r--swift/common/base_storage_server.py70
1 files changed, 70 insertions, 0 deletions
diff --git a/swift/common/base_storage_server.py b/swift/common/base_storage_server.py
new file mode 100644
index 000000000..4eb024b27
--- /dev/null
+++ b/swift/common/base_storage_server.py
@@ -0,0 +1,70 @@
+# Copyright (c) 2010-2014 OpenStack Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import inspect
+from swift.common.utils import public, timing_stats, config_true_value
+from swift.common.swob import Response
+
+
+class BaseStorageServer(object):
+ """
+ Implements common OPTIONS method for object, account, container servers.
+ """
+
+ def __init__(self, conf, **kwargs):
+ self._allowed_methods = None
+ replication_server = conf.get('replication_server', None)
+ if replication_server is not None:
+ replication_server = config_true_value(replication_server)
+ self.replication_server = replication_server
+
+ @property
+ def allowed_methods(self):
+ if self._allowed_methods is None:
+ self._allowed_methods = []
+ all_methods = inspect.getmembers(self, predicate=callable)
+
+ if self.replication_server is True:
+ for name, m in all_methods:
+ if (getattr(m, 'publicly_accessible', False) and
+ getattr(m, 'replication', False)):
+ self._allowed_methods.append(name)
+ elif self.replication_server is False:
+ for name, m in all_methods:
+ if (getattr(m, 'publicly_accessible', False) and not
+ getattr(m, 'replication', False)):
+ self._allowed_methods.append(name)
+ elif self.replication_server is None:
+ for name, m in all_methods:
+ if getattr(m, 'publicly_accessible', False):
+ self._allowed_methods.append(name)
+
+ self._allowed_methods.sort()
+ return self._allowed_methods
+
+ @public
+ @timing_stats()
+ def OPTIONS(self, req):
+ """
+ Base handler for OPTIONS requests
+
+ :param req: swob.Request object
+ :returns: swob.Response object
+ """
+ # Prepare the default response
+ headers = {'Allow': ', '.join(self.allowed_methods)}
+ resp = Response(status=200, request=req, headers=headers)
+
+ return resp