summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJustin Santa Barbara <justin@fathomdb.com>2011-03-28 16:36:25 -0700
committerJustin Santa Barbara <justin@fathomdb.com>2011-03-28 16:36:25 -0700
commita6e8c83196cb4b2d8a292a99cb1feb22ed9b21db (patch)
tree9f200c9cdad969698f26739912710f2413c7c94b /nova
parent57a4864e30df604612a347ba069ccc8499b04f1f (diff)
Cleaned up images/fake.py, including move to Duplicate exception
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/incubator/volumes/volume_attachments.py30
-rw-r--r--nova/api/openstack/incubator/volumes/volumes.py18
-rw-r--r--nova/api/openstack/incubator/volumes/volumes_ext.py4
-rw-r--r--nova/compute/manager.py2
-rw-r--r--nova/image/fake.py29
5 files changed, 39 insertions, 44 deletions
diff --git a/nova/api/openstack/incubator/volumes/volume_attachments.py b/nova/api/openstack/incubator/volumes/volume_attachments.py
index 93786d1c7..1e260b34d 100644
--- a/nova/api/openstack/incubator/volumes/volume_attachments.py
+++ b/nova/api/openstack/incubator/volumes/volume_attachments.py
@@ -34,7 +34,7 @@ FLAGS = flags.FLAGS
def _translate_detail_view(context, volume):
- """Maps keys for details view"""
+ """Maps keys for details view."""
d = _translate_summary_view(context, volume)
@@ -44,12 +44,12 @@ def _translate_detail_view(context, volume):
def _translate_summary_view(context, vol):
- """Maps keys for summary view"""
+ """Maps keys for summary view."""
d = {}
volume_id = vol['id']
- #NOTE(justinsb): We use the volume id as the id of the attachment object
+ # NOTE(justinsb): We use the volume id as the id of the attachment object
d['id'] = volume_id
d['volumeId'] = volume_id
@@ -62,7 +62,7 @@ def _translate_summary_view(context, vol):
class Controller(wsgi.Controller):
- """The volume attachment API controller for the Openstack API
+ """The volume attachment API controller for the Openstack API.
A child resource of the server. Note that we use the volume id
as the ID of the attachment (though this is not guaranteed externally)"""
@@ -81,12 +81,12 @@ class Controller(wsgi.Controller):
super(Controller, self).__init__()
def index(self, req, server_id):
- """Returns the list of volume attachments for a given instance """
+ """Returns the list of volume attachments for a given instance."""
return self._items(req, server_id,
entity_maker=_translate_summary_view)
def show(self, req, server_id, id):
- """Return data about the given volume"""
+ """Return data about the given volume."""
context = req.environ['nova.context']
volume_id = id
@@ -103,7 +103,7 @@ class Controller(wsgi.Controller):
return {'volumeAttachment': _translate_detail_view(context, vol)}
def create(self, req, server_id):
- """Attach a volume to an instance """
+ """Attach a volume to an instance."""
context = req.environ['nova.context']
env = self._deserialize(req.body, req.get_content_type())
@@ -131,15 +131,15 @@ class Controller(wsgi.Controller):
attachment['id'] = volume_id
attachment['volumeId'] = volume_id
- #NOTE(justinsb): And now, we have a problem...
+ # NOTE(justinsb): And now, we have a problem...
# The attach is async, so there's a window in which we don't see
- # the attachment (until the attachment completes). We could also
- # get problems with concurrent requests. I think we need an
- # attachment state, and to write to the DB here, but that's a bigger
- # change.
+ # the attachment (until the attachment completes). We could also
+ # get problems with concurrent requests. I think we need an
+ # attachment state, and to write to the DB here, but that's a bigger
+ # change.
# For now, we'll probably have to rely on libraries being smart
- #TODO(justinsb): How do I return "accepted" here?
+ # TODO(justinsb): How do I return "accepted" here?
return {'volumeAttachment': attachment}
def update(self, _req, _server_id, _id):
@@ -147,7 +147,7 @@ class Controller(wsgi.Controller):
return faults.Fault(exc.HTTPBadRequest())
def delete(self, req, server_id, id):
- """Detach a volume from an instance """
+ """Detach a volume from an instance."""
context = req.environ['nova.context']
volume_id = id
@@ -168,7 +168,7 @@ class Controller(wsgi.Controller):
return exc.HTTPAccepted()
def _items(self, req, server_id, entity_maker):
- """Returns a list of attachments, transformed through entity_maker"""
+ """Returns a list of attachments, transformed through entity_maker."""
context = req.environ['nova.context']
try:
diff --git a/nova/api/openstack/incubator/volumes/volumes.py b/nova/api/openstack/incubator/volumes/volumes.py
index e122bb465..a7d5fbaa6 100644
--- a/nova/api/openstack/incubator/volumes/volumes.py
+++ b/nova/api/openstack/incubator/volumes/volumes.py
@@ -31,7 +31,7 @@ FLAGS = flags.FLAGS
def _translate_detail_view(context, vol):
- """Maps keys for details view"""
+ """Maps keys for details view."""
d = _translate_summary_view(context, vol)
@@ -41,7 +41,7 @@ def _translate_detail_view(context, vol):
def _translate_summary_view(_context, vol):
- """Maps keys for summary view"""
+ """Maps keys for summary view."""
d = {}
instance_id = None
@@ -79,7 +79,7 @@ def _translate_summary_view(_context, vol):
class Controller(wsgi.Controller):
- """The Volumes API controller for the OpenStack API"""
+ """The Volumes API controller for the OpenStack API."""
_serialization_metadata = {
'application/xml': {
@@ -99,7 +99,7 @@ class Controller(wsgi.Controller):
super(Controller, self).__init__()
def show(self, req, id):
- """Return data about the given volume"""
+ """Return data about the given volume."""
context = req.environ['nova.context']
try:
@@ -110,7 +110,7 @@ class Controller(wsgi.Controller):
return {'volume': _translate_detail_view(context, vol)}
def delete(self, req, id):
- """Delete a volume """
+ """Delete a volume."""
context = req.environ['nova.context']
LOG.audit(_("Delete volume with id: %s"), id, context=context)
@@ -122,15 +122,15 @@ class Controller(wsgi.Controller):
return exc.HTTPAccepted()
def index(self, req):
- """Returns a summary list of volumes"""
+ """Returns a summary list of volumes."""
return self._items(req, entity_maker=_translate_summary_view)
def detail(self, req):
- """Returns a detailed list of volumes """
+ """Returns a detailed list of volumes."""
return self._items(req, entity_maker=_translate_detail_view)
def _items(self, req, entity_maker):
- """Returns a list of volumes, transformed through entity_maker"""
+ """Returns a list of volumes, transformed through entity_maker."""
context = req.environ['nova.context']
volumes = self.volume_api.get_all(context)
@@ -139,7 +139,7 @@ class Controller(wsgi.Controller):
return {'volumes': res}
def create(self, req):
- """Creates a new volume"""
+ """Creates a new volume."""
context = req.environ['nova.context']
env = self._deserialize(req.body, req.get_content_type())
diff --git a/nova/api/openstack/incubator/volumes/volumes_ext.py b/nova/api/openstack/incubator/volumes/volumes_ext.py
index 87a57320d..6a3bb0265 100644
--- a/nova/api/openstack/incubator/volumes/volumes_ext.py
+++ b/nova/api/openstack/incubator/volumes/volumes_ext.py
@@ -37,8 +37,8 @@ class VolumesExtension(extensions.ExtensionDescriptor):
def get_resources(self):
resources = []
- #NOTE(justinsb): No way to provide singular name ('volume')
- # Does this matter?
+ # NOTE(justinsb): No way to provide singular name ('volume')
+ # Does this matter?
res = extensions.ResourceExtension('volumes',
volumes.Controller(),
collection_actions={'detail': 'GET'}
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index 10636f602..468771f46 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1078,6 +1078,6 @@ class ComputeManager(manager.SchedulerDependentManager):
# Are there VMs not in the DB?
for vm_not_found_in_db in vms_not_found_in_db:
name = vm_not_found_in_db
- #TODO(justinsb): What to do here? Adopt it? Shut it down?
+ # TODO(justinsb): What to do here? Adopt it? Shut it down?
LOG.warning(_("Found VM not in DB: '%(name)s'. Ignoring")
% locals())
diff --git a/nova/image/fake.py b/nova/image/fake.py
index 29159f337..cdb650165 100644
--- a/nova/image/fake.py
+++ b/nova/image/fake.py
@@ -29,11 +29,11 @@ FLAGS = flags.FLAGS
class MockImageService(service.BaseImageService):
- """Mock (fake) image service for unit testing"""
+ """Mock (fake) image service for unit testing."""
def __init__(self):
self.images = {}
- # NOTE(justinsb): The OpenStack API can't upload an image???
+ # NOTE(justinsb): The OpenStack API can't upload an image?
# So, make sure we've got one..
image = {'id': '123456',
'status': 'active',
@@ -46,17 +46,17 @@ class MockImageService(service.BaseImageService):
super(MockImageService, self).__init__()
def index(self, context):
- """Returns list of images"""
+ """Returns list of images."""
return self.images.values()
def detail(self, context):
- """Return list of detailed image information"""
+ """Return list of detailed image information."""
return self.images.values()
def show(self, context, image_id):
- """
- Returns a dict containing image data for the given opaque image id.
- """
+ """Get data about specified image.
+
+ Returns a dict containing image data for the given opaque image id."""
image_id = int(image_id)
image = self.images.get(image_id)
if image:
@@ -66,16 +66,14 @@ class MockImageService(service.BaseImageService):
raise exception.NotFound
def create(self, context, data):
- """
- Store the image data and return the new image id.
+ """Store the image data and return the new image id.
- :raises AlreadyExists if the image already exist.
+ :raises Duplicate if the image already exist.
"""
image_id = int(data['id'])
if self.images.get(image_id):
- #TODO(justinsb): Where is this AlreadyExists exception??
- raise exception.Error("AlreadyExists")
+ raise exception.Duplicate()
self.images[image_id] = data
@@ -91,8 +89,7 @@ class MockImageService(service.BaseImageService):
self.images[image_id] = data
def delete(self, context, image_id):
- """
- Delete the given image.
+ """Delete the given image.
:raises NotFound if the image does not exist.
@@ -103,7 +100,5 @@ class MockImageService(service.BaseImageService):
raise exception.NotFound
def delete_all(self):
- """
- Clears out all images
- """
+ """Clears out all images."""
self.images.clear()