Posted onEdited onIncloud Symbols count in article:13kReading time ≈12 mins.
Trystack has STOPPED its service already.
In last post, we used Horizon, canonical implementation of OpenStack’s Dashboard, to request VM resource from Trystack. And finally we can connect to the VM using SSH with allocated public floating IP.
Using GUI is always the first step to start, to improve the productivity and flexibility, Openstack provides API interface as well, for writing software that manages a cloud. With that RESTful API, many software packages are developed to support Openstack operation like python-openstackclient, shade(python), pkgcloud(nodejs), Fog(ruby), ansible etc…
Request API password
First, we need get system information for the API access
Rename the downloaded file as trystackrc.sh, which includes already defined parameters like USERNAME/TENANT_NAME/PROJECT_NAME. But for keystone password, above bash script leaves blank and requires an input. See code snippet below:
1 2 3 4
# With Keystone you pass the keystone password. echo"Please enter your OpenStack Password: " read -sr OS_PASSWORD_INPUT export OS_PASSWORD=$OS_PASSWORD_INPUT
To get access with your resources in the cloud, a new API password needs to be generated.
Copy above generated “zeUC6PMLaD9eijcv”. This code cannot be recovered by Horizon Dash Board. Once lost, a new one needs to be regenerated.
REST API Usage
Source above saved trystackrc.sh in BASH shell, when prompt with “Please enter your OpenStack Password:”, enter generated “zeUC6PMLaD9eijcv” got from previous step.
1 2 3
# source trystackrc.sh Please enter your OpenStack Password: #
Request Token
Authenticate by exchanging credentials for an access token. OS_TENANT_NAME, OS_USERNAME and OS_PASSWORD are already defined in trystackrc.sh
Take note of the value [‘access’][‘token’][‘id’] value produced here (ef4fe7bc85a04053af7fcc65b1b90093 in this case), as you can use it in the calls below. Also pay attention of [‘access’][‘token’][‘expires’] and [‘access’][‘token’][‘issued_at’], the requested token is valid in ONE HOUR once it is accquired.
In section of [‘access’][‘serviceCatalog’], find publicURL with type of “compute”. It can be used with compute API calls below. For others like identity, volume, image, network etc, use this kind of way for the API public URLs.
For the complete API list and parameters definition, move to Openstack API Ref site for more information. Here we use compute API to demo the keypairs operations.
With the REST API Openstack provided, we can make text-based client that helps creating scripts to interact with OpenStack clouds. The community developed python packages for such purpose, here is the way to install openstack command line clients. For docker user, try the following way.
1
# docker run -it wangkexiong/openstackcli /bin/sh
Again we can rewrite the trystackrc.sh and put the Trystack API password in. For the security consideration, periodically renew the password on Trystack website and update in trystackrc.sh.