Furthering the guest agent prepare call

* Fixed minor guestagent bugs
* Added cast_with_consumer
* Added rpc call to instances
This commit is contained in:
Michael Basnight 2012-03-18 21:49:17 -05:00
parent 2bdaa9d8fc
commit 51454ac504
6 changed files with 35 additions and 4 deletions

View File

@ -26,7 +26,6 @@ from reddwarf.common import config
from reddwarf.common import exception from reddwarf.common import exception
from reddwarf.common import utils from reddwarf.common import utils
# from nova.db import api as dbapi # from nova.db import api as dbapi
# from nova.db import base
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -123,7 +122,6 @@ class API(object):
"""Make an asynchronous call to prepare the guest """Make an asynchronous call to prepare the guest
as a database container""" as a database container"""
LOG.debug(_("Sending the call to prepare the Guest")) LOG.debug(_("Sending the call to prepare the Guest"))
#TODO(hub-cap): add this to the kombu api
rpc.cast_with_consumer(context, self._get_routing_key(context, id), rpc.cast_with_consumer(context, self._get_routing_key(context, id),
{"method": "prepare", {"method": "prepare",
"args": {"databases": databases, "args": {"databases": databases,

View File

@ -256,11 +256,11 @@ class DBaaSAgent(object):
LOG.debug("result = " + str(result)) LOG.debug("result = " + str(result))
return result.rowcount != 0 return result.rowcount != 0
def prepare(self, databases): def prepare(self, databases, memory_mb):
"""Makes ready DBAAS on a Guest container.""" """Makes ready DBAAS on a Guest container."""
global PREPARING global PREPARING
PREPARING = True PREPARING = True
from reddwarf.guest.pkg import PkgAgent from reddwarf.guestagent.pkg import PkgAgent
if not isinstance(self, PkgAgent): if not isinstance(self, PkgAgent):
raise TypeError("This must also be an instance of Pkg agent.") raise TypeError("This must also be an instance of Pkg agent.")
preparer = DBaaSPreparer(self) preparer = DBaaSPreparer(self)

View File

@ -24,6 +24,7 @@ from reddwarf.common import context as rd_context
from reddwarf.common import exception from reddwarf.common import exception
from reddwarf.common import utils from reddwarf.common import utils
from reddwarf.common import wsgi from reddwarf.common import wsgi
from reddwarf.guestagent import api as guest_api
from reddwarf.instance import models, views from reddwarf.instance import models, views
CONFIG = config.Config CONFIG = config.Config
@ -139,6 +140,7 @@ class InstanceController(BaseController):
body).data() body).data()
# Now wait for the response from the create to do additional work # Now wait for the response from the create to do additional work
guest_api.API().prepare(context, server['id'], [], 512)
#TODO(cp16net): need to set the return code correctly #TODO(cp16net): need to set the return code correctly
return wsgi.Result(views.InstanceView(server).data(), 201) return wsgi.Result(views.InstanceView(server).data(), 201)

View File

@ -82,6 +82,23 @@ def cast(context, topic, msg):
return _get_impl().cast(context, topic, msg) return _get_impl().cast(context, topic, msg)
def cast_with_consumer(context, topic, msg):
"""Invoke a remote method that does not return anything.
:param context: Information that identifies the user that has made this
request.
:param topic: The topic to send the rpc message to. This correlates to the
topic argument of
nova.rpc.common.Connection.create_consumer() and only applies
when the consumer was created with fanout=False.
:param msg: This is a dict in the form { "method" : "method_to_invoke",
"args" : dict_of_kwargs }
:returns: None
"""
return _get_impl().cast_with_consumer(context, topic, msg)
def fanout_cast(context, topic, msg): def fanout_cast(context, topic, msg):
"""Broadcast a remote method invocation with no return. """Broadcast a remote method invocation with no return.

View File

@ -349,6 +349,15 @@ def cast(context, topic, msg, connection_pool):
conn.topic_send(topic, msg) conn.topic_send(topic, msg)
def cast_with_consumer(context, topic, msg, connection_pool):
"""Sends a message on a topic without waiting for a response."""
LOG.debug(_('Making asynchronous cast on %s...'), topic)
pack_context(msg, context)
with ConnectionContext(connection_pool) as conn:
consumer = conn.declare_topic_consumer(topic=topic)
conn.topic_send(topic, msg)
def fanout_cast(context, topic, msg, connection_pool): def fanout_cast(context, topic, msg, connection_pool):
"""Sends a message on a fanout exchange without waiting for a response.""" """Sends a message on a fanout exchange without waiting for a response."""
LOG.debug(_('Making asynchronous fanout cast...')) LOG.debug(_('Making asynchronous fanout cast...'))

View File

@ -668,6 +668,11 @@ def cast(context, topic, msg):
return rpc_amqp.cast(context, topic, msg, Connection.pool) return rpc_amqp.cast(context, topic, msg, Connection.pool)
def cast_with_consumer(context, topic, msg):
"""Sends a message on a topic without waiting for a response."""
return rpc_amqp.cast(context, topic, msg, Connection.pool)
def fanout_cast(context, topic, msg): def fanout_cast(context, topic, msg):
"""Sends a message on a fanout exchange without waiting for a response.""" """Sends a message on a fanout exchange without waiting for a response."""
return rpc_amqp.fanout_cast(context, topic, msg, Connection.pool) return rpc_amqp.fanout_cast(context, topic, msg, Connection.pool)