summaryrefslogtreecommitdiffstats
path: root/nova/rpc.py
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@yahoo.com>2010-10-01 05:57:17 -0700
committerVishvananda Ishaya <vishvananda@yahoo.com>2010-10-01 05:57:17 -0700
commit5e3da5864825a12da5a1ea1102a6efb6cebe204b (patch)
tree3bf2321dd436f6abb0c03e6aeee932f08ae8b018 /nova/rpc.py
parent4d13a8554459638387d772a23fffe6aaaab3348d (diff)
downloadnova-5e3da5864825a12da5a1ea1102a6efb6cebe204b.tar.gz
nova-5e3da5864825a12da5a1ea1102a6efb6cebe204b.tar.xz
nova-5e3da5864825a12da5a1ea1102a6efb6cebe204b.zip
Fix the deprecation warnings for passing no context.
Moved RequestContext out of nova.api, because it is used by everything Context is passed through the queue. Added some helper methods for converting to admin context. Added a few more fields to request context.
Diffstat (limited to 'nova/rpc.py')
-rw-r--r--nova/rpc.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/nova/rpc.py b/nova/rpc.py
index fe52ad35f..26eff9c55 100644
--- a/nova/rpc.py
+++ b/nova/rpc.py
@@ -34,7 +34,7 @@ from twisted.internet import task
from nova import exception
from nova import fakerabbit
from nova import flags
-
+from nova import context
FLAGS = flags.FLAGS
@@ -151,6 +151,8 @@ class AdapterConsumer(TopicConsumer):
"""
LOG.debug('received %s' % (message_data))
msg_id = message_data.pop('_msg_id', None)
+ dict_context = message_data.pop('_context')
+ ctxt = context.RequestContext.from_dict(dict_context)
method = message_data.get('method')
args = message_data.get('args', {})
@@ -168,7 +170,7 @@ class AdapterConsumer(TopicConsumer):
node_args = dict((str(k), v) for k, v in args.iteritems())
# NOTE(vish): magic is fun!
# pylint: disable-msg=W0142
- d = defer.maybeDeferred(node_func, **node_args)
+ d = defer.maybeDeferred(node_func, context=ctxt, **node_args)
if msg_id:
d.addCallback(lambda rval: msg_reply(msg_id, rval, None))
d.addErrback(lambda e: msg_reply(msg_id, None, e))
@@ -247,12 +249,13 @@ class RemoteError(exception.Error):
traceback))
-def call(topic, msg):
+def call(context, topic, msg):
"""Sends a message on a topic and wait for a response"""
LOG.debug("Making asynchronous call...")
msg_id = uuid.uuid4().hex
msg.update({'_msg_id': msg_id})
LOG.debug("MSG_ID is %s" % (msg_id))
+ msg.update({'_context': context})
class WaitMessage(object):
@@ -282,12 +285,13 @@ def call(topic, msg):
return wait_msg.result
-def call_twisted(topic, msg):
+def call_twisted(context, topic, msg):
"""Sends a message on a topic and wait for a response"""
LOG.debug("Making asynchronous call...")
msg_id = uuid.uuid4().hex
msg.update({'_msg_id': msg_id})
LOG.debug("MSG_ID is %s" % (msg_id))
+ msg.update({'_context': context.to_dict()})
conn = Connection.instance()
d = defer.Deferred()
@@ -313,9 +317,10 @@ def call_twisted(topic, msg):
return d
-def cast(topic, msg):
+def cast(context, topic, msg):
"""Sends a message on a topic without waiting for a response"""
LOG.debug("Making asynchronous cast...")
+ msg.update({'_context': context.to_dict()})
conn = Connection.instance()
publisher = TopicPublisher(connection=conn, topic=topic)
publisher.send(msg)