Configure the Python SDK for OCI and run the showoci.py example

This example is using user opc on a OCI OCI VM.  

First configure the OCI CLI.  See my post here

$ python3 -mvenv pythonocienv

$ source pythonocienv/bin/activate

(pythonocienv) [opc@myhost ~]$ pip install oci

Collecting oci

  Downloading https://files.pythonhosted.org/packages/08/1d/3169bc534bd21b831297c96e3cc621b17b7bec28d05aff407fed0b8ddd94/oci-2.21.2-py2.py3-none-any.whl (5.2MB)

    100% |████████████████████████████████| 5.2MB 210kB/s 

Collecting certifi (from oci)

  Downloading https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl (156kB)

    100% |████████████████████████████████| 163kB 5.4MB/s 

Collecting cryptography==2.8 (from oci)

  Downloading https://files.pythonhosted.org/packages/45/73/d18a8884de8bffdcda475728008b5b13be7fbef40a2acc81a0d5d524175d/cryptography-2.8-cp34-abi3-manylinux1_x86_64.whl (2.3MB)

    100% |████████████████████████████████| 2.3MB 460kB/s 

Collecting pyOpenSSL<=19.1.0,>=17.5.0 (from oci)

  Downloading https://files.pythonhosted.org/packages/9e/de/f8342b68fa9e981d348039954657bdf681b2ab93de27443be51865ffa310/pyOpenSSL-19.1.0-py2.py3-none-any.whl (53kB)

    100% |████████████████████████████████| 61kB 8.3MB/s 

Collecting pytz>=2016.10 (from oci)

  Downloading https://files.pythonhosted.org/packages/4f/a4/879454d49688e2fad93e59d7d4efda580b783c745fd2ec2a3adf87b0808d/pytz-2020.1-py2.py3-none-any.whl (510kB)

    100% |████████████████████████████████| 512kB 2.2MB/s 

Collecting python-dateutil<3.0.0,>=2.5.3 (from oci)

  Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)

    100% |████████████████████████████████| 235kB 3.6MB/s 

Collecting configparser==4.0.2 (from oci)

  Downloading https://files.pythonhosted.org/packages/7a/2a/95ed0501cf5d8709490b1d3a3f9b5cf340da6c433f896bbe9ce08dbe6785/configparser-4.0.2-py2.py3-none-any.whl

Collecting cffi!=1.11.3,>=1.8 (from cryptography==2.8->oci)

  Downloading https://files.pythonhosted.org/packages/82/7e/9cc46f072c9a414b5a6e08c5c2da5db3bff2601e69c4a6d4f6a34e6f9cfc/cffi-1.14.2-cp36-cp36m-manylinux1_x86_64.whl (400kB)

    100% |████████████████████████████████| 409kB 2.4MB/s 

Collecting six>=1.4.1 (from cryptography==2.8->oci)

  Downloading https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl

Collecting pycparser (from cffi!=1.11.3,>=1.8->cryptography==2.8->oci)

  Downloading https://files.pythonhosted.org/packages/ae/e7/d9c3a176ca4b02024debf82342dab36efadfc5776f9c8db077e8f6e71821/pycparser-2.20-py2.py3-none-any.whl (112kB)

    100% |████████████████████████████████| 112kB 7.2MB/s 

Installing collected packages: certifi, pycparser, cffi, six, cryptography, pyOpenSSL, pytz, python-dateutil, configparser, oci

Successfully installed certifi-2020.6.20 cffi-1.14.2 configparser-4.0.2 cryptography-2.8 oci-2.21.2 pyOpenSSL-19.1.0 pycparser-2.20 python-dateutil-2.8.1 pytz-2020.1 six-1.15.0

You are using pip version 9.0.3, however version 20.2.2 is available.

You should consider upgrading via the ‘pip install –upgrade pip’ command.

(pythonocienv) [opc@api2 ~]$ 

(pythonocienv) [opc@api2 ~]$ pip install –upgrade pip

Collecting pip

  Using cached https://files.pythonhosted.org/packages/5a/4a/39400ff9b36e719bdf8f31c99fe1fa7842a42fa77432e584f707a5080063/pip-20.2.2-py2.py3-none-any.whl

Installing collected packages: pip

  Found existing installation: pip 9.0.3

    Uninstalling pip-9.0.3:

      Successfully uninstalled pip-9.0.3

Successfully installed pip-20.2.2

Install Git to Pull Down the Python SDK 

As root – 

#yum install git

Clone the OCI-Python-SDK (with the samples)

(keep in mind that the directory this is installed in will be your default when you run the command.  It does not need to be under the python virtual directory.  I put mine at the root of my working directory)

(pythonocienv) [opc@myhost ~]$ git clone https://github.com/oracle/oci-python-sdk

Cloning into ‘oci-python-sdk’…

remote: Enumerating objects: 299, done.

remote: Counting objects: 100% (299/299), done.

remote: Compressing objects: 100% (205/205), done.

remote: Total 18883 (delta 156), reused 150 (delta 88), pack-reused 18584

Receiving objects: 100% (18883/18883), 14.79 MiB | 22.81 MiB/s, done.

Resolving deltas: 100% (16182/16182), done.

Configure the SDK Documentation for Reference –

https://docs.cloud.oracle.com/en-us/iaas/Content/API/Concepts/sdkconfig.htm 

Now Run the showoci example

$ cd /home/opc/oci-python-sdk/examples/showoci

To see command line information 

$ python showoci.py

Parameter -ip indicates use of instance principal.

-so summary only

-a all

  -c compute

$python showoci.py  -so -a -ip

$python showoci.py  -lq -c -ip

Examine the output of the above.  I have not included it here as it includes a lot of specific tenancy information.

Each time you use the SDK, you should source the python virtual environment as well as set your environment.  

I added to my .bashrc for that.

export export OCI_CLI_AUTH=instance_principal

. /home/opc/pythonocienv/bin/activate

Leave a Reply

Your email address will not be published. Required fields are marked *

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.