Signals and Receivers

Signals of the infrastructure app.

They are sent by the infrastructure services, smarter.apps.infrastructure.services, whichever cloud provider implements them, so that the platform can observe its infrastructure, e.g. to audit or meter the billable resources that it creates, without knowing which cloud it runs on. The sender is the service’s class.

Every signal has the arguments service, the name of the service, e.g. dns (see InfrastructureServiceNames), and provider, the name of the cloud provider, e.g. aws, plus those listed.

Resource signals also have resource_type, e.g. dns.zone, and resource_name, e.g. example.com, and resource_id once the provider has assigned one.

Example:

from django.dispatch import receiver
from smarter.apps.infrastructure.signals import billable_resource_created

@receiver(billable_resource_created)
def meter(sender, service, provider, resource_type, resource_name, resource_id, **kwargs):
    ...
smarter.apps.infrastructure.signals.billable_resource_created = <django.dispatch.dispatcher.Signal object>

Sent after a service creates a resource that its provider bills for.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.billable_resource_creating = <django.dispatch.dispatcher.Signal object>

Sent before a service creates a resource that its provider bills for, e.g. a DNS zone.

Arguments: service, provider, resource_type, resource_name.

smarter.apps.infrastructure.signals.billable_resource_destroyed = <django.dispatch.dispatcher.Signal object>

Sent after a service destroys a resource that its provider bills for.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.billable_resource_destroying = <django.dispatch.dispatcher.Signal object>

Sent before a service destroys a resource that its provider bills for.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.email_failed = <django.dispatch.dispatcher.Signal object>

Sent when an email cannot be sent.

Arguments: service, provider, subject (str), recipients (list[str]), error (str).

smarter.apps.infrastructure.signals.email_sent = <django.dispatch.dispatcher.Signal object>

Sent after an email is sent.

Arguments: service, provider, subject (str), recipients (list[str]).

smarter.apps.infrastructure.signals.infrastructure_authenticated = <django.dispatch.dispatcher.Signal object>

Sent when a provider authenticates with its cloud, the first time and after a failure.

Arguments: service, provider, identity (dict), the provider’s account identity, e.g. its account id.

smarter.apps.infrastructure.signals.infrastructure_authentication_failed = <django.dispatch.dispatcher.Signal object>

Sent when a provider cannot authenticate with its cloud, the first time and after a success.

Arguments: service, provider, error (str).

smarter.apps.infrastructure.signals.infrastructure_connected = <django.dispatch.dispatcher.Signal object>

Sent when a service connects to its backend, e.g. a Kubernetes cluster, or a cloud API.

Arguments: service, provider.

smarter.apps.infrastructure.signals.infrastructure_connection_failed = <django.dispatch.dispatcher.Signal object>

Sent when a service cannot connect to its backend.

Arguments: service, provider, error (str).

smarter.apps.infrastructure.signals.infrastructure_operation_failed = <django.dispatch.dispatcher.Signal object>

Sent when a service’s operation fails.

Arguments: service, provider, operation (str), e.g. apply_manifest, error (str).

smarter.apps.infrastructure.signals.resource_applied = <django.dispatch.dispatcher.Signal object>

Sent after Kubernetes resources are created or updated, from a manifest.

Arguments: service, provider, kinds (list[str]), the kinds of the manifest’s resources.

smarter.apps.infrastructure.signals.resource_created = <django.dispatch.dispatcher.Signal object>

Sent after a service creates, or updates, a resource that is not billed for on its own.

e.g. a DNS record, or a TLS certificate.

Arguments: service, provider, resource_type, resource_name, resource_id.

smarter.apps.infrastructure.signals.resource_destroyed = <django.dispatch.dispatcher.Signal object>

Sent after a service destroys a resource that is not billed for on its own.

Arguments: service, provider, resource_type, resource_name, resource_id.

Django Signal Receivers for the infrastructure app.

They log the infrastructure services’ signals, so that every change to the platform’s infrastructure is traceable, whichever cloud provider made it. Billable resources are logged at warning level, because they cost money, and failures at error level.

The resources that are created and destroyed are also recorded in the ledger, InfrastructureResource. A ledger that cannot be written is logged, and never fails the infrastructure operation.

smarter.apps.infrastructure.receivers.handle_billable_resource_created(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a billable resource was created, and record it in the ledger.

smarter.apps.infrastructure.receivers.handle_billable_resource_creating(sender, service, provider, resource_type, resource_name, **kwargs)[source]

Log that a billable resource is about to be created.

smarter.apps.infrastructure.receivers.handle_billable_resource_destroyed(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a billable resource was destroyed, and record it in the ledger.

smarter.apps.infrastructure.receivers.handle_billable_resource_destroying(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a billable resource is about to be destroyed.

smarter.apps.infrastructure.receivers.handle_email_failed(sender, service, provider, subject=None, recipients=None, error=None, **kwargs)[source]

Log that an email could not be sent.

smarter.apps.infrastructure.receivers.handle_email_sent(sender, service, provider, subject=None, recipients=None, **kwargs)[source]

Log that an email was sent.

smarter.apps.infrastructure.receivers.handle_infrastructure_authenticated(sender, service, provider, identity=None, **kwargs)[source]

Log that a provider authenticated with its cloud.

smarter.apps.infrastructure.receivers.handle_infrastructure_authentication_failed(sender, service, provider, error=None, **kwargs)[source]

Log that a provider could not authenticate with its cloud.

smarter.apps.infrastructure.receivers.handle_infrastructure_connected(sender, service, provider, **kwargs)[source]

Log that a service connected to its backend.

smarter.apps.infrastructure.receivers.handle_infrastructure_connection_failed(sender, service, provider, error=None, **kwargs)[source]

Log that a service could not connect to its backend.

smarter.apps.infrastructure.receivers.handle_infrastructure_operation_failed(sender, service, provider, operation=None, error=None, **kwargs)[source]

Log that a service’s operation failed.

smarter.apps.infrastructure.receivers.handle_resource_applied(sender, service, provider, kinds=None, **kwargs)[source]

Log that Kubernetes resources were applied.

smarter.apps.infrastructure.receivers.handle_resource_created(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a resource was created or updated, and record it in the ledger.

smarter.apps.infrastructure.receivers.handle_resource_destroyed(sender, service, provider, resource_type, resource_name, resource_id=None, **kwargs)[source]

Log that a resource was destroyed, and record it in the ledger.