summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorMichael Gundlach <michael.gundlach@rackspace.com>2010-08-24 16:16:41 -0400
committerMichael Gundlach <michael.gundlach@rackspace.com>2010-08-24 16:16:41 -0400
commit09bc71460b976f28c7bc6a507006d6c7c12c5824 (patch)
tree8e05c4b33cad0fb3d09ea9c3632825d6ecbad05d /nova/api
parent4d1b2539d2d2f39ca53e9383e317af76dbc71905 (diff)
Move imageservice to its own directory
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/rackspace/images.py4
-rw-r--r--nova/api/services/image.py90
2 files changed, 2 insertions, 92 deletions
diff --git a/nova/api/rackspace/images.py b/nova/api/rackspace/images.py
index 36a26688c..b7668a1e1 100644
--- a/nova/api/rackspace/images.py
+++ b/nova/api/rackspace/images.py
@@ -17,7 +17,7 @@
from nova import datastore
from nova.api.rackspace import base
-from nova.api.services import image
+from nova import image
from webob import exc
class Controller(base.Controller):
@@ -32,7 +32,7 @@ class Controller(base.Controller):
}
def __init__(self):
- self._service = image.ImageService.load()
+ self._service = image.service.ImageService.load()
self._id_translator = RackspaceAPIImageIdTranslator()
def _to_rs_id(self, image_id):
diff --git a/nova/api/services/image.py b/nova/api/services/image.py
deleted file mode 100644
index 1a7a258b7..000000000
--- a/nova/api/services/image.py
+++ /dev/null
@@ -1,90 +0,0 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-
-# Copyright 2010 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 cPickle as pickle
-import os.path
-import random
-import string
-
-class ImageService(object):
- """Provides storage and retrieval of disk image objects."""
-
- @staticmethod
- def load():
- """Factory method to return image service."""
- #TODO(gundlach): read from config.
- class_ = LocalImageService
- return class_()
-
- def index(self):
- """
- Return a dict from opaque image id to image data.
- """
-
- def show(self, id):
- """
- Returns a dict containing image data for the given opaque image id.
- """
-
-
-class GlanceImageService(ImageService):
- """Provides storage and retrieval of disk image objects within Glance."""
- # TODO(gundlach): once Glance has an API, build this.
- pass
-
-
-class LocalImageService(ImageService):
- """Image service storing images to local disk."""
-
- def __init__(self):
- self._path = "/tmp/nova/images"
- try:
- os.makedirs(self._path)
- except OSError: # exists
- pass
-
- def _path_to(self, image_id=''):
- return os.path.join(self._path, image_id)
-
- def _ids(self):
- """The list of all image ids."""
- return os.listdir(self._path)
-
- def index(self):
- return [ self.show(id) for id in self._ids() ]
-
- def show(self, id):
- return pickle.load(open(self._path_to(id)))
-
- def create(self, data):
- """
- Store the image data and return the new image id.
- """
- id = ''.join(random.choice(string.letters) for _ in range(20))
- data['id'] = id
- self.update(id, data)
- return id
-
- def update(self, image_id, data):
- """Replace the contents of the given image with the new data."""
- pickle.dump(data, open(self._path_to(image_id), 'w'))
-
- def delete(self, image_id):
- """
- Delete the given image. Raises OSError if the image does not exist.
- """
- os.unlink(self._path_to(image_id))