Getting Started

Verify Installation

OTC Extensions needs to be installed correctly. Please check Installation for further instructions. The otcextensions Python package pulls the openstacksdk package automatically as dependency which is needed to create own OpenStack scripts.

Configure Connection Credentials

In order to work with an OpenStack cloud you first need to create a Connection using your credentials. A Connection can be created in three ways, using the class itself, Configuring a clouds.yaml file, or Agency based authorization. It is recommended use Configuring a clouds.yaml file as the same config can be used across tools and languages. Examples are:

  • OpenStack Client

  • Gophercloud (library for golang)

  • Terraform (based on Gophercloud)

Note

Please be also aware that environment variables carrying credentials can be a security risk.

Creating a Minimal Python Script

At first we need to import openstack to get access to all available Proxy functions. Enable Logging is an optional step in the script and can be left out in productive usage. For communication purposes a Connection instance is created to communicate with the Cloud environment. The cloud=<NAME> represents the Connection name defined while creating the clouds.yaml file in Configuring a clouds.yaml file. The cloud-variable can be left out if environment variables are used or only one Cloud-connection is defined.

#!/usr/bin/env python3

import openstack

# optional, enable Logging on
openstack.enable_logging(True)

# Creates cloud connection
# Parameter cloud='otc' is optional for env variables or single
# clouds.yaml entry.
conn = openstack.connect(cloud='otc')

for server in conn.compute.servers():
    print(server)

Note

For further examples, see Examples.

Note

For further information about logging, please see Logging User Guide.

Run the Script

After saving the script as list_server.py. You can simply run it by using the following command.

python list_server.py

The output represents all existent OpenStack servers in your Cloud environment.

OTC Extensions specific Example for Open Telekom Cloud

The following script uses the OTC Extensions to list all existent CCE Clusters in your account.

#!/usr/bin/env python3

import openstack

# openstack.enable_logging(True)
conn = openstack.connect()

for cluster in conn.cce.clusters():
    print(cluster)

Save the file as list_cce_clusters.py and run it with:

python list_cce_clusters.py