2 General Syntax of opc compute Commands

You can view the general syntax of opc compute commands by running the following command:

opc -h

The following is the general syntax of opc compute commands:

opc [global_options...] service_name [service_options...] resource_name command [arguments...] [options...]
Option Description More Information
global_options... The global command line options. Global Options
service_name Specify compute.  
service_options... Command line options that are specific to Compute Classic. Service Options
resource_name

The Compute Classic resource that you want to manage using opc compute CLI.

To view the list of Compute Classic resources that you can manage, run the following command:

opc compute -h
 
command An action that you can perform on Compute Classic objects by using the CLI commands. General CLI Command Actions
[arguments...] [options...] Arguments and options are specific to each command.  

Global Options

The following table describes the general CLI command options that you can use. It is not mandatory to provide values for any of these options.

Option Description

--format value

-f value

Specifies whether the command output should be presented in plain-text format without any table borders, table format, or JSON format.

You can specify one of the following values:

  • text: This is the default option. Displays the output in plain-text format without any table borders. If you use the text format while executing the list commands, only values for the name parameter is returned.

    Example

    opc -f text compute image-list list /oracle/public/

    Sample output

    This is a sample output. The output you see will vary depending on your environment. Some lines may be truncated with ellipses (...) for readability.

    NAME
    /oracle/public/oel6
    /oracle/public/WIN_2008_SE_R2-1.0.0-20160902-040218
    ...
  • json: Displays the output in the JavaScript Object Notation (JSON) format and this output is not filtered. Note that if you specify this format, the CLI ignores the -F option.

    Example

    opc -f json compute image-list get /oracle/public/oel6

    Sample output

    This is a sample output. The output you see will vary depending on your environment.

    {
     "default": 1,
     "description": "\"\"",
     "entries": [
      {
       "attributes": {},
       "imagelist": null,
       "machineimages": [
        "/oracle/public/oel6"
       ],
       "uri": "https://api-z999.compute.us0.oraclecloud.com/imagelist/oracle/public/oel6/entry/1",
       "version": 1
      }
     ],
     "name": "/oracle/public/oel6",
     "uri": "https://api-z999.compute.us0.oraclecloud.com/imagelist/oracle/public/oel6"
    }
    
  • table: Displays the each field in a separate column. While using the -f table flag, you can use the -F or -fields option to filter the output for specific resource attributes.

    If you have already set the OPC_FORMAT environment variable, this command line argument overrides that.

    Example

    opc -f table compute image-list get /oracle/public/oel6

    Sample output

    This is a sample output. The output you see will vary depending on your environment.

    +-------------------------+---------------------------------------------------------------+
      default                 | 1
      description             | ""
      entries/0/imagelist     |
      entries/0/machineimages | ["/oracle/public/oel6"]
      entries/0/uri           | https://api-z999.compute.us0.oraclecloud.com/imagelist/oracle/public/oel6/entry/1
      entries/0/version       | 1
      name                    | /oracle/public/oel6
      uri                     | https://api-z999.compute.us0.oraclecloud.com/imagelist/oracle/public/oel6
    +-------------------------+---------------------------------------------------------------+
    

-F comma-separated-field-names

--fields comma-separated-field-names

Lists values only for the specified resource attributes. You can use this option to filter the output to show only the attributes that you want to see, particularly for objects that have numerous attributes.

To use this option, you must also specify the -f table or -f text option.

If you have already set the OPC_FIELDS environment variable, this command line argument overrides that.

The list of attributes that you can specify depends on the resource. For example, the SSH key resource has the attributes name, enabled, and key.

Example 1: Viewing filtered output in tabular format with borders

To retrieve only the names and RAM of all available shapes:

opc -f table -F name,ram compute shape list

Sample output

This is a sample output. The output you see will vary depending on your environment. Some lines may be truncated with ellipses (...) for readability.

+------------+--------+
     NAME    |  RAM
+------------+--------+
  oc3        |   7680
  oc5        |  30720
  oc4        |  15360
  oc6        |  61440
  ...
+------------+--------+

Example 2: Viewing filtered output in text format without table borders

To retrieve only the names and RAM of all available shapes:

opc -f text -F name,ram compute shape list

Sample output

This is a sample output. The output you see will vary depending on your environment. Some lines may be truncated with ellipses (...) for readability.

NAME    RAM
oc3     7680
oc5     30720
oc4     15360
oc6     61440
...     ...

--debug-requests

Indicates that the command must be run in debug mode. The output in this mode is very verbose. It includes the request and response details of the internal API call that is invoked for the CLI command. This output may be useful for debugging issues.

If you have already set the DEBUG environment variable, this command line argument overrides that value.

--insecure-tls

Specify this option when you want to disable SSL certificate verification or if you are using an unsigned certificate.

--insecure-http

Specify this option when you want to use HTTP instead of HTTPS while connection to Oracle Cloud services.

--profile file_name

-p file_name

A text file that contains the user name and password for authenticating access to Compute Classic. It also contains information about the REST API endpoint URL for your Compute Classic site.

For information about creating a profile, see Setting Up the Required Environment Variables and Files.

Note that the file must not be world-readable.

If you have already set the OPC_PROFILE_FILE environment variable, this command line argument overrides that value.

Required if you choose not to set the environment variables: OPC_COMPUTE_ENDPOINT, OPC_COMPUTE_USER, and OPC_COMPUTE_PASSWORD_FILE.

If you don't use this option and you have not set the environment variables, then while running every command you must explicitly specify the REST API endpoint URL by using the -e option, the user name by using the -u option, and the file which contains the password by using the -pf option as described in Service Options.

--profile-directory directory_name

--pd directory_name

The folder that contains the file name that you specify using the --profile or -p option.

If you have already set the OPC_PROFILE_DIRECTORY environment variable, this command line argument overrides that value.

-h

--help

Show help message and exit.

Example

opc -h

-v

--version

Prints the version of the CLI.

Example

opc --version

Sample output

opc version 17.2.4

--verbose

Print verbose output (where supported).

Service Options

The following table lists the command options that are specific to Compute Classic. For information about using these options, see Setting Up Environment Variables and Files.

Option Description

-u value

--user value

User name for authenticating access to Compute Classic.

-pf file

--password-file file

Provide the full path of the text file containing the password for the user that you specify using the -u option. Note that the file must not be world-readable.

-e url

--endpoint url

The API endpoint URL of your site in Compute Classic account. Some of the examples in this guide use the following API endpoint URL:

https://api-z999.compute.us0.oraclecloud.com

-ac environment variable

--auth-cookie environment variable

Provide a valid authentication cookie.

-h

--help

Show help message and exit.

Example

opc compute -h

General CLI Command Actions

The following table describes the general actions that you can perform on Compute Classic objects by using the CLI commands.

Note that some of these actions may not be supported for certain objects and there may be additional, unique actions for some objects.

Action Description

add

Creates an object.

delete

Deletes an object. No response is returned for the delete action.

discover

Retrieves the names of the specified object in a container and the names of the sub-containers. This command does not retrieve details of the object and the contents of the sub-container. You must specify a container, which can only be a parent path of the key field. For example, /Compute-identity_domain/user.

get

Retrieves details of the specified object.

list

Retrieves information about the specified object from the container you specify. This command not only retrieves the name of the object, but also all other details of the object. For some objects, you can also use additional arguments to filter the output.

update

Updates values of all the parameters of the specified object. If you don’t provide a value for a parameter while running this command, that parameter is set to null. Before running the update command, you can run the get command to retrieve all the parameter values that are currently assigned, so that you can identify the values you want to retain and the ones you want to change.

Accessing Context-Sensitive Help at the Command Line

While executing a command, you can access context-sensitive help at the command line. Here are a few examples.

  • opc --help

    Provides information about the general syntax to use the CLI.

  • opc compute --help

    Provides information about the general syntax to use the opc compute CLI, the command-line options, and lists all the Compute Classic resources that you can manage using the CLI.

  • opc compute instances -help

    Describes the Compute Classic resource, instances in this example and lists the actions that you can take on this resource.

    SUMMARY:
       An Compute Classic instance is a virtual machine running a specific operating system and with CPU and memory resources that you specify
    
    USAGE:
       opc compute instances command [arguments...] [options...]
    
    COMMANDS:
          delete    Delete an Instance
          discover  Retrieve Names of all Instances in a Container
          get       Retrieve Details of an Instance
          list      Retrieve Details of all Instances in a Container
    
    OPTIONS:
       --help, -h  show help
    
  • opc compute instances get -help

    Provides the syntax to perform the specified action on the specified resource. In this example, the get action is performed on the instances resource. It also lists all the required and mandatory arguments to run the command and describes each argument.

    NAME:
       compute instances get - Retrieve Details of an Instance
    
    USAGE:
       compute instances get name
    
    DESCRIPTION:
       Retrieve Details of an Instance
    
    REQUIRED ARGUMENTS:
       name - Multipart name of the object.
    

The CLI also prompts you to enter the correct command, if you misspell the action or the resource name. For example:

  • opc compute orchestaration 
    Can't find "orchestaration", did you mean "orchestration"? 
  • opc compute orchestration updat 
    Can't find "updat", did you mean "update"?