From 77b761d6463fcec383c12bf8ee0df1ae1410c464 Mon Sep 17 00:00:00 2001 From: Rajaram Mallya Date: Mon, 22 Aug 2011 11:58:29 +0530 Subject: Vinkesh/Rajaram|fixed setup.py and made openstack a module with a __init__.py file --- openstack/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 openstack/__init__.py (limited to 'openstack') 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. -- cgit From 0789e762583f3b306aa50c8c74c48256e731eb6c Mon Sep 17 00:00:00 2001 From: Rajaram Mallya Date: Thu, 25 Aug 2011 10:58:45 +0530 Subject: Rajaram/Vinkesh | Removed references to Glance in code --- openstack/common/config.py | 30 ++++++++++++++++-------------- openstack/common/exception.py | 8 +++----- openstack/common/utils.py | 9 +-------- 3 files changed, 20 insertions(+), 27 deletions(-) (limited to 'openstack') diff --git a/openstack/common/config.py b/openstack/common/config.py index 758d128..7b069f3 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, app_config_dir_name=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/ + * ~.app_config_dir_name/ * ~ - * /etc/glance + * /etc/app_config_dir_name * /etc :retval Full path to config file, or None if no config file found """ + app_config_dir_name = app_config_dir_name 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('~', '.' + app_config_dir_name)), fix_path('~'), - '/etc/glance/', + os.path.join('/etc', app_config_dir_name), '/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, app_config_dir_name=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/ + * ~.app_config_dir_name/ * ~ - * /etc/glance + * /etc/app_config_dir_name * /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, app_config_dir_name) 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, app_config_dir_name=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/ + * ~.app_config_dir_name/ * ~ - * /etc/glance + * /etc/app_config_dir_name * /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, app_config_dir_name) 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..cd382d6 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 AppBaseException(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(AppBaseException): 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" -- cgit From 7f842efba56125e0903a13a9e50a925adef48bc2 Mon Sep 17 00:00:00 2001 From: Rajaram Mallya Date: Tue, 30 Aug 2011 14:09:14 +0530 Subject: Rajaram/Vinkesh| restructured wsgi.resource to allow inheriting classes to override serialization, deserialization and action execution --- openstack/common/wsgi.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'openstack') 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: -- cgit From 0ec0a05aafbeec0b02da7e08ee8de69b459495df Mon Sep 17 00:00:00 2001 From: Rajaram Mallya Date: Wed, 31 Aug 2011 08:29:34 +0530 Subject: Rajaram|renamed AppBaseException to OpenstackException and app_config_dir_name to config_dir as per jaypipes' feedback --- openstack/common/config.py | 28 ++++++++++++++-------------- openstack/common/exception.py | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'openstack') diff --git a/openstack/common/config.py b/openstack/common/config.py index 7b069f3..e954609 100644 --- a/openstack/common/config.py +++ b/openstack/common/config.py @@ -178,7 +178,7 @@ def setup_logging(options, conf): root_logger.addHandler(handler) -def find_config_file(app_name, options, args, app_config_dir_name=None): +def find_config_file(app_name, options, args, config_dir=None): """ Return the first config file found for an application. @@ -187,14 +187,14 @@ def find_config_file(app_name, options, args, app_config_dir_name=None): * If args[0] is a file, use that * Search for $app.conf in standard directories: * . - * ~.app_config_dir_name/ + * ~.config_dir/ * ~ - * /etc/app_config_dir_name + * /etc/config_dir * /etc :retval Full path to config file, or None if no config file found """ - app_config_dir_name = app_config_dir_name or app_name + config_dir = config_dir or app_name fix_path = lambda p: os.path.abspath(os.path.expanduser(p)) if options.get('config_file'): @@ -206,9 +206,9 @@ def find_config_file(app_name, options, args, app_config_dir_name=None): # Handle standard directory search for $app_name.conf config_file_dirs = [fix_path(os.getcwd()), - fix_path(os.path.join('~', '.' + app_config_dir_name)), + fix_path(os.path.join('~', '.' + config_dir)), fix_path('~'), - os.path.join('/etc', app_config_dir_name), + os.path.join('/etc', config_dir), '/etc'] for cfg_dir in config_file_dirs: @@ -217,7 +217,7 @@ def find_config_file(app_name, options, args, app_config_dir_name=None): return cfg_file -def load_paste_config(app_name, options, args, app_config_dir_name=None): +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. @@ -227,9 +227,9 @@ def load_paste_config(app_name, options, args, app_config_dir_name=None): * If args[0] is a file, use that * Search for $app_name.conf in standard directories: * . - * ~.app_config_dir_name/ + * ~.config_dir/ * ~ - * /etc/app_config_dir_name + * /etc/config_dir * /etc :param app_name: Name of the application to load config for, or None. @@ -242,7 +242,7 @@ def load_paste_config(app_name, options, args, app_config_dir_name=None): :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, app_config_dir_name) + 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) @@ -254,7 +254,7 @@ def load_paste_config(app_name, options, args, app_config_dir_name=None): % (conf_file, e)) -def load_paste_app(app_name, options, args, app_config_dir_name=None): +def load_paste_app(app_name, options, args, config_dir=None): """ Builds and returns a WSGI app from a paste config file. @@ -263,9 +263,9 @@ def load_paste_app(app_name, options, args, app_config_dir_name=None): * If args[0] is a file, use that * Search for $app_name.conf in standard directories: * . - * ~.app_config_dir_name/ + * ~.config_dir/ * ~ - * /etc/app_config_dir_name + * /etc/config_dir * /etc :param app_name: Name of the application to load @@ -276,7 +276,7 @@ def load_paste_app(app_name, options, args, app_config_dir_name=None): cannot be loaded from config file """ conf_file, conf = load_paste_config(app_name, options, - args, app_config_dir_name) + 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 cd382d6..a81355e 100644 --- a/openstack/common/exception.py +++ b/openstack/common/exception.py @@ -117,7 +117,7 @@ def wrap_exception(f): return _wrap -class AppBaseException(Exception): +class OpenstackException(Exception): """ Base Exception @@ -139,5 +139,5 @@ class AppBaseException(Exception): return self._error_string -class InvalidContentType(AppBaseException): +class InvalidContentType(OpenstackException): message = "Invalid content type %(content_type)s" -- cgit