Launch, manage, and scale OCI compute instances with capacity retry logic. Use when provisioning VMs, selecting instance shapes, or handling "out of capacity" errors. Trigger with "oci compute", "launch instance", "out of capacity", "instance shapes".
Provision and manage OCI compute instances using the Python SDK. Compute is the entry point for most OCI workloads, but "out of host capacity" errors, shape selection confusion (Flex vs Standard, AMD vs ARM vs Intel), and boot volume management make it harder than AWS EC2. This skill covers shape selection, launch with capacity retry across availability domains, instance lifecycle actions, and boot volume management.
Purpose: Launch reliable compute instances with retry logic that survives capacity shortages.
pip install oci~/.oci/config with fields: user, fingerprint, tenancy, region, key_fileAllow group Developers to manage instances in compartment <name>oraclecloud-core-workflow-b)| Shape | Arch | Flex? | OCPUs | Use Case |
|---|---|---|---|---|
| VM.Standard.A1.Flex | ARM (Ampere) | Yes | 1-80 | Always Free eligible, best price/perf |
| VM.Standard.E5.Flex | AMD | Yes | 1-94 | General purpose, broadest availability |
| VM.Standard3.Flex | Intel | Yes | 1-32 | Intel-specific workloads |
| VM.Standard.E4.Flex | AMD | Yes | 1-64 | Previous gen, still available |
Key rule: Always use Flex shapes. They let you set exact OCPU and memory. Standard (non-Flex) shapes have fixed sizes and are being phased out.
import oci
config = oci.config.from_file("~/.oci/config")
compute = oci.core.ComputeClient(config)
identity = oci.identity.IdentityClient(config)
# Get availability domains
ads = identity.list_availability_domains(compartment_id=config["tenancy"]).data
# List shapes in each AD
for ad in ads:
shapes = compute.list_shapes(
compartment_id=config["tenancy"],
availability_domain=ad.name
).data
flex_shapes = [s for s in shapes if "Flex" in s.shape]
print(f"\n{ad.name}:")
for s in flex_shapes:
print(f" {s.shape} | OCPUs: {s.ocpu_options.min}-{s.ocpu_options.max}")
The most common OCI error is 500 InternalError with message "Out of host capacity." The fix is to retry across availability domains.
import oci
import time
config = oci.config.from_file("~/.oci/config")
compute = oci.core.ComputeClient(config)
identity = oci.identity.IdentityClient(config)
ads = identity.list_availability_domains(compartment_id=config["tenancy"]).data
launch_details = oci.core.models.LaunchInstanceDetails(
compartment_id=config["tenancy"],
display_name="my-app-server",
shape="VM.Standard.A1.Flex",
shape_config=oci.core.models.LaunchInstanceShapeConfigDetails(
ocpus=2, memory_in_gbs=12
),
source_details=oci.core.models.InstanceSourceViaImageDetails(
image_id="ocid1.image.oc1...", # Oracle Linux 8 image OCID
boot_volume_size_in_gbs=50
),
create_vnic_details=oci.core.models.CreateVnicDetails(
subnet_id="ocid1.subnet.oc1..."
),
metadata={"ssh_authorized_keys": open("/home/user/.ssh/id_rsa.pub").read()},
)
# Retry across all ADs on capacity errors
for ad in ads:
launch_details.availability_domain = ad.name
try:
response = compute.launch_instance(launch_details)
print(f"Launched in {ad.name}: {response.data.id}")
break
except oci.exceptions.ServiceError as e:
if e.status == 500 and "capacity" in str(e.message).lower():
print(f"No capacity in {ad.name}, trying next AD...")
time.sleep(2)
continue
raise