Introducing o, the easy way to use the CLI

May 26, 2021 | 5 minute read
Kevin Colwell
Master Cloud Solutions Engineer
Text Size 100%:

Use o to radically accelerate your cloud operations workflow. Spend less time searching the docs and say goodbye to the days of copy-and-pasting those long OCIDs.

You installed and configured the Oracle Cloud Infrastructure (OCI) command line interface (CLI). Next, you find some “easy” examples to try out. But soon you’re wading through hundreds of lines of JSON and the JMESPath query that filters this output doesn’t seem so simple. Don’t panic.

A quote from William of Ockham: It is vain to do more with what can be done with less.

Introducing o, a friendly helper for the Oracle Cloud CLI

o is a smart wrapper for the oci command in Oracle Cloud’s CLI. o knows all the oci commands, and it learns about your resources. With this knowledge, o help you use oci to manage your cloud resources. Tasks that used to required scripting can now be performed directly from the command line.

o guides you every step of the way, by helping you with the following tasks:

  • Find the right command, parameters, and options.

  • Build and run the command.

  • Display user-friendly results.

OCI offers a wide range of enterprise-grade infrastructure, platform, and software services. The command oci arranges commands by service, resource name, and action, often using multi-word commands separated by dashes. The command is powerful and comprehensive, supporting more than 2,300 different commands, each with required, optional, and global parameters. This complexity is mostly harmless, but it can be tedious to construct a complete oci command and get the wanted output.

Use o to find the command you want

Suppose we want to see the subnets in our compartment. Use o to find all subnet commands.

A screenshot of the output for searching subnet commands.

Possible commands are sorted by length. Occam’s Razor tells us the simplest command is likely the one we want, so the output suggests a best match, along with parameter quick reference.

We want to list subnets. So, let’s get the quick reference.

A screenshot of the output for listing subnets with o in the CLI.

The order of list and subnet doesn’t matter, and we omitted the service name network altogether. Give o a hint and it brings back all possible matches. After it’s narrowed down, o provides usage details for the best match.

Build and run a command

In the previous images, we see that oci network list subnet requires one parameter: the compartment ID. I don’t know the ID, but o does. My compartment name is “kevco,” so I give that, and o shows the full oci command that can run. Type “go” to run the oci command.

A screenshot of the output for running the “go” command on a subnet.

o runs the command, processes the results, and automatically reports the three subnets found in my compartment in a compact table. You can truncate or trim data values to pack useful info in a small space. For example, the "a" column is the availability domain, and the "N" values are short for “none.”

In the next example, I need to stop an instance in the TEST compartment. First, I list the instances in TEST, then send a STOP action to the instance using a portion of the instance display-name.

A screenshot of the output for running a STOP command on an instance.

The resource name that you give doesn’t have to be complete or case-sensitive, if you provide enough to identify the resource. Duplicate resource names, which are allowed in Oracle Cloud, can be resolved by providing the compartment name with the resource name or any unique snippet from the OCID. For example, the previous instance can be specified with -i test/2bct or -i hnugb. You can always use the complete OCID as a last resort.

Are you impressed yet? Let’s do something harder. Here, I use o to launch a new Compute instance named "marvin" in my robots subnet.

A screenshot of the output for creating an instance.

o instantly transforms the highlighted o command into nine lines of well-formed oci command. We can note the following observations:

  • We only need launch to find oci compute instance launch.

  • Three resource names are replaced with OCIDs.

  • -ad expands to --availability-domain.

  • -api expands to --assign-public-ip.

  • All multi-word commands and options (connected by hyphens) support this mwcao technique.

  • -s is --shape because --shape the first option that starts with --s. Other --s options need at least two characters.

  • --subnet-id ca be specified with --sub, -subnet, --su, or -si. Use what pleases you.

Easy output

By default, o presents a subset of interesting fields in an easy-to-read table. Often, you want more or different details. o makes it easy to show all key-value pairs, choose a few fields, and even get CSV output.

A gif showing different output options for o.

We can note the following details of the output:

  • Partial matches can select multiple matching fields. Two “time” fields are selected.

  • The field separator determines output format:
    / for text output
    , for CSV output
    # for table output (not shown)

  • Pair with xargs to act on many resources at once. With this technique, you can quickly create or delete hundreds of similar resources.

Give it a try

o works on Linux, MacOS, and Cloud Shell. Windows users can use o in WSL.

To install, download o, place it in your PATH and make it executable.

where=$(which oci) && wget -q https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/examples/project_o/o -O ${where%ci} && chmod a+x ${where%ci}

Run o oci_commands.

It can take a few minutes to discover all the oci commands and parameters.

Then run o, and it explains how to complete the setup for your tenancy.

Give o a try, and see how much easier the Oracle Cloud Infrastructure command line can be. Let me know how o improves your CLI experience. Share and enjoy!

Kevin Colwell

Master Cloud Solutions Engineer

Kevin is a Master Cloud Solutions Engineer in the Oracle NSG.  


Previous Post

Oracle’s Ampere A1 Arm VMs: First impressions

Gilson Melo | 4 min read

Next Post


Announcing VMware HCX Enterprise for Oracle Cloud VMware Solution

John Lindblom | 1 min read