Models

Models of the infrastructure app.

InfrastructureResource is the ledger of the cloud resources that the platform creates: DNS zones and records, TLS certificates, and billable Kubernetes resources, whichever cloud provider created them. The receivers of the infrastructure signals keep it, see smarter.apps.infrastructure.receivers, so that what the platform has provisioned, and what it costs, can be audited without asking each cloud.

class smarter.apps.infrastructure.models.InfrastructureResource(*args, **kwargs)[source]

Bases: TimestampedModel

A cloud resource that the platform created, and whether it still exists.

Parameters:
  • id (Unknown) – Primary key: ID

  • created_at (Unknown) – Created at

  • updated_at (Unknown) – Updated at

  • provider (Unknown) – Provider. The cloud provider, e.g. aws.

  • service (Unknown) – Service. The infrastructure service, e.g. dns.

  • resource_type (Unknown) – Resource type. The kind of resource, e.g. dns.zone.

  • resource_name (Unknown) – Resource name. The resource’s name, e.g. example.com.

  • resource_id (Unknown) – Resource id. The provider’s id of the resource, if any.

  • billable (Unknown) – Billable. Whether the provider bills for the resource.

  • status (Unknown) – Status

  • destroyed_at (Unknown) – Destroyed at

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

exception NotUpdated

Bases: ObjectNotUpdated, DatabaseError

class Status(*values)[source]

Bases: TextChoices

Whether the resource exists.

ACTIVE = 'active'
DESTROYED = 'destroyed'
billable

BooleanField

Billable. Whether the provider bills for the resource.

Type:

Type

created_at

DateTimeField

Created at

Timestamp indicating when the model instance was created.

This field is automatically set to the current date and time when the instance is first created. It is indexed in the database for efficient querying.

Type:

Type

destroyed_at

DateTimeField

Destroyed at

Type:

Type

get_status_display(*, field=<django.db.models.CharField: status>)

Shows the label of the status. See get_FOO_display() for more information.

id

BigAutoField

Primary key: ID

Type:

Type

objects = <django.db.models.Manager object>
provider

CharField

Provider. The cloud provider, e.g. aws.

Type:

Type

classmethod record_created(provider, service, resource_type, resource_name, resource_id=None, billable=False)[source]

Record that a resource was created, or updated.

A resource that is already active is updated, rather than recorded twice.

Return type:

InfrastructureResource

classmethod record_destroyed(provider, service, resource_type, resource_name, resource_id=None, billable=False)[source]

Record that a resource was destroyed.

A resource that the ledger does not know, e.g. one created before it existed, is recorded as destroyed.

Return type:

InfrastructureResource

resource_id

CharField

Resource id. The provider’s id of the resource, if any.

Type:

Type

resource_name

CharField

Resource name. The resource’s name, e.g. example.com.

Type:

Type

resource_type

CharField

Resource type. The kind of resource, e.g. dns.zone.

Type:

Type

service

CharField

Service. The infrastructure service, e.g. dns.

Type:

Type

status

CharField

Status

Choices:

  • active

  • destroyed

Type:

Type

updated_at

DateTimeField

Updated at

Timestamp indicating when the model instance was last updated.

This field is automatically updated to the current date and time whenever the instance is saved. It is indexed in the database for efficient querying.

Type:

Type

Serializers of the infrastructure app.

class smarter.apps.infrastructure.serializers.InfrastructureResourceSerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

Serializer of the ledger of cloud resources, InfrastructureResource, with camelCase field names.

Example usage:

from smarter.apps.infrastructure.serializers import InfrastructureResourceSerializer
data = InfrastructureResourceSerializer(resource).data