Merge "Format each container inside capsule"
This commit is contained in:
commit
e370dd0c61
@ -68,9 +68,10 @@ class CapsuleCollection(collection.Collection):
|
||||
@staticmethod
|
||||
def convert_with_links(rpc_capsules, limit, url=None,
|
||||
expand=False, **kwargs):
|
||||
context = pecan.request.context
|
||||
collection = CapsuleCollection()
|
||||
collection.capsules = \
|
||||
[view.format_capsule(url, p) for p in rpc_capsules]
|
||||
[view.format_capsule(url, p, context) for p in rpc_capsules]
|
||||
collection.next = collection.get_next(limit, url=url, **kwargs)
|
||||
return collection
|
||||
|
||||
@ -260,7 +261,8 @@ class CapsuleController(base.Controller):
|
||||
new_capsule.uuid)
|
||||
|
||||
pecan.response.status = 202
|
||||
return view.format_capsule(pecan.request.host_url, new_capsule)
|
||||
return view.format_capsule(pecan.request.host_url, new_capsule,
|
||||
context)
|
||||
|
||||
@pecan.expose('json')
|
||||
@exception.wrap_pecan_controller_exception
|
||||
@ -269,9 +271,10 @@ class CapsuleController(base.Controller):
|
||||
|
||||
:param capsule_ident: UUID or name of a capsule.
|
||||
"""
|
||||
context = pecan.request.context
|
||||
capsule = _get_capsule(capsule_ident)
|
||||
check_policy_on_capsule(capsule.as_dict(), "capsule:get")
|
||||
return view.format_capsule(pecan.request.host_url, capsule)
|
||||
return view.format_capsule(pecan.request.host_url, capsule, context)
|
||||
|
||||
@pecan.expose('json')
|
||||
@exception.wrap_pecan_controller_exception
|
||||
|
@ -73,7 +73,8 @@ class ContainerCollection(collection.Collection):
|
||||
context = pecan.request.context
|
||||
collection = ContainerCollection()
|
||||
collection.containers = \
|
||||
[view.format_container(context, url, p) for p in rpc_containers]
|
||||
[view.format_container(context, url, p.as_dict())
|
||||
for p in rpc_containers]
|
||||
collection.next = collection.get_next(limit, url=url, **kwargs)
|
||||
return collection
|
||||
|
||||
@ -264,7 +265,7 @@ class ContainersController(base.Controller):
|
||||
raise exception.ServerNotUsable
|
||||
|
||||
return view.format_container(context, pecan.request.host_url,
|
||||
container)
|
||||
container.as_dict())
|
||||
|
||||
def _generate_name_for_container(self):
|
||||
"""Generate a random name like: zeta-22-container."""
|
||||
@ -396,7 +397,7 @@ class ContainersController(base.Controller):
|
||||
new_container.uuid)
|
||||
pecan.response.status = 202
|
||||
return view.format_container(context, pecan.request.host_url,
|
||||
new_container)
|
||||
new_container.as_dict())
|
||||
|
||||
def _set_default_resource_limit(self, container_dict):
|
||||
# NOTE(kiennt): Default disk size will be set later.
|
||||
@ -600,7 +601,7 @@ class ContainersController(base.Controller):
|
||||
compute_api = pecan.request.compute_api
|
||||
container = compute_api.container_update(context, container, patch)
|
||||
return view.format_container(context, pecan.request.host_url,
|
||||
container)
|
||||
container.as_dict())
|
||||
|
||||
@base.Controller.api_version("1.1", "1.13")
|
||||
@pecan.expose('json')
|
||||
@ -621,7 +622,7 @@ class ContainersController(base.Controller):
|
||||
context = pecan.request.context
|
||||
container.save(context)
|
||||
return view.format_container(context, pecan.request.host_url,
|
||||
container)
|
||||
container.as_dict())
|
||||
|
||||
@base.Controller.api_version("1.19")
|
||||
@pecan.expose('json')
|
||||
@ -646,7 +647,7 @@ class ContainersController(base.Controller):
|
||||
compute_api.resize_container(context, container, kwargs)
|
||||
pecan.response.status = 202
|
||||
return view.format_container(context, pecan.request.host_url,
|
||||
container)
|
||||
container.as_dict())
|
||||
|
||||
@pecan.expose('json')
|
||||
@exception.wrap_pecan_controller_exception
|
||||
|
@ -15,6 +15,7 @@
|
||||
import itertools
|
||||
|
||||
from zun.api.controllers import link
|
||||
from zun.api.controllers.v1.views import containers_view
|
||||
|
||||
|
||||
_basic_keys = (
|
||||
@ -39,7 +40,7 @@ _basic_keys = (
|
||||
)
|
||||
|
||||
|
||||
def format_capsule(url, capsule):
|
||||
def format_capsule(url, capsule, context):
|
||||
def transform(key, value):
|
||||
if key not in _basic_keys:
|
||||
return
|
||||
@ -51,6 +52,13 @@ def format_capsule(url, capsule):
|
||||
'bookmark', url,
|
||||
'capsules', value,
|
||||
bookmark=True)])
|
||||
elif key == 'containers':
|
||||
containers = []
|
||||
for c in value:
|
||||
container = containers_view.format_container(
|
||||
context, None, c)
|
||||
containers.append(container)
|
||||
yield ('containers', containers)
|
||||
else:
|
||||
yield (key, value)
|
||||
|
||||
|
@ -60,14 +60,15 @@ def format_container(context, url, container):
|
||||
return
|
||||
if key == 'uuid':
|
||||
yield ('uuid', value)
|
||||
yield ('links', [link.make_link(
|
||||
'self', url, 'containers', value),
|
||||
link.make_link(
|
||||
'bookmark', url,
|
||||
'containers', value,
|
||||
bookmark=True)])
|
||||
if url:
|
||||
yield ('links', [link.make_link(
|
||||
'self', url, 'containers', value),
|
||||
link.make_link(
|
||||
'bookmark', url,
|
||||
'containers', value,
|
||||
bookmark=True)])
|
||||
else:
|
||||
yield (key, value)
|
||||
|
||||
return dict(itertools.chain.from_iterable(
|
||||
transform(k, v) for k, v in container.as_dict().items()))
|
||||
transform(k, v) for k, v in container.items()))
|
||||
|
Loading…
Reference in New Issue
Block a user