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.
- get_kubernetes_cluster_health()[source]
Describe the health of the platform’s Kubernetes cluster, as the cloud provider sees it.
The MCPServer’s staff-only
eks_statustool reports it. This implementation knows only whatget_kubernetes_cluster_info()returns: the control plane’s status, versions and health issues. A provider overrides it to add its node groups, add-ons and recommendations, asAWSProviderdoes with EKS.- Return type:
- Returns:
The cluster’s health, with no node groups, add-ons or insights.
- Raises:
InfrastructureNotReadyError – If the provider is not ready.
- 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:
- get_kubernetes_cluster_resources()[source]
Return the cloud resources of the platform’s Kubernetes cluster, for the inventory.
e.g. the cluster itself, its add-ons, and its node groups, which are provisioned outside the platform, e.g. with Terraform, so that no signal records them.
- Return type:
- Returns:
The resources, by resource type, e.g.
kubernetes.cluster. A type that could not be listed is left out, so that the inventory does not record its resources as destroyed. This implementation lists none.
- get_kubernetes_token()[source]
Return a bearer token for the platform’s Kubernetes cluster, which kubectl uses instead of its kubeconfig’s.
The kubeconfig of a managed cluster usually runs a command to fetch a token, e.g.
aws eks get-token, on every kubectl call, which takes seconds. A provider that can create a token itself returns one, which is used until it expires.- Return type:
- Returns:
The token and when it expires, as a
time.time(), or None for kubectl to use its kubeconfig’s credentials.
- 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.
- abstract property storage: StorageService
The provider’s private object storage.
- smarter.apps.infrastructure.providers.configure_provider(factory)[source]
Use another provider, e.g. a fake in tests.
- Parameters:
factory (
Callable[[],CloudProvider] |None) – 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,
CloudProvider.certificates and CloudProvider.storage, and contributes what the cloud-independent services need
from it: the Kubernetes cluster’s kubeconfig, the cluster’s description, and the cloud resources
of the cluster, for the inventory.
To add a cloud, e.g. Azure:
Add a package,
smarter.apps.infrastructure.providers.azure, with aCloudProviderwhose DNS, certificate and storage services implement the primitives ofDNSService,CertificateServiceandStorageService.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.
- get_kubernetes_cluster_health()[source]
Describe the health of the platform’s Kubernetes cluster, as the cloud provider sees it.
The MCPServer’s staff-only
eks_statustool reports it. This implementation knows only whatget_kubernetes_cluster_info()returns: the control plane’s status, versions and health issues. A provider overrides it to add its node groups, add-ons and recommendations, asAWSProviderdoes with EKS.- Return type:
- Returns:
The cluster’s health, with no node groups, add-ons or insights.
- Raises:
InfrastructureNotReadyError – If the provider is not ready.
- 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:
- get_kubernetes_cluster_resources()[source]
Return the cloud resources of the platform’s Kubernetes cluster, for the inventory.
e.g. the cluster itself, its add-ons, and its node groups, which are provisioned outside the platform, e.g. with Terraform, so that no signal records them.
- Return type:
- Returns:
The resources, by resource type, e.g.
kubernetes.cluster. A type that could not be listed is left out, so that the inventory does not record its resources as destroyed. This implementation lists none.
- get_kubernetes_token()[source]
Return a bearer token for the platform’s Kubernetes cluster, which kubectl uses instead of its kubeconfig’s.
The kubeconfig of a managed cluster usually runs a command to fetch a token, e.g.
aws eks get-token, on every kubectl call, which takes seconds. A provider that can create a token itself returns one, which is used until it expires.- Return type:
- Returns:
The token and when it expires, as a
time.time(), or None for kubectl to use its kubeconfig’s credentials.
- 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.
- abstract property storage: StorageService
The provider’s private object storage.