Installing OpenStack CLI clients

Last updated 19 December, 2018

About OpenStack CLI clients 

OpenStackClient (OSC) is a command-line client for OpenStack that brings the command set for Nova (compute), Neutron (networking), Cinder (block storage), Glance (image), and Keystone (identity) APIs together in a single shell with a uniform command structure.

OpenStack CLI clients enable faster automation of repetitive operations in HPE OneSphere.

See also Using the OpenStack CLI with HPE OneSphere.

Sourcing your OpenStack RC file

The OpenStack RC file captures the configuration parameters necessary for the OpenStack CLIs to communicate with the REST API endpoints exposed by OpenStack. HPE OneSphere exposes the RC parameters for you.

Before making any OpenStack API calls through the OpenStack CLI, you must access your private cloud zone and obtain an OpenStack Keystone endpoint mapped to the zone, then create an RC file using the retrieved Keystone endpoint, as described in the following procedure.

Procedure
  1. Log in to any Linux machine on which you want to install OpenStack CLIs.
  2. Generate an authentication token to access the OpenStack services REST API to retrieve your zone ID.

    NOTE:

    An authentication token permits access to the OpenStack services REST API. Each OpenStack project provides a command line client that enables you to access its API through CLI commands.

    curl -H "Content-Type: application/json" -X POST 
    -d '{"username": <"your-username">, "password": <"your-password">}' 
    https://<onesphere-url>/rest/session | python -m json.tool
    

    The system will return the following:

    <command statistics>
    {
        "token": <"token-Result">,
        "userUri": <"user-UriResult">
    }
  3. Use your token to retrieve your zone ID.

    NOTE:

    If you have more than one private zone connected to HPE OneSphere, make sure to retrieve the zone ID from the response.

    curl -H "Authorization: Bearer <token-Result>" 
    https://<onesphere-url>/rest/zones | python -m json.tool
    

    Here is an example of the output you can expect. The zone ID is bolded below.

    <command statistics>
    
    "clusters": [],
    "created": "2018-04-20T09:05:06.762761615Z",
    "currentTasks": [],
    "id": "f58760f2-e5ac-4f1c-ad5d-df4d3d963390",
    "kvmServers": [],
    "managed": false,
    "metrics": [],
    "modified": "2018-04-20T12:44:35.790966922Z",
    "name": "hpeftckvm1",
    "providerUri": "/rest/providers/f2154e6d-df6b-11e7-bed0-06b7e5e8411c-pcp",
    "regionUri": "/rest/regions/85dc1aa5-9a4b-4953-bba7-29380ddc45c3",
    "resourceCapacity": 0,
    "state": "Enabled",
    "status": "Ok",
    "uri": "/rest/zones/f58760f2-e5ac-4f1c-ad5d-df4d3d963390",
    "zoneTypeUri": "/rest/zone-types/kvm"
    
  4. To generate the list of OpenStack endpoints without versions associated with your zone, use the following command specifying the zone ID from the bolded output in the previous command result above.
    curl -H "Authorization: Bearer <token>" 
    https://<onesphere-url>/rest/zones/f58760f2-e5ac-4f1c-ad5d-df4d3d963390/os-endpoints | python -m json.tool

    Sample response:

    {
        "os-endpoints": [
            "https://<your-account>.hpeonesphere.com/nova",
            "https://<your-account>.hpeonesphere.com/neutron",
            "https://<your-account>.hpeonesphere.com/cinder",
            "https://<your-account>.hpeonesphere.com/heat",
            "https://<your-account>.hpeonesphere.com/keystone"
        ],
        "os-rc": [
            "export OS_AUTH_URL=https://<your-account>.hpeonesphere.com/keystone/v3",
            "export OS_IDENTITY_API_VERSION=3",
            "export OS_REGION_NAME=region1",
            "export OS_USERNAME=<username>",
            "export OS_PASSWORD=<password>",
            "export OS_PROJECT_NAME=service",
            "export OS_PROJECT_DOMAIN_ID=${OS_PROJECT_DOMAIN_ID:-'default'}",
            "export OS_USER_DOMAIN_ID=default"
        ]
    }
  5. To generate the list of OpenStack endpoints with versions associated with your zone, use the following command specifying the zone ID from the bolded output in the previous command result above.
    curl -H "Authorization: Bearer <token>" 
    https://<onesphere-url>/rest/zones/f58760f2-e5ac-4f1c-ad5d-df4d3d963390/os-endpoints?version=true | python -m json.tool

    Sample response:

    {
        "os-endpoints": [
            "https://<your-account>.hpeonesphere.com/nova/v2.1",
            "https://<your-account>.hpeonesphere.com/neutron/v2.0",
            "https://<your-account>.hpeonesphere.com/cinder/v2",
            "https://<your-account>.hpeonesphere.com/heat/v1",
            "https://<your-account>.hpeonesphere.com/keystone/v2.0"
        ],
        "os-rc": [
            "export OS_AUTH_URL=https://<your-account>.hpeonesphere.com/keystone/v3",
            "export OS_IDENTITY_API_VERSION=3",
            "export OS_REGION_NAME=region1",
            "export OS_USERNAME=<username>",
            "export OS_PASSWORD=<password>",
            "export OS_PROJECT_NAME=service",
            "export OS_PROJECT_DOMAIN_ID=${OS_PROJECT_DOMAIN_ID:-'default'}",
            "export OS_USER_DOMAIN_ID=default"
        ]
    }
  6. Copy the contents of the OpenStack RC section into a new file (such as hpe-openstack.rc) on a computer that has access to both the HPE OneSphere endpoints and the OpenStack Glance image catalog.
  7. Update the value for the OS_USERNAME and OS_PASSWORD parameters with your HPE OneSphere account username and password, then save the file.

    IMPORTANT:

    Be sure to secure the file because it contains the user information and password necessary to log in to your private cloud and the HPE OneSphere portal.

Providing access to OpenStack CLI through a proxy server 

You can make the OpenStack CLI accessible through a proxy server by setting the required environment variables for the proxy server in the OpenStack RC file.

Prerequisites

The administrator:

Procedure
  1. Set the environment variable for the proxy server you want to use in the OpenStack RC file.
    export http_proxy=http://<server-ip>:<port>/
    export https_proxy=http://<server-ip>:<port>/
    For example, if http://proxy-server.samplecorp.com/ is the URL of the proxy server, and 3128 is the port number, then you can edit the OpenStack RC file to specify the URL and port number with the following export command:
    export http_proxy=http://proxy-server.samplecorp.com:3128/
    export https_proxy=http://proxy-server.samplecorp.com:3128/
  2. (Optional) If the proxy server requires a username and password, then add the username and password in the URL.
    For example:
    export http_proxy=http://<username>:<password>@<server-ip>:<port>/
    export https_proxy=http://<username>:<password>@<server-ip>:<port>/
  3. (Optional) If one or more OpenStack services can be accessed locally, you can use the environment variable no_proxy to prevent the service from using the proxy.
    For example, you might want to access OpenStack Glance locally. In this case, you can add the following command to the OpenStack RC file.
    glance_endpoint_id=$(openstack endpoint list -f value | awk '/glance / { print $1 }')
    glanceIP=$(openstack endpoint show "$glance_endpoint_id" -c publicurl -f value | sed 's|http://||')
    export no_proxy=localhost,127.0.0.1,$glanceIP

    In this example, 127.0.0.1 is your local host IP address and glanceIP is the address reported using the OpenStack endpoint list command. 

    NOTE:

    If you know the exact IP address of your OpenStack Glance API server, you could directly assign it to glanceIP in the above command. For example: glanceIP=<glance api server ip address>.

  4. The OpenStack RC file can be sourced on the machine where you want to run the OpenStack CLI so that the OpenStack CLI is available through the proxy server.

    For example:

    source <path to saved openstack rc file>  

    TIP:

    Alternatively, you can add the export commands to the /etc/environments on the machine you want to run the OpenStack CLI.

Installing OpenStack CLI Client in a virtual environment

You can install openstackclient and neutronclient in a virtual environment, which provides the following advantages:

  • Virtual environments are self-contained, so there are no conflicts with the underlying operating system.

  • You can delete a virtual environment without causing changes to the underlying operating system.

Prerequisites
  • The host where you intend to install the OpenStack clients is running Python 2.7.

Procedure
  1. Execute the following command to install Python .

    For Centos and RHEL

    • Execute the following commands:

      yum install -y epel-release
      yum install -y gcc openssl-devel python-pip python-wheel python-virtualenv python-virtualenvwrapper
    • Load the virtualenvwrapper setup script into your current shell session.
      # location of virtualenvwrapper.sh
      source /usr/bin/virtualenvwrapper.sh
      # directory to store virtual environments
      export WORKON_HOME=$HOME/.virtenvs

    For Ubuntu

    • Update the list of available packages.

      apt-get -y update
    • Install GNU compiler library (GCC), Python, and the dependent libraries.

      apt-get -y install gcc libffi-dev libssl-dev python python-dev python-virtualenv virtualenvwrapper
    • Load the virtualenvwrapper setup script into your current shell session.

      # location of virtualenvwrapper.sh
      source /usr/share/virtualenvwrapper/virtualenvwrapper.sh 
      # directory to store virtual environments
      export WORKON_HOME=$HOME/.virtenvs
  2. Create a new virtual environment.
    mkvirtualenv os_cli
  3. From the newly created virtual environment, upgrade pip.
    pip install pip --upgrade
  4. Create a requirements.txt file with the following content in the current working directory.
    aodhclient
    gnocchiclient
    python-barbicanclient
    python-ceilometerclient
    python-cinderclient
    python-designateclient
    python-glanceclient
    python-heatclient
    python-keystoneclient
    python-muranoclient
    python-neutronclient
    python-novaclient
    python-openstackclient
  5. Run the following command to set up your OpenStack CLI.
    pip install --upgrade --requirement ./requirements.txt --constraint
    http://raw.githubusercontent.com/openstack/requirements/stable/newton/upper-constraints.txt