Listening to notification after creation of instance in Openstack

446 views Asked by At

Am interested in finding out if there is a way to create a listener within openstack which gets notified every time a new instance gets created.

2

There are 2 answers

0
Max Lobur On

Try to take a look at OpenStack workload measuring project https://launchpad.net/ceilometer

0
YBathia On

One way to do this is by using Django signals. So, you can create a signal and send it after the line of code which creates an instance. The function which expects the notification can be made the receiver which listens to this signal. The function will wait till it receives the signal.As an example:

#Declaring a signal
from django.dispatch import Signal
instance_signal = Signal(providing_args=['param1', 'param2'])


#function that sends the signal
def instance_create():
--code that creates the instance  
instance_signal.send(sender='instance_create', param1='I am param 1', param2='I am param 2')


#Defining the function that listens to this signal(the receiver)
def notify_me(**kwargs):
x, y= kwargs['param1'], kwargs['param2']



#Connect the signal to the receiver (Can be written anywhere in the code)
instance_signal.connect(notify_me)

The best part about Django Signals is that you can create the signal, the receiver function and connect them anywhere in the whole application. Django Signals are very useful in scheduling tasks or in your case, receiving notifications.