Revision history [back]

click to hide/show revision 1
initial version

How to fill context for rpc call when calling heat engine

I have created heat extension which listens nova notifications "notifications.info" and does actions for instances in stacks accordingly (e.g. instance stopped could restart instance in stack). After received the notification I'm calling heat engine through RPC mechanism (i.e. using heat/heat/rpc/client.py and EngineClient class from there).

The problem is how to fill the context parameter correctly when calling heat engine? E.g. when I call set_watch_state(ctxt, watch_name, state) i.e. want to set alarm (whihc has restarter policy in my template). How to fill ctxt parameter correctly concerning passwords?

I can get stack related context from heat db with

        rs = db_api.resource_get_by_physical_resource_id(None, instance_id)
        if not rs:
            LOG.debug("No stack found for stopped instance '%s'. Do nothing." % instance_id)
            return                

        user_creds = db_api.user_creds_get(rs.stack.user_creds_id)
        stack_context = context.RequestContext.from_dict(user_creds)

with instanceId and then use stack_context successfully in any further db reads etc. But when using the same context in rpc call it fails to utf8 encoding as "password" and "service_password" are in some odd format when read from db.

Everything works if I in the code assign stack_context.password = "root" #my admin password happens to be root stack_context.service_password = "" # just set it empty to avoid utf8 encoding error

So how I get the password correctly?