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:
InfrastructureServiceA 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 taggedINFRASTRUCTURE.
- 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_authenticatedorinfrastructure_authentication_failedwhen the state changes, rather than on every check.
- 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:
- 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.
- service_name: str = 'provider'
The name of the service in signals and logs, see
InfrastructureServiceNames.
- 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 restoresmarter_settings.cloud_provider.- Return type:
- smarter.apps.infrastructure.providers.get_provider()[source]
Return the cloud provider, which is created once.
- Raises:
InfrastructureConfigurationError – If
smarter_settings.cloud_provideris not registered.- Return type:
- smarter.apps.infrastructure.providers.register_provider(name, factory)[source]
Register a cloud provider under its name, so that
smarter_settings.cloud_providercan select it.- Parameters:
name (
str) – The provider’s name, seeCloudProviders.factory (
Callable[[],CloudProvider]) – Returns the provider, e.g. its class.
- Return type:
- smarter.apps.infrastructure.providers.registered_providers()[source]
The names of the registered providers.
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:
Add a package,
smarter.apps.infrastructure.providers.azure, with aCloudProviderwhose DNS and certificate services implement the primitives ofDNSServiceandCertificateService.Register it, in
smarter.apps.infrastructure.providers, under itsCloudProvidersname.Set
SMARTER_CLOUD_PROVIDER=azure.
The platform does not change.
- class smarter.apps.infrastructure.providers.base.CloudProvider(allow_in_tests=False, **kwargs)[source]
Bases:
InfrastructureServiceA 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 taggedINFRASTRUCTURE.
- 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_authenticatedorinfrastructure_authentication_failedwhen the state changes, rather than on every check.
- 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:
- 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.
- service_name: str = 'provider'
The name of the service in signals and logs, see
InfrastructureServiceNames.