Python signals

Important

If you are adding or changing Fleio files, other than Fleio setting files that are stored in Docker volumes, see Adding or changing files in Fleio Docker images.

Signal listeners (or hooks) are Python callables that are automatically called on certain events. The callable receives relevant parameters in the context of the event. This techniques allows code decoupling: you can change the application behavior without changing the original source code. And therefore, you will not have to merge your changes on every Fleio package upgrade.

Or as Django documentation describes signals:

Django includes a “signal dispatcher” which helps allow decoupled applications get notified when actions occur elsewhere in the framework. In a nutshell, signals allow certain senders to notify a set of receivers that some action has taken place. They’re especially useful when many pieces of code may be interested in the same events.

Django signals

Learn how to write Django signals: https://docs.djangoproject.com/en/2.2/topics/signals/

Signals provided by Django that you can find useful to customize Fleio include:

Django offers

Fleio signals

Fleio will add signals by the same model Django uses signals.

  • boot from ISO signal

In the 2019.09.0 release we have implemented a new signal for instances that are booted from ISO. In order to use the signal you need to add the following code inside the settings.py file:

from fleio.openstack.signals.signals import instance_boot_from_iso
from django.dispatch import receiver
@receiver(instance_boot_from_iso, dispatch_uid='instance_boot_from_iso_demo')
def instance_boot_from_iso(sender, **kwargs):
   instance_id = kwargs['instance_id']
   is_new_instance = kwargs['is_new_instance']
   print('Instance {} was booted from ISO. Instance is new: {}'.format(instance_id, is_new_instance))

This will add a new entry in the celery log each time an instance is booted from ISO.

Need a signal? Contact us and asked for it.