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