Autoscale Abstractions
cloudspells.core.abstractions.autoscale
Cloud-neutral autoscaling abstractions for CloudSpells multi-cloud support.
Defines the scaling policy dataclasses and the scalable workload interface shared across all providers. Scaling concepts—CPU/memory thresholds and cron-schedule-based rules—are cloud-neutral and map directly to OCI Autoscaling Configurations, AWS Auto Scaling Groups, and GCP Managed Instance Group autoscalers.
The base LoadBalancerConfig omits provider-specific bandwidth
fields (e.g. OCI flexible-shape Mbps). Provider implementations extend it
with their own specialised subclass (e.g. OciLoadBalancerConfig).
Exports
ScalingMetric: Enum of supported autoscaling metric types. ScalingAction: Enum of scaling action kinds. MetricScalingPolicy: CPU/memory threshold-based scaling configuration. ScheduleEntry: A single cron-schedule scaling action. ScheduleScalingPolicy: Schedule-based scaling configuration. LoadBalancerConfig: Base cloud-neutral load balancer configuration. AbstractScalableWorkload: Interface for a horizontally-scalable compute tier.
ScalingMetric
Bases: Enum
Metrics available for autoscaling policies.
Attributes:
| Name | Type | Description |
|---|---|---|
CPU_UTILIZATION |
Scale based on average CPU utilisation (percent). |
|
MEMORY_UTILIZATION |
Scale based on average memory utilisation (percent). |
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
32 33 34 35 36 37 38 39 40 41 | |
ScalingAction
Bases: Enum
Action types for scheduled scaling policies.
Attributes:
| Name | Type | Description |
|---|---|---|
CHANGE_COUNT_BY |
Change the instance count by a relative delta
(e.g. |
|
CHANGE_COUNT_TO |
Set the instance count to an absolute target value. |
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
44 45 46 47 48 49 50 51 52 53 54 | |
MetricScalingPolicy
dataclass
Metric-based autoscaling policy configuration.
Triggers scale-out when scale_out_threshold is exceeded and scale-in when the metric falls below scale_in_threshold. Maps to OCI threshold autoscaling, AWS target tracking / step scaling, or GCP autoscaling policies.
Attributes:
| Name | Type | Description |
|---|---|---|
scale_out_threshold |
int
|
Percentage threshold to trigger scale-out
(add instances). Default: |
scale_in_threshold |
int
|
Percentage threshold to trigger scale-in
(remove instances). Default: |
scale_out_value |
int
|
Number of instances to add when scaling out.
Default: |
scale_in_value |
int
|
Number of instances to remove when scaling in
(negative value). Default: |
cooldown_in_seconds |
int
|
Minimum time between consecutive scaling
actions (300-3600 s). Default: |
metric |
ScalingMetric
|
The metric to monitor. Default:
|
Example
policy = MetricScalingPolicy(
scale_out_threshold=70,
scale_in_threshold=25,
cooldown_in_seconds=600,
)
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
ScheduleEntry
dataclass
A single scheduled scaling action.
Attributes:
| Name | Type | Description |
|---|---|---|
cron_expression |
str
|
Quartz cron format expression in UTC
(e.g. |
action |
ScalingAction
|
Whether to change the count by a delta or to an absolute value. |
value |
int
|
Magnitude of the scaling action. |
display_name |
str
|
Human-readable label for this schedule entry. |
Example
scale_up = ScheduleEntry(
cron_expression="0 0 8 ? * MON-FRI *",
action=ScalingAction.CHANGE_COUNT_TO,
value=10,
display_name="Business-hours scale-up",
)
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
ScheduleScalingPolicy
dataclass
Schedule-based autoscaling policy configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
schedules |
list[ScheduleEntry]
|
Ordered list of |
Example
policy = ScheduleScalingPolicy(
schedules=[
ScheduleEntry("0 0 8 ? * MON-FRI *",
ScalingAction.CHANGE_COUNT_TO, 10,
"Scale up business hours"),
ScheduleEntry("0 0 20 ? * MON-FRI *",
ScalingAction.CHANGE_COUNT_TO, 2,
"Scale down after hours"),
]
)
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
LoadBalancerConfig
dataclass
Base cloud-neutral load balancer configuration.
Covers the properties that are meaningful on every major cloud
provider. Provider-specific subclasses add extra fields; for example
OciLoadBalancerConfig adds min_bandwidth_mbps and max_bandwidth_mbps
for OCI's flexible load-balancer shape.
Attributes:
| Name | Type | Description |
|---|---|---|
backend_port |
int
|
Port on backend instances to receive forwarded
traffic and health-check probes. Default: |
health_check_path |
str
|
HTTP path for health checks.
Default: |
is_public |
bool
|
Whether the load balancer should have a public IP.
Default: |
ssl_certificate_name |
str | None
|
Name of an SSL certificate for HTTPS
termination. When set, an HTTPS listener on port 443 is
created in addition to HTTP on port 80.
Default: |
Example
lb_cfg = LoadBalancerConfig(
backend_port=8080,
health_check_path="/api/health",
)
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
AbstractScalableWorkload
Bases: ABC
Interface for a horizontally-scalable compute tier.
Provider implementations (OCI ScalableWorkload, AWS
AwsScalableWorkload, GCP GcpScalableWorkload) combine a load
balancer, instance pool / auto scaling group, and autoscaling
configuration behind this interface.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
Output[str]
|
Provider resource ID of the instance pool / ASG. |
auto_generated_keys |
bool
|
|
Example
def export_workload(wl: AbstractScalableWorkload,
label: str) -> None:
pulumi.export(f"{label}_lb_ip", wl.get_load_balancer_ip())
pulumi.export(f"{label}_pool_id", wl.get_instance_pool_id())
export_workload(oci_pool, "web")
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
get_load_balancer_ip() -> pulumi.Output[str]
abstractmethod
Return the public IP of the load balancer.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
215 216 217 218 219 220 221 | |
get_instance_pool_id() -> pulumi.Output[str]
abstractmethod
Return the provider resource ID of the instance pool.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
223 224 225 226 227 228 229 | |
get_load_balancer_id() -> pulumi.Output[str]
abstractmethod
Return the provider resource ID of the load balancer.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
231 232 233 234 235 236 237 | |
export() -> None
abstractmethod
Publish standard scalable workload stack outputs.
Source code in packages/cloudspells-core/src/cloudspells/core/abstractions/autoscale.py
239 240 241 | |