From 20c8c3e1054ba364e4a2ace8e49a5e976d4faf2e Mon Sep 17 00:00:00 2001 From: Tim Simpson Date: Wed, 7 Mar 2012 14:11:51 -0600 Subject: [PATCH] Removed API folder. --- reddwarf/api/__init__.py | 21 -- reddwarf/api/database/__init__.py | 54 ----- reddwarf/api/database/contrib/__init__.py | 39 ---- reddwarf/api/database/contrib/databases.py | 75 ------- reddwarf/api/database/extensions.py | 33 --- reddwarf/api/database/instances.py | 106 --------- reddwarf/api/database/versions.py | 236 --------------------- reddwarf/api/database/views/__init__.py | 17 -- reddwarf/api/database/views/instances.py | 67 ------ 9 files changed, 648 deletions(-) delete mode 100644 reddwarf/api/__init__.py delete mode 100644 reddwarf/api/database/__init__.py delete mode 100644 reddwarf/api/database/contrib/__init__.py delete mode 100644 reddwarf/api/database/contrib/databases.py delete mode 100644 reddwarf/api/database/extensions.py delete mode 100644 reddwarf/api/database/instances.py delete mode 100644 reddwarf/api/database/versions.py delete mode 100644 reddwarf/api/database/views/__init__.py delete mode 100644 reddwarf/api/database/views/instances.py diff --git a/reddwarf/api/__init__.py b/reddwarf/api/__init__.py deleted file mode 100644 index 8d837e6532..0000000000 --- a/reddwarf/api/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# 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. - -""" -WSGI middleware for OpenStack API controllers. -""" diff --git a/reddwarf/api/database/__init__.py b/reddwarf/api/database/__init__.py deleted file mode 100644 index c52a76d409..0000000000 --- a/reddwarf/api/database/__init__.py +++ /dev/null @@ -1,54 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# 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. - -""" -WSGI middleware for OpenStack Compute API. -""" - -import nova.api.openstack -from reddwarf.api.database import extensions -from reddwarf.api.database import instances -from reddwarf.api.database import versions -from nova import flags -from nova import log as logging - - -LOG = logging.getLogger('reddwarf.api.database') -FLAGS = flags.FLAGS - - -class APIRouter(nova.api.openstack.APIRouter): - """ - Routes requests on the OpenStack API to the appropriate controller - and method. - """ - ExtensionManager = extensions.ExtensionManager - - def _setup_routes(self, mapper): - self.resources['versions'] = versions.create_resource() - mapper.connect("versions", "/", - controller=self.resources['versions'], - action='show') - - mapper.redirect("", "/") - - self.resources['instances'] = instances.create_resource() - mapper.resource("instance", "instances", - controller=self.resources['instances'], - collection={'detail': 'GET'}, - member={'action': 'POST'}) diff --git a/reddwarf/api/database/contrib/__init__.py b/reddwarf/api/database/contrib/__init__.py deleted file mode 100644 index 63d76028d6..0000000000 --- a/reddwarf/api/database/contrib/__init__.py +++ /dev/null @@ -1,39 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2011 Justin Santa Barbara -# 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. - -"""Contrib contains extensions that are shipped with nova. - -It can't be called 'extensions' because that causes namespacing problems. - -""" - -from nova import flags -from nova import log as logging -from nova.api.openstack import extensions - - -FLAGS = flags.FLAGS -LOG = logging.getLogger('reddwarf.api.database.contrib') - - -def standard_extensions(ext_mgr): - extensions.load_standard_extensions(ext_mgr, LOG, __path__, __package__) - - -def select_extensions(ext_mgr): - extensions.load_standard_extensions(ext_mgr, LOG, __path__, __package__, - FLAGS.osapi_compute_ext_list) diff --git a/reddwarf/api/database/contrib/databases.py b/reddwarf/api/database/contrib/databases.py deleted file mode 100644 index ac231ffad5..0000000000 --- a/reddwarf/api/database/contrib/databases.py +++ /dev/null @@ -1,75 +0,0 @@ -# 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. - -import webob.exc - -from nova.api.openstack import extensions -from nova import log as logging - -LOG = logging.getLogger('reddwarf.api.database.contrib.databases') - - -class DatabasesController(object): - - def index(self, req): - LOG.info("index call databases") - return "This is a index of databases" - - -class UsersController(object): - - def index(self, req): - LOG.info("index call users") - return "This is a index of users" - - -class Databases(extensions.ExtensionDescriptor): - """The Databases Extension""" - - name = "Databases" - alias = "DATABASES" - namespace = "http://TBD" - updated = "2011-01-22T13:25:27-06:00" - - def __init__(self, ext_mgr): - ext_mgr.register(self) - - def get_resources(self): - resources = [] - resource = extensions.ResourceExtension('databases', - DatabasesController()) - resources.append(resource) - resource = extensions.ResourceExtension('users', - UsersController()) - resources.append(resource) - - return resources - - def get_controller_extensions(self): - extension_list = [] - - extension_set = [ -# (DatabasesControllerExtension, 'instances'), -# (FoxInSocksFlavorGooseControllerExtension, 'flavors'), -# (FoxInSocksFlavorBandsControllerExtension, 'flavors'), - ] - for klass, collection in extension_set: - controller = klass() - ext = extensions.ControllerExtension(self, collection, controller) - extension_list.append(ext) - - return extension_list diff --git a/reddwarf/api/database/extensions.py b/reddwarf/api/database/extensions.py deleted file mode 100644 index a3abe0bfd0..0000000000 --- a/reddwarf/api/database/extensions.py +++ /dev/null @@ -1,33 +0,0 @@ -# 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. - -from nova.api.openstack import extensions as base_extensions -from nova import flags -from nova import log as logging - - -LOG = logging.getLogger('reddwarf.api.database.extensions') -FLAGS = flags.FLAGS - - -class ExtensionManager(base_extensions.ExtensionManager): - def __init__(self): - LOG.audit(_('Initializing extension manager.')) - - self.cls_list = FLAGS.reddwarf_api_extension - self.extensions = {} - self._load_extensions() diff --git a/reddwarf/api/database/instances.py b/reddwarf/api/database/instances.py deleted file mode 100644 index 3d60faeeda..0000000000 --- a/reddwarf/api/database/instances.py +++ /dev/null @@ -1,106 +0,0 @@ -# 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. - -from nova import flags -from nova import log as logging -from nova.api.openstack import wsgi -from novaclient.v1_1.client import Client -from nova.openstack.common import cfg -from reddwarf.api.database.views import instances as views_instances - -LOG = logging.getLogger('reddwarf.api.database.instances') - -reddwarf_opts = [ - cfg.StrOpt('reddwarf_proxy_admin_user', - default='admin', - help='User by which you make proxy requests to the nova api with'), - cfg.StrOpt('reddwarf_proxy_admin_pass', - default='3de4922d8b6ac5a1aad9', - help='Password for the admin user defined in ' - 'reddwarf_proxy_admin_user'), - cfg.StrOpt('reddwarf_proxy_admin_tenant_name', - default='admin', - help='Tenant name for the admin user defined in ' - 'reddwarf_proxy_admin_user'), - cfg.StrOpt('reddwarf_auth_url', - default='http://0.0.0.0:5000/v2.0', - help='Auth url for authing against reddwarf_proxy_admin_user'), - ] - -FLAGS = flags.FLAGS -FLAGS.register_opts(reddwarf_opts) - - -class Controller(wsgi.Controller): - - _view_builder_class = views_instances.ViewBuilder - - def __init__(self, **kwargs): - super(Controller, self).__init__(**kwargs) - - def get_client(self, req): - proxy_token = req.headers["X-Auth-Token"] - client = Client(FLAGS.reddwarf_proxy_admin_user, - FLAGS.reddwarf_proxy_admin_pass, - FLAGS.reddwarf_proxy_admin_tenant_name, - FLAGS.reddwarf_auth_url, - token=proxy_token) - client.authenticate() - return client - - def index(self, req): - """Return all instances.""" - servers = self.get_client(req).servers.list() - for server in servers: - LOG.info(server.__dict__) - return self._view_builder.index(req, servers) - - @wsgi.response(204) - def delete(self, req, id): - """Deletes an instance.""" - self.get_client(req).servers.delete(id) - - @wsgi.response(202) - @wsgi.serializers(xml=FullServerTemplate) - @wsgi.deserializers(xml=CreateDeserializer) - def create(self, req, body): - """Creates an instance""" - server = self.get_client(req).servers.create( - body['name'], body['image'], body['flavor']) - LOG.info(server) - robj = wsgi.ResponseObject(server) - - return self._add_location(robj) - - @staticmethod - def _add_location(robj): - """Stolen form compute/servers. do we need it?""" - # Just in case... - if 'server' not in robj.obj: - return robj - - link = filter(lambda l: l['rel'] == 'self', - robj.obj['server']['links']) - if link: - robj['Location'] = link[0]['href'] - - # Convenience return - return robj - - -def create_resource(): - return wsgi.Resource(Controller()) diff --git a/reddwarf/api/database/versions.py b/reddwarf/api/database/versions.py deleted file mode 100644 index be5bdf64a7..0000000000 --- a/reddwarf/api/database/versions.py +++ /dev/null @@ -1,236 +0,0 @@ -# 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. - -import datetime - -from lxml import etree - -from nova.api.openstack.compute.views import versions as views_versions -from nova.api.openstack import wsgi -from nova.api.openstack import xmlutil - - -VERSIONS = { - "v2.0": { - "id": "v2.0", - "status": "CURRENT", - "updated": "2012-01-01T11:33:21Z", - "links": [ - { - "rel": "describedby", - "type": "application/pdf", - "href": "http://docs.rackspacecloud.com/" - "clouddatabase/api/v1.1/cs-devguide-20110125.pdf", - }, - { - "rel": "describedby", - "type": "application/vnd.sun.wadl+xml", - "href": "http://docs.rackspacecloud.com/" - "clouddatabase/api/v1.1/application.wadl", - }, - ], - "media-types": [ - { - "base": "application/xml", - "type": "application/vnd.openstack.reddwarf+xml;version=2", - }, - { - "base": "application/json", - "type": "application/vnd.openstack.reddwarf+json;version=2", - } - ], - } -} - - -class MediaTypesTemplateElement(xmlutil.TemplateElement): - def will_render(self, datum): - return 'media-types' in datum - - -def make_version(elem): - elem.set('id') - elem.set('status') - elem.set('updated') - - mts = MediaTypesTemplateElement('media-types') - elem.append(mts) - - mt = xmlutil.SubTemplateElement(mts, 'media-type', selector='media-types') - mt.set('base') - mt.set('type') - - xmlutil.make_links(elem, 'links') - - -version_nsmap = {None: xmlutil.XMLNS_V11, 'atom': xmlutil.XMLNS_ATOM} - - -class VersionTemplate(xmlutil.TemplateBuilder): - def construct(self): - root = xmlutil.TemplateElement('version', selector='version') - make_version(root) - return xmlutil.MasterTemplate(root, 1, nsmap=version_nsmap) - - -class VersionsTemplate(xmlutil.TemplateBuilder): - def construct(self): - root = xmlutil.TemplateElement('versions') - elem = xmlutil.SubTemplateElement(root, 'version', selector='versions') - make_version(elem) - return xmlutil.MasterTemplate(root, 1, nsmap=version_nsmap) - - -class ChoicesTemplate(xmlutil.TemplateBuilder): - def construct(self): - root = xmlutil.TemplateElement('choices') - elem = xmlutil.SubTemplateElement(root, 'version', selector='choices') - make_version(elem) - return xmlutil.MasterTemplate(root, 1, nsmap=version_nsmap) - - -class AtomSerializer(wsgi.XMLDictSerializer): - - NSMAP = {None: xmlutil.XMLNS_ATOM} - - def __init__(self, metadata=None, xmlns=None): - self.metadata = metadata or {} - if not xmlns: - self.xmlns = wsgi.XMLNS_ATOM - else: - self.xmlns = xmlns - - def _get_most_recent_update(self, versions): - recent = None - for version in versions: - updated = datetime.datetime.strptime(version['updated'], - '%Y-%m-%dT%H:%M:%SZ') - if not recent: - recent = updated - elif updated > recent: - recent = updated - - return recent.strftime('%Y-%m-%dT%H:%M:%SZ') - - def _get_base_url(self, link_href): - # Make sure no trailing / - link_href = link_href.rstrip('/') - return link_href.rsplit('/', 1)[0] + '/' - - def _create_feed(self, versions, feed_title, feed_id): - feed = etree.Element('feed', nsmap=self.NSMAP) - title = etree.SubElement(feed, 'title') - title.set('type', 'text') - title.text = feed_title - - # Set this updated to the most recently updated version - recent = self._get_most_recent_update(versions) - etree.SubElement(feed, 'updated').text = recent - - etree.SubElement(feed, 'id').text = feed_id - - link = etree.SubElement(feed, 'link') - link.set('rel', 'self') - link.set('href', feed_id) - - author = etree.SubElement(feed, 'author') - etree.SubElement(author, 'name').text = 'Rackspace' - etree.SubElement(author, 'uri').text = 'http://www.rackspace.com/' - - for version in versions: - feed.append(self._create_version_entry(version)) - - return feed - - def _create_version_entry(self, version): - entry = etree.Element('entry') - etree.SubElement(entry, 'id').text = version['links'][0]['href'] - title = etree.SubElement(entry, 'title') - title.set('type', 'text') - title.text = 'Version %s' % version['id'] - etree.SubElement(entry, 'updated').text = version['updated'] - - for link in version['links']: - link_elem = etree.SubElement(entry, 'link') - link_elem.set('rel', link['rel']) - link_elem.set('href', link['href']) - if 'type' in link: - link_elem.set('type', link['type']) - - content = etree.SubElement(entry, 'content') - content.set('type', 'text') - content.text = 'Version %s %s (%s)' % (version['id'], - version['status'], - version['updated']) - return entry - - -class VersionsAtomSerializer(AtomSerializer): - def default(self, data): - versions = data['versions'] - feed_id = self._get_base_url(versions[0]['links'][0]['href']) - feed = self._create_feed(versions, 'Available API Versions', feed_id) - return self._to_xml(feed) - - -class VersionAtomSerializer(AtomSerializer): - def default(self, data): - version = data['version'] - feed_id = version['links'][0]['href'] - feed = self._create_feed([version], 'About This Version', feed_id) - return self._to_xml(feed) - - -class Versions(wsgi.Resource): - def __init__(self): - super(Versions, self).__init__(None) - - @wsgi.serializers(xml=VersionsTemplate, - atom=VersionsAtomSerializer) - def index(self, req): - """Return all versions.""" - builder = views_versions.get_view_builder(req) - return builder.build_versions(VERSIONS) - - @wsgi.serializers(xml=ChoicesTemplate) - @wsgi.response(300) - def multi(self, req): - """Return multiple choices.""" - builder = views_versions.get_view_builder(req) - return builder.build_choices(VERSIONS, req) - - def get_action_args(self, request_environment): - """Parse dictionary created by routes library.""" - args = {} - if request_environment['PATH_INFO'] == '/': - args['action'] = 'index' - else: - args['action'] = 'multi' - - return args - - -class VersionV2(object): - @wsgi.serializers(xml=VersionTemplate, - atom=VersionAtomSerializer) - def show(self, req): - builder = views_versions.get_view_builder(req) - return builder.build_version(VERSIONS['v2.0']) - - -def create_resource(): - return wsgi.Resource(VersionV2()) diff --git a/reddwarf/api/database/views/__init__.py b/reddwarf/api/database/views/__init__.py deleted file mode 100644 index 747015af53..0000000000 --- a/reddwarf/api/database/views/__init__.py +++ /dev/null @@ -1,17 +0,0 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - -# Copyright 2010 United States Government as represented by the -# Administrator of the National Aeronautics and Space Administration. -# 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/reddwarf/api/database/views/instances.py b/reddwarf/api/database/views/instances.py deleted file mode 100644 index c2b2b13fa4..0000000000 --- a/reddwarf/api/database/views/instances.py +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright 2011 OpenStack LLC -# -# 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 os - - -from nova import log as logging -from nova.api.openstack.compute.views import servers as views_servers -#from reddwarf.api.database.views import flavors - - -LOG = logging.getLogger('reddwarf.api.views.instance') -LOG.setLevel(logging.DEBUG) - - -def _project_id(req): - return getattr(req.environ['nova.context'], 'project_id', '') - - -def _base_url(req): - return req.application_url - - -class ViewBuilder(object): - """Views for an instance""" - - def __init__(self): - self.servers_viewbuilder = views_servers.ViewBuilder() - - def basic(self, request, instance): - return { - "instance": { - "id": instance.id, - "name": instance.name, - "links": self.servers_viewbuilder._get_links(request, - instance.id), - }, - } - - def index(self, request, servers): - """Show a list of servers without many details.""" - return self._list_view(self.basic, request, servers) - - def _list_view(self, func, request, servers): - """Provide a view for a list of instances.""" - # This is coming back as a server entity but we change it to instances - instance_list = [func(request, instance)["instance"] - for instance in servers] - servers_links = self.servers_viewbuilder._get_collection_links( - request, servers) - instances_dict = dict(instances=instance_list) - - if servers_links: - instances_dict["servers_links"] = servers_links - - return instances_dict