Use Oracle Cloud Infrastructure Command Line Interface to manage Oracle Exadata Database Service on Cloud@Customer
Introduction
Oracle Cloud Infrastructure Command Line Interface (OCI CLI) is a great tool for managing your resources in OCI, including Oracle Exadata Database Service on Cloud@Customer resources. OCI CLI lets you easily and efficiently orchestrate and automate OCI operations. As OCI CLI calls on the OCI REST API, this means OCI CLI and OCI REST API is compatible even though the syntax is different. You can use OCI CLI during your development of OCI REST API automations for trial and error and then deploy your automations with less effort.
This is a two part series, where in this first part we are introducing you to the basics of OCI CLI, while in the second part we are focusing more on the Oracle Exadata Database Service on Cloud@Customer specific commands and workflows.
Note: OCI CLI is also required when using Dynamic Scaling with the remote plugin, but Dynamic Scaling itself will not be covered in this tutorial.
Objectives
-
Install OCI CLI.
-
Use output formatting to filter and format the command outputs for your needs.
-
Use input assistance to simplify the use of OCI CLI.
Prerequisites
-
Access to an OCI tenancy with an Oracle Exadata Database Service on Cloud@Customer infrastructure.
-
A user created in the tenancy, in a group with a policy that grants the desired permissions.
-
A supported version of Python environment installed on a supported Operating System (OS) with access to the OCI tenancy. For more information, see Supported Python Versions and Operating Systems.
-
A keypair used for signing API requests, with the public key uploaded to Oracle.
Task 1: Install OCI CLI
The OCI CLI is built on the OCI Software Development Kit (SDK) for Python and runs on Mac, Windows, or Linux. The Python code makes calls to OCI APIs to provide the functionality implemented for the various services including Oracle Exadata Database Service on Cloud@Customer and Oracle Autonomous Database on Exadata Cloud@Customer.
-
Download OCI CLI for your OS from here: OCI CLI GitHub repository.
-
Follow the installation instructions as per your operating system.
-
Run the following command to verify your installation.
$ oci --version
-
Set up a configuration using the setup dialog that contains the required credentials for working with OCI.
$ oci setup config
-
Verify your configuration file.
For example:
[DEFAULT] user=ocid1.user.oc1..<unique_ID> fingerprint=<your_fingerprint> key_file=~/.oci/oci_api_key.pem tenancy=ocid1.tenancy.oc1..<unique_ID> # Some comment region=us-ashburn-1
-
Run the following command to check your connectivity, which will show the namespace of your tenancy.
$ oci os ns get
-
Run the following command to list your available compartments.
$ oci iam compartment list
This will generate the following JSON response:
{ "data": [ { "compartment-id": "ocid1.tenancy.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5xlq", "defined-tags": { "Oracle-Tags": { "CreatedBy": "default/some-email@oracle.com", "CreatedOn": "2023-11-10T13:27:32.885Z" } }, "description": "Compartment for Exadata Infrastructure", "freeform-tags": {}, "id": "ocid1.compartment.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdh7q", "inactive-status": null, "is-accessible": null, "lifecycle-state": "ACTIVE", "name": "ExaInfra", "time-created": "2023-11-10T13:27:32.945000+00:00" } ] }
Note: Note that the output has been truncated to show only the first compartment.
-
Run the following command to list all work requests in a compartment.
$ oci work-requests work-request list --compartment-id ocid1.compartment.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxdh7q
Use Output Formatting to Filter and Format the Command Outputs for your Needs
As you have seen in the previous examples, the JSON response from OCI CLI commands can be extensive, hard to follow and not easy to read.
At the command prompt in Linux for example, you can always pipe the output to power tools like grep to filter your response.
Use the following command to list all the VM clusters in a specific compartment and filtering for id
.
$ oci db vm-cluster list --compartment-id <OCID> | grep \"id\"
This will generate the following response:
"id":"ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2tkq"
"id":"ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz5ra"
However, OCI CLI has built in query functionality with the --query
parameter, where you can specify which fields you want to query for.
-
Run the following command with the
--query
parameter.$ oci db vm-cluster list --compartment-id <OCID> --query "data[].[\"id\"]"
The JSON response will be:
[ [ "ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2tkq" ], [ "ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz5ra" ] ]
-
You can easily specify additional fields behind
--query
to build a more complex query.$ oci db vm-cluster list --compartment-id <OCID> --query "data[].[\"hostname\" , \"id\"]"
The JSON response will be:
[ [ "fraexaclu1-uvlkz", "ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2tkq" ], [ "fraexaclu2-2uyfk", "ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz5ra" ] ]
-
You can get a more user-friendly output by using the
--output
table parameter.$oci db vm-cluster list --compartment-id <OCID> --query "data[].[\"hostname\" , \"id\"]" --output table
The response will be:
+----------------------------------------------------------------------------------------------------------------------+ | Column1 | Column2 | +----------------------------------------------------------------------------------------------------------------------+ | fraexaclu1-uvlkz | ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2tkq | | fraexaclu2-2uyfk | ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz5ra | +------------------+---------------------------------------------------------------------------------------------------+
-
You can also specify the headings for the columns by using the
--query
parameter.$ oci db vm-cluster list --compartment-id <OCID> --query "data[].{\"Hostname\" : \"hostname\" , \"OCID\" : \"id\" }" --output table
The response will be:
+----------------------------------------------------------------------------------------------------------------------+ | Hostname | OCID | +----------------------------------------------------------------------------------------------------------------------+ | fraexaclu1-uvlkz | ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2tkq | | fraexaclu2-2uyfk | ocid1.vmcluster.oc1.eu-frankfurt-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxz5ra | +------------------+---------------------------------------------------------------------------------------------------+
Note: It is important to understand the correlation between the syntax used with the
--query
parameter and the JSON response. OCI CLI sub-commands likelist
typically returns many results, while OCI CLI sub-commands likeget
returns only one result.-
Where the JSON response shows that the data is a list or array as specified by a
[
.[opc@jens-oci-1 ~]$ oci db vm-cluster list { "data": [ {
Then the query syntax look like this:
--query "data[].[ field1 , field2 ]"
-
Where the JSON response shows that the data is a single object.
[opc@jens-oci-1 ~]$ oci db vm-cluster get { "data": {
Then the syntax for the
get
command look like this:--query "data.[ field1 , field2 ]"
-
Use Input Assistance to Simplify the Use of OCI CLI
There is a number of different ways to get input assistance with the OCI CLI for both ad-hoc and automated use cases.
-
Using Environment Variables:
You can use environment variables to store the values of the parameters that we pass to the OCI CLI.
For example, you might want to use
$T
for a tenancy OCID and$C
for a compartment OCID.T=ocid1.tenancy.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5xlq C=ocid1.compartment.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7m7a
You can use this in the OCI CLI commands like this:
$ oci work-requests work-request list --compartment-id $C
-
Using
--help
:You can always use
--help
to get additional information on your command. This is applicable at all levels in the OCI CLI command structure.For example:
oci --help oci db --help oci db vm-cluster --help oci db vm-cluster list --help
The following is the response example of the
oci db vm-cluster --help
command.Usage: oci db vm-cluster [OPTIONS] COMMAND [ARGS]... Details of the cloud VM cluster. Applies to Exadata Cloud Service instances only. Options: -?, -h, --help For detailed help on any of these individual commands, enter <command> --help. Commands: add Add Virtual Machines to the Cloud... change-vm-cluster-subscription Associate a cloud VM cluster with... change-compartment Moves a cloud VM cluster and its... create Creates a cloud VM cluster. delete Deletes the specified cloud VM... get Gets information about the... get-exadata-iorm-config Gets the IORM configuration for... get-update Gets information about a... get-update-history Gets the maintenance update... list Gets a list of the cloud VM... list-update-histories Gets the history of the... list-updates Lists the maintenance updates... remove Remove Virtual Machines from the... update Updates the specified cloud VM... update-exadata-iorm-config Updates the IORM settings for the...
-
Using Profiles in the main Configuration File:
When setting up the OCI CLI using the setup dialog a main configuration file will be created and it is path listed in the output. On Linux and Unix the main configuration file is located at
/home/opc/.oci/config
.Example of a main configuration file:
[opc@jens-oci-1 ~]$ cat .oci/config [DEFAULT] user=ocid1.user.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3dpa fingerprint=5f:12:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:8c:e4 key_file=/home/opc/.oci/oci_api_key.pem tenancy=ocid1.tenancy.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5xlq region=eu-frankfurt-1
In the above example, the default profile has been created with the user, tenancy and region defined. When using command line without specifying the parameters, the default values will be used from the profile. If you wanted to see results outside of the values defined in the profile file, you can explicitly specify the values in the command line.
You can also create multiple profiles in the main configuration file.
[DEFAULT] user=ocid1.user.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3dpa fingerprint=5f:12:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:8c:e4 key_file=/home/opc/.oci/oci_api_key.pem tenancy=ocid1.tenancy.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5xlq region=eu-frankfurt-1 [AMS] user=ocid1.user.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx3dpa fingerprint=5f:12:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx:8c:e4 key_file=/home/opc/.oci/oci_api_key.pem tenancy=ocid1.tenancy.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx5xlq region=eu-amsterdam-1
You can refer to the predefined profile with the following command.
oci db vm-cluster list --compartment-id $C --profile AMS --query "data[].[\"display-name\"]" --output table
-
Using the Runtime Configuration Files:
When you want to make it even easier to select between different regions, compartments, VM clusters, and so on, you specify profiles with this information in a second optional runtime configuration file. The runtime configuration file is complementing the main configuration file. You can specify default values for the command line parameters in the runtime configuration file.
You can create a runtime configuration file with the following command.
$ oci setup oci-cli-rc --file .oci/oci_cli_rc
You can complement the profiles in the main configuration file and add additional profile details to the end of your runtime configuration file.
[DEFAULT] compartment-id = ocid1.compartment.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7m7a [AMS] compartment-id = ocid1.compartment.oc1..xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7m7a vm-cluster-id = ocid1.vmcluster.oc1.eu-amsterdam-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2tkq
You can specify these defined profiles at command execution with the following command.
$ oci db vm-cluster get --profile AMS --query "data.{\"OCID\" : \"id\" , \"Core Count\" : \"cpu-core-count\" }" --output table +------------+------------------------------------------------------------------------------------------------------+ | Core Count | OCID | +------------+------------------------------------------------------------------------------------------------------+ | 0 | ocid1.vmcluster.oc1.eu-amsterdam-1.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2tkq | +------------+------------------------------------------------------------------------------------------------------+
-
Generate Full Command JSON Input file:
The full command JSON input file is used with the
--from-json file://<json file name>
parameter to specify all parameters for the command. To make this feasible there is a parameter called--generate-full-command-json-input
which will create a JSON file with all parameters for that command.Use the following command to generate JSON file with the filename
vm-cluster_update.json
.oci db vm-cluster update --generate-full-command-json-input > vm-cluster_update.json
You can edit this JSON input file and keep only the parameters relevant to the command you want to execute. In this example, we will scale the number of OCPU for the VM cluster, which was at 0 (zero), and in order to do that we will need the VM cluster ID and the new amount of OCPU (scaling to 4 OCPU).
{ "vmclusterId": "ocid1.vmcluster.oc1.eu-frankfurt-1.antheljrvwun52iawxlyg2hp6lr3xawbvub7kcjje7yta45yluiz6xxl2tkq", "cpuCoreCount": 4 }
Use the following command to utilize the JSON input file.
oci db vm-cluster update --from-json file://vm-cluster_update.json
Related Links
-
Oracle Cloud Infrastructure Command Line Interface (OCI CLI)
-
Oracle Cloud Infrastructure Command Line Interface Command Reference
Acknowledgments
- Authors - Jens Ejvinsson (Exadata Cloud@Customer Black Belt), Zsolt Szokol (Exadata Cloud@Customer Black Belt)
More Learning Resources
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center.
Use Oracle Cloud Infrastructure Command Line Interface to manage Oracle Exadata Database Service on Cloud@Customer
G38664-01
Copyright ©2025, Oracle and/or its affiliates.