diff --git a/reddwarf/guestagent/api.py b/reddwarf/guestagent/api.py index ada76620e2..0984facc00 100644 --- a/reddwarf/guestagent/api.py +++ b/reddwarf/guestagent/api.py @@ -26,7 +26,6 @@ from reddwarf.common import config from reddwarf.common import exception from reddwarf.common import utils # from nova.db import api as dbapi -# from nova.db import base LOG = logging.getLogger(__name__) @@ -123,7 +122,6 @@ class API(object): """Make an asynchronous call to prepare the guest as a database container""" 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), {"method": "prepare", "args": {"databases": databases, diff --git a/reddwarf/guestagent/dbaas.py b/reddwarf/guestagent/dbaas.py index 472d811d78..bba36d3f66 100644 --- a/reddwarf/guestagent/dbaas.py +++ b/reddwarf/guestagent/dbaas.py @@ -256,11 +256,11 @@ class DBaaSAgent(object): LOG.debug("result = " + str(result)) return result.rowcount != 0 - def prepare(self, databases): + def prepare(self, databases, memory_mb): """Makes ready DBAAS on a Guest container.""" global PREPARING PREPARING = True - from reddwarf.guest.pkg import PkgAgent + from reddwarf.guestagent.pkg import PkgAgent if not isinstance(self, PkgAgent): raise TypeError("This must also be an instance of Pkg agent.") preparer = DBaaSPreparer(self) diff --git a/reddwarf/instance/service.py b/reddwarf/instance/service.py index 47d0e589b8..c1142e6f98 100644 --- a/reddwarf/instance/service.py +++ b/reddwarf/instance/service.py @@ -24,6 +24,7 @@ from reddwarf.common import context as rd_context from reddwarf.common import exception from reddwarf.common import utils from reddwarf.common import wsgi +from reddwarf.guestagent import api as guest_api from reddwarf.instance import models, views CONFIG = config.Config @@ -139,6 +140,7 @@ class InstanceController(BaseController): body).data() # 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 return wsgi.Result(views.InstanceView(server).data(), 201) diff --git a/reddwarf/rpc/__init__.py b/reddwarf/rpc/__init__.py index 0dfc44686d..22dc0a14ee 100644 --- a/reddwarf/rpc/__init__.py +++ b/reddwarf/rpc/__init__.py @@ -82,6 +82,23 @@ def 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): """Broadcast a remote method invocation with no return. diff --git a/reddwarf/rpc/amqp.py b/reddwarf/rpc/amqp.py index a5a3b1feef..5bcd2506e8 100644 --- a/reddwarf/rpc/amqp.py +++ b/reddwarf/rpc/amqp.py @@ -349,6 +349,15 @@ def cast(context, topic, msg, connection_pool): 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): """Sends a message on a fanout exchange without waiting for a response.""" LOG.debug(_('Making asynchronous fanout cast...')) diff --git a/reddwarf/rpc/impl_kombu.py b/reddwarf/rpc/impl_kombu.py index 682ff8339a..8960a0fbe4 100644 --- a/reddwarf/rpc/impl_kombu.py +++ b/reddwarf/rpc/impl_kombu.py @@ -668,6 +668,11 @@ def cast(context, topic, msg): 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): """Sends a message on a fanout exchange without waiting for a response.""" return rpc_amqp.fanout_cast(context, topic, msg, Connection.pool)