Cloud Providers

The cloud providers, and the one that the platform uses.

smarter_settings.cloud_provider (SMARTER_CLOUD_PROVIDER) names the provider, e.g. aws, and get_provider() returns it. Tests replace it with configure_provider():

from smarter.apps.infrastructure.providers import configure_provider
from smarter.apps.infrastructure.providers.memory import InMemoryProvider

configure_provider(InMemoryProvider)
...
configure_provider(None)
class smarter.apps.infrastructure.providers.CloudProvider(allow_in_tests=False, **kwargs)[source]

Bases: InfrastructureService

A cloud provider: the cloud-specific half of the infrastructure services.

Parameters:

allow_in_tests (bool) – Allow the provider to reach its cloud in the unit tests, e.g. in a test tagged INFRASTRUCTURE.

__init__(allow_in_tests=False, **kwargs)[source]
property account_id: str | None

The cloud account’s id, or None if the provider is not authenticated.

authentication_state(identity, error=None)[source]

Record whether the provider is authenticated with its cloud.

Sends infrastructure_authenticated or infrastructure_authentication_failed when the state changes, rather than on every check.

Parameters:
  • identity (Optional[dict]) – The provider’s identity, or None if it is not authenticated.

  • error (Optional[str]) – Why it is not authenticated.

Return type:

bool

Returns:

Whether it is authenticated.

abstract property certificates: CertificateService

The provider’s TLS certificate service.

abstract property dns: DNSService

The provider’s DNS service.

abstractmethod get_kubernetes_cluster_info()[source]

Describe the platform’s Kubernetes cluster, e.g. for the status API.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

Return type:

dict[str, Any]

abstract property identity: dict[str, Any] | None

The identity that the provider authenticates as, e.g. its account, or None.

name: str = 'cloud'

The provider’s name, see CloudProviders.

abstract property sdk_version: str

The version of the provider’s SDK.

service_name: str = 'provider'

The name of the service in signals and logs, see InfrastructureServiceNames.

abstractmethod update_kubeconfig()[source]

Write the kubeconfig of the platform’s Kubernetes cluster, for kubectl.

Return type:

bool

Returns:

True if it was written.

smarter.apps.infrastructure.providers.configure_provider(factory)[source]

Use another provider, e.g. a fake in tests.

Parameters:

factory (Optional[Callable[[], CloudProvider]]) – Returns the provider, or None to restore smarter_settings.cloud_provider.

Return type:

None

smarter.apps.infrastructure.providers.get_provider()[source]

Return the cloud provider, which is created once.

Raises:

InfrastructureConfigurationError – If smarter_settings.cloud_provider is not registered.

Return type:

CloudProvider

smarter.apps.infrastructure.providers.register_provider(name, factory)[source]

Register a cloud provider under its name, so that smarter_settings.cloud_provider can select it.

Parameters:
Return type:

None

smarter.apps.infrastructure.providers.registered_providers()[source]

The names of the registered providers.

Return type:

list[str]

The base class of the cloud providers.

A cloud provider implements the services that depend on a cloud, CloudProvider.dns and CloudProvider.certificates, and contributes what the cloud-independent services need from it: the Kubernetes cluster’s kubeconfig, and the cluster’s description.

To add a cloud, e.g. Azure:

  1. Add a package, smarter.apps.infrastructure.providers.azure, with a CloudProvider whose DNS and certificate services implement the primitives of DNSService and CertificateService.

  2. Register it, in smarter.apps.infrastructure.providers, under its CloudProviders name.

  3. Set SMARTER_CLOUD_PROVIDER=azure.

The platform does not change.

class smarter.apps.infrastructure.providers.base.CloudProvider(allow_in_tests=False, **kwargs)[source]

Bases: InfrastructureService

A cloud provider: the cloud-specific half of the infrastructure services.

Parameters:

allow_in_tests (bool) – Allow the provider to reach its cloud in the unit tests, e.g. in a test tagged INFRASTRUCTURE.

__init__(allow_in_tests=False, **kwargs)[source]
property account_id: str | None

The cloud account’s id, or None if the provider is not authenticated.

authentication_state(identity, error=None)[source]

Record whether the provider is authenticated with its cloud.

Sends infrastructure_authenticated or infrastructure_authentication_failed when the state changes, rather than on every check.

Parameters:
  • identity (Optional[dict]) – The provider’s identity, or None if it is not authenticated.

  • error (Optional[str]) – Why it is not authenticated.

Return type:

bool

Returns:

Whether it is authenticated.

abstract property certificates: CertificateService

The provider’s TLS certificate service.

abstract property dns: DNSService

The provider’s DNS service.

abstractmethod get_kubernetes_cluster_info()[source]

Describe the platform’s Kubernetes cluster, e.g. for the status API.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

Return type:

dict[str, Any]

abstract property identity: dict[str, Any] | None

The identity that the provider authenticates as, e.g. its account, or None.

name: str = 'cloud'

The provider’s name, see CloudProviders.

abstract property sdk_version: str

The version of the provider’s SDK.

service_name: str = 'provider'

The name of the service in signals and logs, see InfrastructureServiceNames.

abstractmethod update_kubeconfig()[source]

Write the kubeconfig of the platform’s Kubernetes cluster, for kubectl.

Return type:

bool

Returns:

True if it was written.