OCI Autoscale
cloudspells.providers.oci.autoscale
Scalable Workload spell for CloudSpells.
Provides ScalableWorkload, which creates a complete horizontally-scalable
OCI compute tier with load balancing and autoscaling:
- OCI Load Balancer (flexible shape) in the VCN's public subnet with HTTP and optional HTTPS listeners.
- Instance Configuration as a launch template for pool instances.
- Instance Pool in the VCN's private subnet, spread across all availability domains.
- Autoscaling Configuration — metric-based (CPU/memory) or schedule-based (cron expressions).
Supporting configuration dataclasses:
LoadBalancerConfig: Customise LB port, health check path, bandwidth, and SSL.MetricScalingPolicy: Scale in/out based on CPU or memory utilisation thresholds.ScheduleScalingPolicy: Scale in/out on a Quartz cron schedule (e.g. business hours).ScheduleEntry: A single cron-schedule scaling action.ScalingMetric: Enum of available metric types.ScalingAction: Enum of available scaling action types.
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 | |
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 | |
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 | |
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 | |
OciLoadBalancerConfig
dataclass
Bases: LoadBalancerConfig
OCI-specific load balancer configuration extending the cloud-neutral base.
Adds OCI flexible-shape bandwidth parameters to the base LoadBalancerConfig.
Use this class instead of LoadBalancerConfig when deploying ScalableWorkload
on OCI and you need to control the LB's minimum or maximum bandwidth allocation.
Attributes:
| Name | Type | Description |
|---|---|---|
backend_port |
int
|
|
health_check_path |
str
|
|
is_public |
bool
|
|
min_bandwidth_mbps |
int
|
|
max_bandwidth_mbps |
int
|
|
ssl_certificate_name |
str | None
|
|
Example
from cloudspells.providers.oci.autoscale import OciLoadBalancerConfig
lb_cfg = OciLoadBalancerConfig(
backend_port=8080,
health_check_path="/api/health",
min_bandwidth_mbps=100,
max_bandwidth_mbps=500,
)
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
52 53 54 55 56 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 | |
ScalableWorkload
Bases: BaseResource, AbstractScalableWorkload
OCI Scalable Workload with load balancer, instance pool, and autoscaling.
Creates a complete horizontally-scalable compute tier following OCI best practices:
- OCI Load Balancer (flexible shape) in the VCN public subnet — internet-facing, with HTTP and optional HTTPS listeners.
- Instance Configuration as the launch template for pool VMs.
- Instance Pool in the VCN private subnet, spread across all availability domains.
- Autoscaling Configuration — metric-based (CPU/memory thresholds) or
schedule-based (Quartz cron). Pass
Noneto disable autoscaling.
Security rules are added automatically to the VCN via
Vcn.add_security_list_rules before Vcn.finalize_network is called.
Attributes:
| Name | Type | Description |
|---|---|---|
vcn |
Vcn | VcnRef
|
The |
shape |
Input[str]
|
Compute shape for instance pool VMs
(e.g. |
ocpus |
Input[float]
|
Number of OCPUs per instance. |
memory_in_gbs |
Input[float]
|
RAM in GiB per instance. |
ssh_public_key |
str
|
OpenSSH public key installed on instances. |
ssh_private_key |
str | None
|
Corresponding private key, or |
image_id |
Input[str] | None
|
OCID of the boot image resolved for the pool instances. |
user_data |
str | None
|
Base64-encoded cloud-init user data string stored internally,
or |
min_instances |
int
|
Minimum (floor) number of instances for autoscaling. |
max_instances |
int
|
Maximum (ceiling) number of instances for autoscaling. |
initial_instances |
int
|
Instance count when the pool is first created. |
load_balancer_config |
LoadBalancerConfig
|
|
scaling_policy |
MetricScalingPolicy | ScheduleScalingPolicy | None
|
|
auto_generated_keys |
bool
|
|
load_balancer |
LoadBalancer
|
The |
backend_set |
BackendSet
|
The |
listeners |
list[Listener]
|
List of |
instance_configuration |
InstanceConfiguration
|
The |
instance_pool |
InstancePool
|
The |
autoscaling_configuration |
AutoScalingConfiguration | None
|
The
|
id |
Output[str]
|
|
Example
vcn = Vcn(name="app", compartment_id=comp_id, cidr_block="10.0.0.0/16")
pool = ScalableWorkload(
name="web",
compartment_id=comp_id,
vcn=vcn,
min_instances=2,
max_instances=10,
load_balancer_config=LoadBalancerConfig(backend_port=8080),
scaling_policy=MetricScalingPolicy(scale_out_threshold=70),
)
pulumi.export("lb_ip", pool.get_load_balancer_ip())
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
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 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 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 187 188 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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 | |
__init__(name: str, compartment_id: pulumi.Input[str], vcn: Vcn | VcnRef, stack_name: str | None = None, shape: pulumi.Input[str] = 'VM.Standard.E4.Flex', ocpus: pulumi.Input[float] = 1, memory_in_gbs: pulumi.Input[float] = 16, image_id: pulumi.Input[str] | None = None, os_name: str = 'oracle', ssh_public_key: pulumi.Input[str] | None = None, user_data: str | bytes | None = None, boot_volume_size_in_gbs: pulumi.Input[int] = 50, nsg_ids: list[pulumi.Input[str]] | None = None, min_instances: int = 1, max_instances: int = 5, initial_instances: int | None = None, load_balancer_config: LoadBalancerConfig | None = None, scaling_policy: MetricScalingPolicy | ScheduleScalingPolicy | None = _UNSET, defined_tags: dict[str, Any] | None = None, opts: pulumi.ResourceOptions | None = None) -> None
Create a scalable workload with load balancer, instance pool, and autoscaling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Logical name for the workload (e.g. |
required |
compartment_id
|
Input[str]
|
OCID of the OCI compartment to deploy into. |
required |
vcn
|
Vcn | VcnRef
|
|
required |
stack_name
|
str | None
|
Pulumi stack name. Defaults to
|
None
|
shape
|
Input[str]
|
OCI compute shape for instance pool VMs
(default: |
'VM.Standard.E4.Flex'
|
ocpus
|
Input[float]
|
Number of OCPUs per instance (default: |
1
|
memory_in_gbs
|
Input[float]
|
RAM in GiB per instance (default: |
16
|
image_id
|
Input[str] | None
|
Explicit boot image OCID. When |
None
|
os_name
|
str
|
Friendly OS name used to auto-discover the latest image
when |
'oracle'
|
ssh_public_key
|
Input[str] | None
|
OpenSSH public key to install on instances.
When |
None
|
user_data
|
str | bytes | None
|
Cloud-init script as a plain |
None
|
boot_volume_size_in_gbs
|
Input[int]
|
Boot volume size in GiB (default:
|
50
|
nsg_ids
|
list[Input[str]] | None
|
List of Network Security Group OCIDs to attach to each
pool instance VNIC. When |
None
|
min_instances
|
int
|
Minimum number of instances in the pool
(default: |
1
|
max_instances
|
int
|
Maximum number of instances the autoscaler may
create (default: |
5
|
initial_instances
|
int | None
|
Initial instance count when the pool is first
created. Defaults to |
None
|
load_balancer_config
|
LoadBalancerConfig | None
|
|
None
|
scaling_policy
|
MetricScalingPolicy | ScheduleScalingPolicy | None
|
Autoscaling policy. Pass a |
_UNSET
|
defined_tags
|
dict[str, Any] | None
|
OCI defined tags applied to the load balancer,
instance configuration, instance pool, and autoscaling
resources, in |
None
|
opts
|
ResourceOptions | None
|
Pulumi resource options forwarded to the component. |
None
|
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/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 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
export() -> None
Export standard scalable workload stack outputs.
Publishes load balancer IP, load balancer OCID, and instance pool OCID under keys derived from the spell's logical name. The SSH private key is exported as a Pulumi secret only when it was auto-generated.
Example
pool = ScalableWorkload(name="web-pool", ...)
pool.export()
# Exports: web_pool_lb_ip, web_pool_lb_id, web_pool_pool_id,
# and conditionally web_pool_ssh_private_key (secret)
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 | |
get_load_balancer_ip() -> pulumi.Output[str]
Return the public IP address of the load balancer.
Resolves the first entry in the load balancer's ip_address_details
list, which is the public VIP when LoadBalancerConfig.is_public
is True.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Output[str]
|
empty string if the load balancer has no IP details yet. |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
808 809 810 811 812 813 814 815 816 817 818 819 820 821 | |
get_instance_pool_id() -> pulumi.Output[str]
Return the OCID of the instance pool.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
823 824 825 826 827 828 829 | |
get_load_balancer_id() -> pulumi.Output[str]
Return the OCID of the load balancer.
Returns:
| Type | Description |
|---|---|
Output[str]
|
|
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
831 832 833 834 835 836 837 | |
get_ssh_public_key() -> str
Return the SSH public key installed on pool instances.
Returns:
| Type | Description |
|---|---|
str
|
OpenSSH public key string (auto-generated or caller-supplied). |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
839 840 841 842 843 844 845 | |
get_ssh_private_key() -> str | None
Return the SSH private key if it was auto-generated.
Returns:
| Type | Description |
|---|---|
str | None
|
PEM-encoded private key string when keys were auto-generated, |
str | None
|
or |
Source code in packages/cloudspells-oci/src/cloudspells/providers/oci/autoscale.py
847 848 849 850 851 852 853 854 | |