Using OPC CLI and Vagrant to Ease Access to Oracle Public Cloud


On your Mac or Windows machine, you can use brew or other package managers to manage different installations of scripting frameworks.  I have a customer who is using OPC (Oracle Public Cloud) pretty heavily and I wanted to simplify access to the environment.  I decided to take a look at the Oracle Compute CLI which was initially released in the Spring 2016.

This CLI rides on top of the REST API and is written using Python 2.6.  The REST API is below.

I can also add the Database CLI features which as well.  This is a java application and I will add this later.


The usability issue I had was that I didn’t want to deal with the REST API and the authentication with Postman.  I know, it is not that hard, but having the Compute CLI is much easier and I can format responses as needed.  There are some nice features in the CLI.

The downside to the Compute CLI is that it is certified on OL 6.7 and requires Python 2.6.6 or higher.  I have a Mac and I don’t plan on re-formatting my drive anytime soon.  This leaves me with Virtualbox, but I didn’t want to use the little window and do the complete ISO install and then configure. Quick, easy and agile is the way. This is where Vagrant comes in for Mac and Windows users.

The Database Cloud Service CLI is a Java 1.7 utility, so all I need to do is install Java on the OL 6.7 instance and run it from there.  I have quick gist on installing the jdk or you can download and install the jdk in a similar method that you install the rpm in this blog post.  It’s up to you.


1. Install Oracle VM VirtualBox

Just in case you don’t have it!


2. Download and install Vagrant by HashiCorp for your OS

I will assume, you know how to install vagrant and some of the basics.

3. Finding an OL 6.7 Box: vagrantboxes/ at master · terrywang/vagrantboxes · GitHub

Now, I found a OL 6.7 vagrantbox created by Terry Wang.  This seem to fit the bill for me.

More information on Oracle Linux in this FAQ if you are interested.


4. Key Steps: vagrantboxes/ at master · terrywang/vagrantboxes · GitHub

$ vagrant box add oraclelinux-6-x86_64

Note: I used OL67 for the name not oraclelinux-6-x86_64

$ mkdir test_environment

$ cd test_environment

$ vagrant init oraclelinux-6-x86_64

Note: I used “vagrant init ol67”

$ vagrant up (Creates a Vagrantfile in the directory)

$ vagrant ssh

Many Vagrant boxes can be found here:

You can also check as to what boxes you have installed with commands like

vagrant box list


5. Error on starting the Box – Hmm what to do.

Errors happen.

I was getting this error with the Box.  The Box was coming up fine, but it wasn’t mapping the shared drives.

In vagrant, by default, if you go to /vagrant (after issuing vagrant ssh command of course) you can CD to the /vagrant directory and you will be able to list the host computer directory where the Vagrantfile is located.  In the example above, it would list any files in the host directory of “test_environment”.

Remember this, we will be using it later when we do our install of the Oracle Compute CLI rpm.

In order to resolve this issue, I needed to re-install the Virtualbox additions and then restart the VM.

5.1 Vagrantfile

To re-install install the Virtualbox additions, it is easier to use the VBox GUI.  By default with the vagrant init command, the VBox GUI is not enabled,  Open the Vagrantfile in “test_environment” with your text editor and uncomment the 3 lines highlight below. Save the Vagrantfile

vagrant halt

vagrant up

And now the VBox gui shows up and you can see the complete startup of the VM.


5.2 Insert Guest Additions CD

You should have the VBox GUI

Click on the running server and then in the VBox Menu

Devices->Insert Guest Additons CD Image…

This adds the the VBox Guest Additions to the VM and now we just need to re-run the utility to make sure the shared folders mount properly.

5.3 Re-Run the Guest Additions

vagrant ssh

Change to root

sudo su –

Follow the commands in the window below.  The key is that the Guest Additions image is located at /dev/sr0 and they need to be mounted.  I created a directory under media called cdrom.

This should run cleanly since, by default, the Guest Additions are already installed for the box and they just need to be re-installed.

5.4 vagrant halt and then vagrant up

All should be good with the world with a restart.  In your initial environment, you should be able to ls the Vagrantfile.  We will add the opc-cli next.

6. OPC CLI Oracle Cloud Downloads

Accept the license agreement and then download.  I would download and copy to the “test_environment” directory and unzip there.  If you fixed the shared folder issue from above, you can then run the install directly from /vagrant on the machine. Very simple.

7. ssh back into the machine

Now vagrant ssh into the machine and then cd to /vagrant


8. Install the Compute CLI

sudo yum install ./opc-cli-1.0.0.noarch.rpm

And this will generate some output for the rpm install.  Say, yes when prompted. (For some stupid reason, I cleared my screen and cleared all of the output.)


9. Assuming all is good: ol67

If all is good then you should be able to issue oracle-compute and get the following

10. Modify .bash_profile

I use nano and if you want it installed:

sudo yum install nano

cd /home/vagrant or nano /home/vagrant/.bash_profile

At the bottom of the .bash_profile file.

For OPC_API =  notice the “” around the API

For OPC_USER = /Compute-<identitydomain>/

make sure you source the .bash_profile

$ source /home/vagrant/.bash_profile


11. Where is the API URL?

12. Add password file if you want – ol67 — vagrant@oracle:~ — ssh ◂ vagrant ssh — 128×32

Yes, I have been watching Mr. Robot. ;-), however, I am not a real hacker in any sense of the imagination.  Make sure the file permisions are set to 600

chmod 600 <filename> where the contents of the file are the password.  You can place this file anywhere. I placed it in /home/vagrant for now.


13. Compute CLI

If this works, then issue the command

oracle-compute list imagelist /oracle/public

And you will see all of the images in your identity domain.  If you are prompted for a password, then enter your identity domain password.  The file defined above can be used with the -F parameter.

14. Preparing to Use the Oracle Compute Cloud Service CLI

Remember, your role in the Identity domain deterimines your access.  This is from the docs.

Have fun…

%d bloggers like this: