Managing Oracle Cloud Infrastructure
Manage Oracle Cloud Infrastructure using the oci CLI.
MANDATORY: Discovery-First Pattern
Always discover available resources before performing analysis.
Phase 1: Discovery
#!/bin/bash
COMPARTMENT_ID="${OCI_COMPARTMENT_ID:?Set OCI_COMPARTMENT_ID}"
echo "=== Compute Instances ==="
oci compute instance list --compartment-id "$COMPARTMENT_ID" \
--query 'data[*].{id:id,name:"display-name",state:"lifecycle-state",shape:shape,region:region}' \
--output table 2>/dev/null | head -30
echo ""
echo "=== VCNs ==="
oci network vcn list --compartment-id "$COMPARTMENT_ID" \
--query 'data[*].{id:id,name:"display-name",cidr:"cidr-block",state:"lifecycle-state"}' \
--output table 2>/dev/null | head -20
echo ""
echo "=== Block Volumes ==="
oci bv volume list --compartment-id "$COMPARTMENT_ID" \
--query 'data[*].{id:id,name:"display-name",size:"size-in-gbs",state:"lifecycle-state"}' \
--output table 2>/dev/null | head -20
echo ""
echo "=== DB Systems ==="
oci db system list --compartment-id "$COMPARTMENT_ID" \
--query 'data[*].{id:id,name:"display-name",shape:shape,state:"lifecycle-state"}' \
--output table 2>/dev/null | head -10
echo ""
echo "=== Autonomous Databases ==="
oci db autonomous-database list --compartment-id "$COMPARTMENT_ID" \
--query 'data[*].{id:id,name:"display-name",cpus:"cpu-core-count",storage:"data-storage-size-in-tbs",state:"lifecycle-state"}' \
--output table 2>/dev/null | head -10
Phase 2: Analysis
#!/bin/bash
COMPARTMENT_ID="${OCI_COMPARTMENT_ID:?Set OCI_COMPARTMENT_ID}"
INSTANCE_ID="${1:?Instance OCID required}"
echo "=== Instance Details ==="
oci compute instance get --instance-id "$INSTANCE_ID" \
--query 'data.{name:"display-name",state:"lifecycle-state",shape:shape,ocpus:"shape-config"."ocpus",memory:"shape-config"."memory-in-gbs",created:"time-created"}' \
--output table 2>/dev/null
echo ""
echo "=== VNIC Attachments ==="
oci compute vnic-attachment list --compartment-id "$COMPARTMENT_ID" --instance-id "$INSTANCE_ID" \
--query 'data[*].{id:"vnic-id",state:"lifecycle-state",subnet:"subnet-id"}' \
--output table 2>/dev/null | head -10
echo ""
echo "=== Boot Volume ==="
oci compute boot-volume-attachment list --compartment-id "$COMPARTMENT_ID" \
--availability-domain "$(oci compute instance get --instance-id "$INSTANCE_ID" --query 'data."availability-domain"' --raw-output)" \
--instance-id "$INSTANCE_ID" \
--query 'data[*].{id:"boot-volume-id",state:"lifecycle-state"}' \
--output table 2>/dev/null
echo ""
echo "=== Monitoring Metrics ==="
oci monitoring metric-data summarize-metrics-data --compartment-id "$COMPARTMENT_ID" \
--namespace oci_computeagent \
--query-text "CpuUtilization[1h]{resourceId = \"$INSTANCE_ID\"}.mean()" \
--query 'data[*].{name:name,timestamps:"aggregated-datapoints"[*].timestamp,values:"aggregated-datapoints"[*].value}' \
--output table 2>/dev/null | head -20
Output Format
ID NAME STATE SHAPE REGION
ocid1.instance.oc1 web-01 RUNNING VM.Standard3 us-ashburn-1
ocid1.instance.oc2 db-01 RUNNING VM.Standard3 us-ashburn-1
Safety Rules
- Use read-only commands:
list, get, summarize-metrics-data
- Never run
terminate, delete, update without explicit user confirmation
- Always pass
--compartment-id for resource listing
- Use
--query and --output table for clean output
- Limit output with
| head -N to stay under 50 lines
Anti-Hallucination Rules
- NEVER assume resource names — always discover via CLI/API in Phase 1 before referencing in Phase 2.
- NEVER fabricate metric names or dimensions — verify against the service documentation or
--help output.
- NEVER mix CLI commands between service versions — confirm which version/API you are targeting.
- ALWAYS use the discovery → verify → analyze chain — every resource referenced must have been discovered first.
- ALWAYS handle empty results gracefully — an empty response is valid data, not an error to retry.
Counter-Rationalizations
| Shortcut |
Counter |
Why |
| "I'll skip discovery and check known resources" |
Always run Phase 1 discovery first |
Resource names change, new resources appear — assumed names cause errors |
| "The user only asked for a quick check" |
Follow the full discovery → analysis flow |
Quick checks miss critical issues; structured analysis catches silent failures |
| "Default configuration is probably fine" |
Audit configuration explicitly |
Defaults often leave logging, security, and optimization features disabled |
| "Metrics aren't needed for this" |
Always check relevant metrics when available |
API/CLI responses show current state; metrics reveal trends and intermittent issues |
| "I don't have access to that" |
Try the command and report the actual error |
Assumed permission failures prevent useful investigation; actual errors are informative |
1---2name: managing-oracle-oci3description: |4 Use when working with Oracle Oci — oracle Cloud Infrastructure management via5 the OCI CLI. Covers compute instances, networking, block storage, databases,6 and IAM. Use when managing Oracle Cloud resources, checking instance health,7 or reviewing OCI infrastructure.8connection_type: oracle-oci9preload: false10metadata:11 source: https://skillmd.com/skills/cloudthinker-ai/managing-oracle-oci12---1314# Managing Oracle Cloud Infrastructure1516Manage Oracle Cloud Infrastructure using the `oci` CLI.1718## MANDATORY: Discovery-First Pattern1920**Always discover available resources before performing analysis.**2122### Phase 1: Discovery2324```bash25#!/bin/bash2627COMPARTMENT_ID="${OCI_COMPARTMENT_ID:?Set OCI_COMPARTMENT_ID}"2829echo "=== Compute Instances ==="30oci compute instance list --compartment-id "$COMPARTMENT_ID" \31 --query 'data[*].{id:id,name:"display-name",state:"lifecycle-state",shape:shape,region:region}' \32 --output table 2>/dev/null | head -303334echo ""35echo "=== VCNs ==="36oci network vcn list --compartment-id "$COMPARTMENT_ID" \37 --query 'data[*].{id:id,name:"display-name",cidr:"cidr-block",state:"lifecycle-state"}' \38 --output table 2>/dev/null | head -203940echo ""41echo "=== Block Volumes ==="42oci bv volume list --compartment-id "$COMPARTMENT_ID" \43 --query 'data[*].{id:id,name:"display-name",size:"size-in-gbs",state:"lifecycle-state"}' \44 --output table 2>/dev/null | head -204546echo ""47echo "=== DB Systems ==="48oci db system list --compartment-id "$COMPARTMENT_ID" \49 --query 'data[*].{id:id,name:"display-name",shape:shape,state:"lifecycle-state"}' \50 --output table 2>/dev/null | head -105152echo ""53echo "=== Autonomous Databases ==="54oci db autonomous-database list --compartment-id "$COMPARTMENT_ID" \55 --query 'data[*].{id:id,name:"display-name",cpus:"cpu-core-count",storage:"data-storage-size-in-tbs",state:"lifecycle-state"}' \56 --output table 2>/dev/null | head -1057```5859### Phase 2: Analysis6061```bash62#!/bin/bash6364COMPARTMENT_ID="${OCI_COMPARTMENT_ID:?Set OCI_COMPARTMENT_ID}"65INSTANCE_ID="${1:?Instance OCID required}"6667echo "=== Instance Details ==="68oci compute instance get --instance-id "$INSTANCE_ID" \69 --query 'data.{name:"display-name",state:"lifecycle-state",shape:shape,ocpus:"shape-config"."ocpus",memory:"shape-config"."memory-in-gbs",created:"time-created"}' \70 --output table 2>/dev/null7172echo ""73echo "=== VNIC Attachments ==="74oci compute vnic-attachment list --compartment-id "$COMPARTMENT_ID" --instance-id "$INSTANCE_ID" \75 --query 'data[*].{id:"vnic-id",state:"lifecycle-state",subnet:"subnet-id"}' \76 --output table 2>/dev/null | head -107778echo ""79echo "=== Boot Volume ==="80oci compute boot-volume-attachment list --compartment-id "$COMPARTMENT_ID" \81 --availability-domain "$(oci compute instance get --instance-id "$INSTANCE_ID" --query 'data."availability-domain"' --raw-output)" \82 --instance-id "$INSTANCE_ID" \83 --query 'data[*].{id:"boot-volume-id",state:"lifecycle-state"}' \84 --output table 2>/dev/null8586echo ""87echo "=== Monitoring Metrics ==="88oci monitoring metric-data summarize-metrics-data --compartment-id "$COMPARTMENT_ID" \89 --namespace oci_computeagent \90 --query-text "CpuUtilization[1h]{resourceId = \"$INSTANCE_ID\"}.mean()" \91 --query 'data[*].{name:name,timestamps:"aggregated-datapoints"[*].timestamp,values:"aggregated-datapoints"[*].value}' \92 --output table 2>/dev/null | head -2093```9495## Output Format9697```98ID NAME STATE SHAPE REGION99ocid1.instance.oc1 web-01 RUNNING VM.Standard3 us-ashburn-1100ocid1.instance.oc2 db-01 RUNNING VM.Standard3 us-ashburn-1101```102103## Safety Rules104- Use read-only commands: `list`, `get`, `summarize-metrics-data`105- Never run `terminate`, `delete`, `update` without explicit user confirmation106- Always pass `--compartment-id` for resource listing107- Use `--query` and `--output table` for clean output108- Limit output with `| head -N` to stay under 50 lines109110## Anti-Hallucination Rules1111121. **NEVER assume resource names** — always discover via CLI/API in Phase 1 before referencing in Phase 2.1132. **NEVER fabricate metric names or dimensions** — verify against the service documentation or `--help` output.1143. **NEVER mix CLI commands between service versions** — confirm which version/API you are targeting.1154. **ALWAYS use the discovery → verify → analyze chain** — every resource referenced must have been discovered first.1165. **ALWAYS handle empty results gracefully** — an empty response is valid data, not an error to retry.117118## Counter-Rationalizations119120| Shortcut | Counter | Why |121|----------|---------|-----|122| "I'll skip discovery and check known resources" | Always run Phase 1 discovery first | Resource names change, new resources appear — assumed names cause errors |123| "The user only asked for a quick check" | Follow the full discovery → analysis flow | Quick checks miss critical issues; structured analysis catches silent failures |124| "Default configuration is probably fine" | Audit configuration explicitly | Defaults often leave logging, security, and optimization features disabled |125| "Metrics aren't needed for this" | Always check relevant metrics when available | API/CLI responses show current state; metrics reveal trends and intermittent issues |126| "I don't have access to that" | Try the command and report the actual error | Assumed permission failures prevent useful investigation; actual errors are informative |127