Generic OCI Resource manipulation with OCI CLI Raw Request image 62

Generic OCI Resource manipulation with OCI CLI Raw Request

I should have been aware of it – but I was not. The generic OCI CLI Raw Request option – the uniform approach to any OCI resource query or manipulation through OCI CLI. With raw request, each call looks like this:

oci raw-request –http-method POST –target-uri  API-ENDPOINT/API-PATH/resourcetype/resource-OCID –request-body file://request.json

image

The file request.json contains the JSON formatted data to be sent as payload to the OCI API. Note that a sample of that JSON formatted payload can be generated using:

oci <service> <resource type> <operation> –generate-full-command-json-input  > request.json

for example:

oci queue messages put-messages –generate-full-command-json-input  > put-messages.json

for the OCI Queue service, the messages resource type and the put-messages operation.

For GET requests, the values to influence the API behavior are sent as query parameters – like this:

oci raw-request –http-method GET –target-uri  API-ENDPOINT/API-PATH//resourcetype/resource-OCID?parameterName=value&otherParameterName=othervalue

An example call:

oci raw-request –http-method GET –target-uri  https://cell-1.queue.messaging.us-ashburn-1.oci.oraclecloud.com/20210201/queues/ocid1.queue.oc1.iad.amaaaaaa6sde7caooq/messages?visibilityInSeconds=3599&limit=5

This call retrieves all messages on the queue whose OCID is specified – setting the visibility time out for these messages to almost one hour (3599 seconds) and retrieving up to 5 messages.

This raw request opti0n turns OCI CLI into not much more than an OCI REST API HTTP request signer – which can be very useful. Note that by adding the –-debug flag to the call , you can inspect the exact HTTP call that is made.

Example – Container Instance

See: https://docs.oracle.com/en-us/iaas/api/#/en/container-instances/20210415/

Endpoint: https://compute-containers.us-ashburn-1.oci.oraclecloud.com

Get Details for a Container Instance

GET – Path: /20210415/containerInstances/{containerInstanceId}

oci raw-request –http-method GET –target-uri  https://compute-containers.us-ashburn-1.oci.oraclecloud.com/20210415/containerInstances/ocid1.computecontainerinstance.oc1.iad.anuwcljr6sde7caaqixbrxeuu22akkenq4i3h3d2miwe3acuqpr5genlxjkq

image

Start Container Instance (and all containers)

See: https://docs.oracle.com/en-us/iaas/api/#/en/container-instances/20210415/ContainerInstance/StartContainerInstance

POST – /20210415/containerInstances/{containerInstanceId}/actions/start

oci raw-request –http-method POST –target-uri  https://compute-containers.us-ashburn-1.oci.oraclecloud.com/20210415/containerInstances/ocid1.computecontainerinstance.oc1.iad.anuwcljr6sde7caaqixbrxeuu22akkenq4i3h3d2miwe3acuqpr5genlxjkq/actions/start

image

And the console presents the effect: the container instance is starting

image

Resources

OCI CLI Raw Request documentation https://docs.oracle.com/en-us/iaas/tools/oci-cli/3.6.2/oci_cli_docs/cmdref/raw-request.html

OCI API  – Container Instances – https://docs.oracle.com/en-us/iaas/tools/oci-cli/3.22.0/oci_cli_docs/cmdref/container-instances/container-instance/get.html

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.