Quantcast
Viewing latest article 3
Browse Latest Browse All 31

Command Line Interface (CLI) In Oracle Cloud Infrastructure (OCI)

There are many automation tools to build and manage resources such as Compute, Networking, Database, Load Balancer, etc in Oracle Cloud Infrastructure (OCI) like APIs, SDKs, Command Line Interface(CLI), Terraform, Ansible.

In this post, I am going to cover:

  • Overview of CLI
  • Advantages of using CLI Over Cloud Console
  • Steps to install OCI Command Line Interface (CLI)
  • Basics Commands of CLI

Overview of Command Line Interface (CLI)

  • The OCI Command Line Interface (CLI) is a toolkit developed in Python.
  • CLI is a tool that lets you work with most of the available services in Oracle Cloud Infrastructure (OCI).
  • CLI works on the concept of request and response.
  • The responses received are in JSON format.

Services that can be performed by CLI in OCI:

Image may be NSFW.
Clik here to view.
Serices performed in OCI-CLI

Advantages of using CLI Over Cloud Console

  • Functionality: It can be used to easily do things that are difficult or even impossible to do with Cloud console.
  • Speed: Console will be slower than CLI.
  • Scripting & Automation: Create a script that contains a few lines of command and it will do the services in OCI and the script can be reused.

Steps to install OCI Command Line Interface (CLI)

For MacOS, Linux, and Unix

  • Open a terminal, run the following command.

bash -c “$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)

Image may be NSFW.
Clik here to view.
installing CLI in Linux

Note: CLI requests are authenticated using API keys, so we need to generate a key pair.

  • Generate the private key:

mkdir ~/.oci
openssl genrsa -out ~/.oci/oci_api_key.pem 2048

  • Generate the public key:

openssl rsa -pubout -in ~/.oci/oci_api_key.pem -out ~/.oci/oci_api_key_public.pem -passin stdin

Image may be NSFW.
Clik here to view.
public and private key

  • Copy the contents of the public key to the clipboard.

cat ~/.oci/oci_api_key_public.pem

Image may be NSFW.
Clik here to view.
public key

  • Open the navigation menu. Under Administration, go to Identity and click Users.
  • Select User (eg: K21AcademyUser).
  • Go to the API Keys under the Resources, and click Add Public Keys.
  • Paste your complete Public Keys and Click ADD.
  • Check your FingerPrint.
  • To start the configuration process we need to run command and follow the prompts:

$ oci setup config

  • Three parameters will be required.
    • Tenancy OCID: This can be found in the OCI console under Administration > Tenancy Details.
    • User OCID: which can be found in the OCI console under Identity > Users > K21AcademyUser
    • Region Name:

Image may be NSFW.
Clik here to view.
OCID and region

  • Run Following Command to get object Storage Namespace.

oci os ns get

Image may be NSFW.
Clik here to view.
namespace command

 

To know the process of installing Command Line Interface in Windows click here.

Some Basic CLI OCI Commands

  • To list the compartments in your tenancy

oci iam compartment list -c <tenancy_id>

  • Create a compartment

oci iam compartment create –name <compartment_name> -c <root_compartment_id> –description “<friendly_description>”

  • Create the Virtual Cloud Network.

oci network vcn create –compartment-id <compartment_id> –display-name “<friendly_name>” –dns-label <dns_name> –cidr-block “<0.0.0.0/0>”

To know in detail about all CLI commands in OCI click here.

Conclusion

It is not possible giving access to Oracle console to everyone in a team due to some security and privacy issues. So to perform all the services of OCI without using Oracle console CLI interface is used. I have covered the steps to install the CLI interface on Linux, Unix, and MacOS and I hope it will help you understand the whole process. If you find it helpful then share it with your friends.

Related/Further Readings

Begin Your Cloud Journey

Begin your journey towards becoming an Oracle Cloud Certified Architect Associate by joining the FREE Masterclass on “How To Become Oracle Certified Cloud Architect Associate in 8 Weeks”.

Click on the image below to register for the FREE Masterclass NOW!Image may be NSFW.
Clik here to view.
Oracle certified cloud architect

FREE Community

Click on the below image to join our FREE Telegram Group.Image may be NSFW.
Clik here to view.
OCI Telegram group

The post Command Line Interface (CLI) In Oracle Cloud Infrastructure (OCI) appeared first on Oracle Trainings.


Viewing latest article 3
Browse Latest Browse All 31

Trending Articles