OpenStack client API

Voir :

https://docs.openstack.org/python-openstackclient/pike/configuration/index.html

https://developer.rackspace.com/blog/openstack-cli-basics/

https://docs.openstack.org/security-guide/api-endpoints/api-endpoint-configuration-recommendations.html

Sur le fonctionnement des APIs :

https://adam.younglogic.com/2013/09/keystone-v3-api-examples/

https://www.oreilly.com/learning/lets-use-keystone

https://www.mirantis.com/blog/manage-openstack-projects-using-domains-havana/

http://alexconst.net/2016/02/08/ansible/

Install

Paquet Debian

apt-get install openstack-clients

Le script suivant permet de jouer avec les APIs /usr/bin/python2-openstack

Install python-openstackclient via pip

sudo apt-get install virtualenv build-essential python-dev mkdir openstackcli cd openstackcli virtualenv . source bin/activate pip install python-openstackclient sudo ln -fs $PWD/bin/openstack /usr/local/bin/ #deactivate

Install Auto-completion

openstack complete |sudo tee /etc/bash_completion.d/osc.bash_completion

Config

~/.config/openstack/clouds.yaml

clouds: devstack: auth: auth_url: http://192.168.56.11/identity/v3 username: "admin" project_id: 17780b954c3a4b04a8123ac76d68f7b4 project_name: "admin" user_domain_name: "Default" password: "toor" region_name: "RegionOne" interface: "public" identity_api_version: 3

Debug - Test flux

curl http://192.168.56.11/identity/v3

Test

openstack project list --os-cloud devstack export OS_CLOUD=devstack # python2-openstack service list openstack service list openstack project list openstack server list

Ou par variables

devstack-openrc

# # See : # * https://docs.openstack.org/python-openstackclient/pike/cli/man/openstack.html#environment-variables # * https://docs.openstack.org/newton/install-guide-ubuntu/keystone-openrc.html unset $(set |grep _ENDPOINT_ |cut -d= -f1) unset $(set |grep ^OS_ |cut -d= -f1) export LC_ALL=C # LC_ALL=C.UTF-8 export OS_NO_CACHE='true' export OS_CACERT=/etc/ssl/certs/ export OS_PROJECT_NAME='admin' export OS_USERNAME='admin' export OS_PASSWORD='toor' export OS_AUTH_URL='http://192.168.56.11/identity/v3' #export OS_DEFAULT_DOMAIN='Default' export OS_USER_DOMAIN_NAME='Default' export OS_IDENTITY_API_VERSION='3' #export OS_INTERFACE='public' #export OS_AUTH_STRATEGY='keystone' #export OS_REGION_NAME='RegionOne' #export OS_ENDPOINT_TYPE="$OS_AUTH_URL" #export CINDER_ENDPOINT_TYPE="OS_AUTH_URL" #export GLANCE_ENDPOINT_TYPE="$OS_AUTH_URL" #export KEYSTONE_ENDPOINT_TYPE="$OS_AUTH_URL" #export NOVA_ENDPOINT_TYPE="$OS_AUTH_URL" #export NEUTRON_ENDPOINT_TYPE="$OS_AUTH_URL" export OS_CLOUDNAME=devstack # Add OS_CLOUDNAME to PS1 if [ -z "${CLOUDPROMPT_ENABLED:-}" ]; then export PS1=${PS1:-""} export PS1=\${OS_CLOUDNAME:+"(\$OS_CLOUDNAME)"}\ $PS1 export CLOUDPROMPT_ENABLED=1 fi

Syntaxe

openstack --os-identity-api-version 3 --help

Exemple

openstack keypair create --public-key ~/.ssh/id_rsa.pub maclef

Pb

Pb certificate verify failed

$ openstack project list --os-cloud vio
Failed to discover available identity versions when contacting https://vio.acme.local:5000/v3. Attempting to parse version from URL.
SSL exception connecting to https://vio.acme.local:5000/v3/auth/tokens: HTTPSConnectionPool(host='vio.acme.local', port=5000): Max retries exceeded with url: /v3/auth/tokens (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

Solution

echo -n |openssl s_client -showcerts -verify 5 -connect 192.168.21.53:5000 > /usr/local/share/ca-certificates/vio.acme.local_5000.crt update-ca-certificates export OS_CACERT=/etc/ssl/certs/

Pb 'int' object has no attribute 'startswith'

$ openstack server list --os-cloud vio
'int' object has no attribute 'startswith'

Solution 1

Voir https://review.openstack.org/#/c/388832/

Patcher les fichiers ci-dessous comme https://review.openstack.org/#/c/388832/2/osc_lib/cli/client_config.py :

/usr/lib/python2.7/dist-packages/osc_lib/cli/client_config.py

/usr/lib/python2.7/dist-packages/openstackclient/common/client_config.py

Solution 2

Dans clouds.yaml remplacer identity_api_version: 3 par identity_api_version: “3”

Autres

How to Automate the Export of AWS EC2 to Your Openstack Cloud