summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-03-17 12:31:16 -0400
committerBrian Waldon <brian.waldon@rackspace.com>2011-03-17 12:31:16 -0400
commitc1f7df80d22b718bc96332c2f52354627d11700d (patch)
tree0044f6eceb1e50205d04b8b3c275dcaa42d5dcff /nova
parent05ccc91bdb3ad47ffecee29d21835ded17f65816 (diff)
adding comments; removing returns from build_extra; removing unnecessary backslash
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/flavors.py2
-rw-r--r--nova/api/openstack/views/flavors.py26
2 files changed, 21 insertions, 7 deletions
diff --git a/nova/api/openstack/flavors.py b/nova/api/openstack/flavors.py
index bc61e8d1a..6eba0f9b8 100644
--- a/nova/api/openstack/flavors.py
+++ b/nova/api/openstack/flavors.py
@@ -46,7 +46,7 @@ class Controller(wsgi.Controller):
ctxt = req.environ['nova.context']
flavors = db.api.instance_type_get_all(ctxt)
builder = flavors_views.get_view_builder(req)
- items = [builder.build(flavor, is_detail=is_detail) \
+ items = [builder.build(flavor, is_detail=is_detail)
for flavor in flavors.values()]
return items
diff --git a/nova/api/openstack/views/flavors.py b/nova/api/openstack/views/flavors.py
index 7d75c0aa2..92003a19f 100644
--- a/nova/api/openstack/views/flavors.py
+++ b/nova/api/openstack/views/flavors.py
@@ -32,26 +32,27 @@ def get_view_builder(req):
class ViewBuilder(object):
- def __init__(self):
- pass
def build(self, flavor_obj, is_detail=False):
+ """Generic method used to generate a flavor entity."""
if is_detail:
flavor = self._build_detail(flavor_obj)
else:
flavor = self._build_simple(flavor_obj)
- full_flavor = self._build_extra(flavor)
+ self._build_extra(flavor)
- return full_flavor
+ return flavor
def _build_simple(self, flavor_obj):
+ """Build a minimal representation of a flavor."""
return {
"id": flavor_obj["flavorid"],
"name": flavor_obj["name"],
}
def _build_detail(self, flavor_obj):
+ """Build a more complete representation of a flavor."""
simple = self._build_simple(flavor_obj)
detail = {
@@ -64,19 +65,26 @@ class ViewBuilder(object):
return detail
def _build_extra(self, flavor_obj):
- return flavor_obj
+ """Hook for version-specific changes to newly created flavor object."""
+ pass
class ViewBuilder_1_1(ViewBuilder):
+ """Openstack API v1.1 flavors view builder."""
+
def __init__(self, base_url):
+ """
+ :param base_url: url of the root wsgi application
+ """
self.base_url = base_url
def _build_extra(self, flavor_obj):
flavor_obj["links"] = self._build_links(flavor_obj)
- return flavor_obj
def _build_links(self, flavor_obj):
+ """Generate a container of links that refer to the provided flavor."""
href = self.generate_href(flavor_obj["id"])
+
links = [
{
"rel": "self",
@@ -93,11 +101,17 @@ class ViewBuilder_1_1(ViewBuilder):
"href": href,
},
]
+
return links
def generate_href(self, flavor_id):
+ """Create an url that refers to a specific flavor id."""
return "%s/flavors/%s" % (self.base_url, flavor_id)
class ViewBuilder_1_0(ViewBuilder):
+ """
+ Openstack API v1.0 flavors view builder. Currently, there
+ are no 1.0-specific attributes of a flavor.
+ """
pass