Add hooks to obtain conductor api
To obtain conductor api instance easily, this add rpcapi attribute to pecan.request. So now, we can access to conductor api from "pecan.request.rpcapi". Related-Bug: #1406539 Change-Id: I6edbf031d91e65d70637629c3b57d45322eee9fd
This commit is contained in:
parent
c6c606b277
commit
a7a4544033
@ -22,7 +22,8 @@ app = {
|
|||||||
'modules': ['magnum.api'],
|
'modules': ['magnum.api'],
|
||||||
'debug': False,
|
'debug': False,
|
||||||
'hooks': [
|
'hooks': [
|
||||||
hooks.ContextHook()
|
hooks.ContextHook(),
|
||||||
|
hooks.RPCHook(),
|
||||||
],
|
],
|
||||||
'acl_public_routes': [
|
'acl_public_routes': [
|
||||||
'/'
|
'/'
|
||||||
|
@ -307,18 +307,8 @@ class BaysController(rest.RestController):
|
|||||||
if rpc_bay[field] != patch_val:
|
if rpc_bay[field] != patch_val:
|
||||||
rpc_bay[field] = patch_val
|
rpc_bay[field] = patch_val
|
||||||
|
|
||||||
if hasattr(pecan.request, 'rpcapi'):
|
rpc_bay.save()
|
||||||
rpc_bay = objects.Bay.get_by_id(pecan.request.context,
|
return Bay.convert_with_links(rpc_bay)
|
||||||
rpc_bay.bay_id)
|
|
||||||
topic = pecan.request.rpcapi.get_topic_for(rpc_bay)
|
|
||||||
|
|
||||||
new_bay = pecan.request.rpcapi.update_bay(
|
|
||||||
pecan.request.context, rpc_bay, topic)
|
|
||||||
|
|
||||||
return Bay.convert_with_links(new_bay)
|
|
||||||
else:
|
|
||||||
rpc_bay.save()
|
|
||||||
return Bay.convert_with_links(rpc_bay)
|
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
||||||
def delete(self, bay_uuid):
|
def delete(self, bay_uuid):
|
||||||
|
@ -309,18 +309,8 @@ class BayModelsController(rest.RestController):
|
|||||||
if rpc_baymodel[field] != patch_val:
|
if rpc_baymodel[field] != patch_val:
|
||||||
rpc_baymodel[field] = patch_val
|
rpc_baymodel[field] = patch_val
|
||||||
|
|
||||||
if hasattr(pecan.request, 'rpcapi'):
|
rpc_baymodel.save()
|
||||||
rpc_baymodel = objects.BayModel.get_by_id(pecan.request.context,
|
return BayModel.convert_with_links(rpc_baymodel)
|
||||||
rpc_baymodel.baymodel_id)
|
|
||||||
topic = pecan.request.rpcapi.get_topic_for(rpc_baymodel)
|
|
||||||
|
|
||||||
new_baymodel = pecan.request.rpcapi.update_baymodel(
|
|
||||||
pecan.request.context, rpc_baymodel, topic)
|
|
||||||
|
|
||||||
return BayModel.convert_with_links(new_baymodel)
|
|
||||||
else:
|
|
||||||
rpc_baymodel.save()
|
|
||||||
return BayModel.convert_with_links(rpc_baymodel)
|
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
||||||
def delete(self, baymodel_uuid):
|
def delete(self, baymodel_uuid):
|
||||||
|
@ -379,18 +379,8 @@ class ContainersController(rest.RestController):
|
|||||||
if rpc_container[field] != patch_val:
|
if rpc_container[field] != patch_val:
|
||||||
rpc_container[field] = patch_val
|
rpc_container[field] = patch_val
|
||||||
|
|
||||||
if hasattr(pecan.request, 'rpcapi'):
|
rpc_container.save()
|
||||||
rpc_container = objects.Container.get_by_id(pecan.request.context,
|
return Container.convert_with_links(rpc_container)
|
||||||
rpc_container.container_id)
|
|
||||||
topic = pecan.request.rpcapi.get_topic_for(rpc_container)
|
|
||||||
|
|
||||||
new_container = pecan.request.rpcapi.update_container(
|
|
||||||
pecan.request.context, rpc_container, topic)
|
|
||||||
|
|
||||||
return Container.convert_with_links(new_container)
|
|
||||||
else:
|
|
||||||
rpc_container.save()
|
|
||||||
return Container.convert_with_links(rpc_container)
|
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
||||||
def delete(self, container_uuid):
|
def delete(self, container_uuid):
|
||||||
|
@ -298,18 +298,8 @@ class NodesController(rest.RestController):
|
|||||||
if rpc_node[field] != patch_val:
|
if rpc_node[field] != patch_val:
|
||||||
rpc_node[field] = patch_val
|
rpc_node[field] = patch_val
|
||||||
|
|
||||||
if hasattr(pecan.request, 'rpcapi'):
|
rpc_node.save()
|
||||||
rpc_node = objects.Node.get_by_id(pecan.request.context,
|
return Node.convert_with_links(rpc_node)
|
||||||
rpc_node.node_id)
|
|
||||||
topic = pecan.request.rpcapi.get_topic_for(rpc_node)
|
|
||||||
|
|
||||||
new_node = pecan.request.rpcapi.update_node(
|
|
||||||
pecan.request.context, rpc_node, topic)
|
|
||||||
|
|
||||||
return Node.convert_with_links(new_node)
|
|
||||||
else:
|
|
||||||
rpc_node.save()
|
|
||||||
return Node.convert_with_links(rpc_node)
|
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
||||||
def delete(self, node_uuid):
|
def delete(self, node_uuid):
|
||||||
|
@ -304,18 +304,8 @@ class PodsController(rest.RestController):
|
|||||||
if rpc_pod[field] != patch_val:
|
if rpc_pod[field] != patch_val:
|
||||||
rpc_pod[field] = patch_val
|
rpc_pod[field] = patch_val
|
||||||
|
|
||||||
if hasattr(pecan.request, 'rpcapi'):
|
rpc_pod.save()
|
||||||
rpc_pod = objects.Pod.get_by_id(pecan.request.context,
|
return Pod.convert_with_links(rpc_pod)
|
||||||
rpc_pod.pod_id)
|
|
||||||
topic = pecan.request.rpcapi.get_topic_for(rpc_pod)
|
|
||||||
|
|
||||||
new_pod = pecan.request.rpcapi.update_pod(
|
|
||||||
pecan.request.context, rpc_pod, topic)
|
|
||||||
|
|
||||||
return Pod.convert_with_links(new_pod)
|
|
||||||
else:
|
|
||||||
rpc_pod.save()
|
|
||||||
return Pod.convert_with_links(rpc_pod)
|
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
||||||
def delete(self, pod_uuid):
|
def delete(self, pod_uuid):
|
||||||
|
@ -287,18 +287,8 @@ class ServicesController(rest.RestController):
|
|||||||
if rpc_service[field] != patch_val:
|
if rpc_service[field] != patch_val:
|
||||||
rpc_service[field] = patch_val
|
rpc_service[field] = patch_val
|
||||||
|
|
||||||
if hasattr(pecan.request, 'rpcapi'):
|
rpc_service.save()
|
||||||
rpc_service = objects.Service.get_by_id(pecan.request.context,
|
return Service.convert_with_links(rpc_service)
|
||||||
rpc_service.service_id)
|
|
||||||
topic = pecan.request.rpcapi.get_topic_for(rpc_service)
|
|
||||||
|
|
||||||
new_service = pecan.request.rpcapi.update_service(
|
|
||||||
pecan.request.context, rpc_service, topic)
|
|
||||||
|
|
||||||
return Service.convert_with_links(new_service)
|
|
||||||
else:
|
|
||||||
rpc_service.save()
|
|
||||||
return Service.convert_with_links(rpc_service)
|
|
||||||
|
|
||||||
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
@wsme_pecan.wsexpose(None, types.uuid, status_code=204)
|
||||||
def delete(self, service_uuid):
|
def delete(self, service_uuid):
|
||||||
|
@ -22,6 +22,7 @@ from oslo.utils import importutils
|
|||||||
from pecan import hooks
|
from pecan import hooks
|
||||||
|
|
||||||
from magnum.common import context
|
from magnum.common import context
|
||||||
|
from magnum.conductor import api as conductor_api
|
||||||
|
|
||||||
|
|
||||||
class ContextHook(hooks.PecanHook):
|
class ContextHook(hooks.PecanHook):
|
||||||
@ -64,4 +65,11 @@ class ContextHook(hooks.PecanHook):
|
|||||||
user=user_id,
|
user=user_id,
|
||||||
tenant=tenant,
|
tenant=tenant,
|
||||||
domain_id=domain_id,
|
domain_id=domain_id,
|
||||||
domain_name=domain_name)
|
domain_name=domain_name)
|
||||||
|
|
||||||
|
|
||||||
|
class RPCHook(hooks.PecanHook):
|
||||||
|
"""Attach the rpcapi object to the request so controllers can get to it."""
|
||||||
|
|
||||||
|
def before(self, state):
|
||||||
|
state.request.rpcapi = conductor_api.API(context=state.request.context)
|
@ -25,6 +25,7 @@ app = {
|
|||||||
'debug': True,
|
'debug': True,
|
||||||
'hooks': [
|
'hooks': [
|
||||||
hooks.ContextHook(),
|
hooks.ContextHook(),
|
||||||
|
hooks.RPCHook()
|
||||||
],
|
],
|
||||||
'acl_public_routes': [
|
'acl_public_routes': [
|
||||||
'/'
|
'/'
|
||||||
|
Loading…
Reference in New Issue
Block a user