Generic OCI Resource manipulation with OCI CLI Raw Request

Lucas Jellema
0 0
Read Time:2 Minute, 17 Second

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

About Post Author

Lucas Jellema

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

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

Next Post

Delayed Delivery in OCI Queue Service–time based message release

Messages published to an Oracle Cloud Infrastructure (OCI) Queue may not immediately be intended for consumption. It is a not uncommon requirement to make messages available for consumption only at a specific moment in time, rather than right away. OCI Queue does not currently have built in support for a […]
%d bloggers like this: