[Openstack] Running code on instance start/terminate

Andrew Bogott abogott at wikimedia.org
Mon Mar 26 15:59:09 UTC 2012


Rogerio --

> I'm developing a application to work along with openstack. My 
> application needs to keep track of all instances being started or 
> terminated such as feeding it information about the location, status 
> and other information about launched and terminated instances.

Nova already includes a notification framework which works well for this 
sort of thing.

If you want your code to run on a different host or even a separate 
process, you should enable queue-based notifications on nova commandline 
with something like

--notification_driver = nova.notifier.rabbit_notifier

Then you can set up your code as a queue consumer to receive these messages.

That's not the approach that I'm using currently, though.  What I did is 
easier but somewhat more intrusive:  I wrote a custom notification 
driver that checks for interesting messages and does my work inline.

--notification_driver = nova.notifier.list_notifier
--list_notifier_drivers = nova.sharedfs.sharedfs_notifier.SharedFSNotifier

That results in SharedFSNotifier's notify(message) function getting 
called for each notification, where it vets the messages and responds as 
needed:

         event_type = message.get('event_type')
         if event_type not in ['compute.instance.delete.start',
                               'compute.instance.create.end']:
         etc.

You can see the complete class in this patch:  
https://review.openstack.org/#change,5292 .  Look for the file 
'sharedfs_notifier.py'.

Hope that helps!

-Andrew
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack/attachments/20120326/c05ae243/attachment.html>


More information about the Openstack mailing list