Client library for JCS
git clone https://github.com/jiocloudservices/jcsclient.git cd jcsclient sudo pip install -r requirements.txt # Can use virtual environment too sudo python setup.py develop
pip install -e git+https://github.com/jiocloudservices/jcsclient.git#egg=jcsclient
Copy openrc.sample to create openrc file, put your actual credentials in this file and then source this file Edit the src/client/config.py to include your credentials.
cp openrc.sample openrc # Update openrc now, and add your access/secret keys source openrc
If you are from your local machine, you might need to add entries to /etc/hosts file to map an IP to the endpoint. No need to do the same if you are using this library from a staging machien.
NOTE: Never ever commit your access and secret keys and push to a public repository. You have been warned.
You can use CLI to make an API request, or just get the input which you can use with 'curl' command.
$ jcs compute Action=DescribeInstances # Make an API call $ jcs --prettyprint compute Action=DescribeInstances # Make API call and pretty-print dictionary $ jcs --curl compute Action=DescribeInstances # Get the curl input URL $ jcs iam CreateUser --Name user1 --Password ABcwqe@12q # Make an api call to create a user $ jcs iam --help # Displays all iam actions and related client requests $ jcs iam CreateUser --help # Displays help related to action CreateUser
Once you have installed this library in your computer (systemwide or in a virtual environment), you can import the module and start using the associated Python functions. For example, the following file will list all your instances:
from client import common from client import cloud # Set up client with parameters as sourced environment variables common.setup_client_from_env_vars() # OR alternatively set up client by passing required parameters. Optional # key-value argument keys are: 'iam_url', 'dss_url' and 'rds_url' common.setup_client('myaccesskey', 'mysecretkey', 'mycomputeurl', 'myvpcurl', iam_url="http://localhost') print cloud.describe_snapshots()