diff options
| author | jaypipes <jaypipes@gmail.com> | 2011-08-30 20:08:40 -0700 |
|---|---|---|
| committer | jaypipes <jaypipes@gmail.com> | 2011-08-30 20:08:40 -0700 |
| commit | dbab61cd6bb070b5fc40a5fdc49b2caf3b20675a (patch) | |
| tree | c392257a23939c9fd823cb85d65c1dae920502b0 /openstack | |
| parent | f314bc0457781846c116b9cc0ad24ea49891d2d9 (diff) | |
| parent | 0ec0a05aafbeec0b02da7e08ee8de69b459495df (diff) | |
| download | oslo-dbab61cd6bb070b5fc40a5fdc49b2caf3b20675a.tar.gz oslo-dbab61cd6bb070b5fc40a5fdc49b2caf3b20675a.tar.xz oslo-dbab61cd6bb070b5fc40a5fdc49b2caf3b20675a.zip | |
Merge pull request #2 from rajarammallya/master
Made openstack.common a module and removed code references to glance
Diffstat (limited to 'openstack')
| -rw-r--r-- | openstack/__init__.py | 16 | ||||
| -rw-r--r-- | openstack/common/config.py | 30 | ||||
| -rw-r--r-- | openstack/common/exception.py | 8 | ||||
| -rw-r--r-- | openstack/common/utils.py | 9 | ||||
| -rw-r--r-- | openstack/common/wsgi.py | 25 |
5 files changed, 52 insertions, 36 deletions
diff --git a/openstack/__init__.py b/openstack/__init__.py new file mode 100644 index 0000000..d65c689 --- /dev/null +++ b/openstack/__init__.py @@ -0,0 +1,16 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2011 OpenStack LLC. +# All Rights Reserved. +# +# 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. diff --git a/openstack/common/config.py b/openstack/common/config.py index 758d128..e954609 100644 --- a/openstack/common/config.py +++ b/openstack/common/config.py @@ -65,7 +65,7 @@ def add_common_options(parser): :param parser: optparse.OptionParser """ help_text = "The following configuration options are common to "\ - "all glance programs." + "this app's programs." group = optparse.OptionGroup(parser, "Common Options", help_text) group.add_option('-v', '--verbose', default=False, dest="verbose", @@ -178,7 +178,7 @@ def setup_logging(options, conf): root_logger.addHandler(handler) -def find_config_file(app_name, options, args): +def find_config_file(app_name, options, args, config_dir=None): """ Return the first config file found for an application. @@ -187,13 +187,14 @@ def find_config_file(app_name, options, args): * If args[0] is a file, use that * Search for $app.conf in standard directories: * . - * ~.glance/ + * ~.config_dir/ * ~ - * /etc/glance + * /etc/config_dir * /etc :retval Full path to config file, or None if no config file found """ + config_dir = config_dir or app_name fix_path = lambda p: os.path.abspath(os.path.expanduser(p)) if options.get('config_file'): @@ -205,9 +206,9 @@ def find_config_file(app_name, options, args): # Handle standard directory search for $app_name.conf config_file_dirs = [fix_path(os.getcwd()), - fix_path(os.path.join('~', '.glance')), + fix_path(os.path.join('~', '.' + config_dir)), fix_path('~'), - '/etc/glance/', + os.path.join('/etc', config_dir), '/etc'] for cfg_dir in config_file_dirs: @@ -216,7 +217,7 @@ def find_config_file(app_name, options, args): return cfg_file -def load_paste_config(app_name, options, args): +def load_paste_config(app_name, options, args, config_dir=None): """ Looks for a config file to use for an app and returns the config file path and a configuration mapping from a paste config file. @@ -226,9 +227,9 @@ def load_paste_config(app_name, options, args): * If args[0] is a file, use that * Search for $app_name.conf in standard directories: * . - * ~.glance/ + * ~.config_dir/ * ~ - * /etc/glance + * /etc/config_dir * /etc :param app_name: Name of the application to load config for, or None. @@ -241,7 +242,7 @@ def load_paste_config(app_name, options, args): :raises RuntimeError when config file cannot be located or there was a problem loading the configuration file. """ - conf_file = find_config_file(app_name, options, args) + conf_file = find_config_file(app_name, options, args, config_dir) if not conf_file: raise RuntimeError("Unable to locate any configuration file. " "Cannot load application %s" % app_name) @@ -253,7 +254,7 @@ def load_paste_config(app_name, options, args): % (conf_file, e)) -def load_paste_app(app_name, options, args): +def load_paste_app(app_name, options, args, config_dir=None): """ Builds and returns a WSGI app from a paste config file. @@ -262,9 +263,9 @@ def load_paste_app(app_name, options, args): * If args[0] is a file, use that * Search for $app_name.conf in standard directories: * . - * ~.glance/ + * ~.config_dir/ * ~ - * /etc/glance + * /etc/config_dir * /etc :param app_name: Name of the application to load @@ -274,7 +275,8 @@ def load_paste_app(app_name, options, args): :raises RuntimeError when config file cannot be located or application cannot be loaded from config file """ - conf_file, conf = load_paste_config(app_name, options, args) + conf_file, conf = load_paste_config(app_name, options, + args, config_dir) try: # Setup logging early, supplying both the CLI options and the diff --git a/openstack/common/exception.py b/openstack/common/exception.py index ed6b039..a81355e 100644 --- a/openstack/common/exception.py +++ b/openstack/common/exception.py @@ -20,8 +20,6 @@ Exceptions common to OpenStack projects """ import logging -import sys -import traceback class ProcessExecutionError(IOError): @@ -119,9 +117,9 @@ def wrap_exception(f): return _wrap -class GlanceException(Exception): +class OpenstackException(Exception): """ - Base Glance Exception + Base Exception To correctly use this class, inherit from it and define a 'message' property. That message will get printf'd @@ -141,5 +139,5 @@ class GlanceException(Exception): return self._error_string -class InvalidContentType(GlanceException): +class InvalidContentType(OpenstackException): message = "Invalid content type %(content_type)s" diff --git a/openstack/common/utils.py b/openstack/common/utils.py index 45c622e..0d2f89e 100644 --- a/openstack/common/utils.py +++ b/openstack/common/utils.py @@ -20,16 +20,9 @@ System-level utilities and helper functions. """ import datetime -import inspect -import logging -import os -import random -import subprocess -import socket import sys -from glance.common import exception -from glance.common.exception import ProcessExecutionError +from openstack.common import exception TIME_FORMAT = "%Y-%m-%dT%H:%M:%SZ" diff --git a/openstack/common/wsgi.py b/openstack/common/wsgi.py index ef132dc..8faa6dc 100644 --- a/openstack/common/wsgi.py +++ b/openstack/common/wsgi.py @@ -302,21 +302,28 @@ class Resource(object): action_args = self.get_action_args(request.environ) action = action_args.pop('action', None) - deserialized_request = self.dispatch(self.deserializer, - action, request) - action_args.update(deserialized_request) - - action_result = self.dispatch(self.controller, action, - request, **action_args) + deserialized_params = self.deserialize_request(action, request) + action_args.update(deserialized_params) + action_result = self.execute_action(action, request, **action_args) try: - response = webob.Response() - self.dispatch(self.serializer, action, response, action_result) - return response + return self.serialize_response(action, action_result, request) # return unserializable result (typically a webob exc) except Exception: return action_result + def deserialize_request(self, action, request): + return self.dispatch(self.deserializer, action, request) + + def serialize_response(self, action, action_result, request): + response = webob.Response() + self.dispatch(self.serializer, action, response, + action_result, request) + return response + + def execute_action(self, action, request, **action_args): + return self.dispatch(self.controller, action, request, **action_args) + def dispatch(self, obj, action, *args, **kwargs): """Find action-specific method on self and call it.""" try: |
