Package: cs
A simple, yet powerful CloudStack API client for python and the command-line.Async support.All present and future CloudStack API calls and parameters are supported.Syntax highlight in the command-line client if Pygments is installed.BSD license.Installationpip install cs

# with the colored output
pip install cs[highlight]

# with the async support
pip install cs[async]

# with both
pip install cs[async,highlight]UsageIn Python:fromcsimportCloudStackcs=CloudStack(endpoint='https://api.exoscale.ch/v1',key='cloudstack api key',secret='cloudstack api secret')vms=cs.listVirtualMachines()cs.createSecurityGroup(name='web',description='HTTP traffic')From the command-line, this requires some configuration:cat $HOME/.cloudstack.ini[cloudstack]endpoint=https://api.exoscale.ch/v1key=cloudstack api keysecret=cloudstack api secret# Optional ca authority certificateverify=/path/to/certs/exoscale_ca.crt# Optional client PEM certificatecert=/path/to/client_exoscale.pem# If you need to pass the certificate and key as separate filescert_key=/path/to/client_key.pemThen:$cslistVirtualMachines{"count":1,"virtualmachine":[{"account":"...",...}]}$csauthorizeSecurityGroupIngress\cidrlist="0.0.0.0/0"endport=443startport=443\securitygroupname="blah blah"protocol=tcpThe command-line client polls when async results are returned. To disable
polling, use the--asyncflag.To find the list CloudStack API calls go tohttp://cloudstack.apache.org/api.htmlConfigurationConfiguration is read from several locations, in the following order:TheCLOUDSTACK_ENDPOINT,CLOUDSTACK_KEY,CLOUDSTACK_SECRETandCLOUDSTACK_METHODenvironment variables,ACLOUDSTACK_CONFIGenvironment variable pointing to an.inifile,ACLOUDSTACK_VERIFY(optional) environment variable pointing to a CA authority cert file,ACLOUDSTACK_CERT(optional) environment variable pointing to a client PEM cert file,ACLOUDSTACK_CERT_KEY(optional) environment variable pointing to a client PEM certificate key file,Acloudstack.inifile in the current working directory,A.cloudstack.inifile in the home directory.To use that configuration scheme from your Python code:fromcsimportCloudStack,read_configcs=CloudStack(**read_config())Note thatread_config()can raiseSystemExitif no configuration is
found.CLOUDSTACK_METHODor themethodentry in the configuration file can be
used to change the HTTP verb used to make CloudStack requests. By default,
requests are made with the GET method but CloudStack supports POST requests.
POST can be useful to overcome some length limits in the CloudStack API.CLOUDSTACK_TIMEOUTor thetimeoutentry in the configuration file can
be used to change the HTTP timeout when making CloudStack requests (in
seconds). The default value is 10.CLOUDSTACK_RETRYor theretryentry in the configuration file
(integer) can be used to retrylistandqueryAsyncrequests on
failure. The default value is 0, meaning no retry.CLOUDSTACK_JOB_TIMEOUTor thejob_timeout`entry in the configuration file
(float) can be used to set how long an async call is retried assumingfetch_resultis set to true). The default value isNone, it waits forever.CLOUDSTACK_POLL_INTERVALor thepoll_intervalentry in the configuration file (number of seconds, float) can be used to set how frequently polling an async job result is done. The default value is 2.CLOUDSTACK_EXPIRATIONor theexpirationentry in the configuration file
(integer) can be used to set how long a signature is valid. By default, it picks
10 minutes but may be deactivated using any negative value, e.g. -1.CLOUDSTACK_DANGEROUS_NO_TLS_VERIFYor thedangerous_no_tls_verifyentry
in the configuration file (boolean) can be used to deactivate the TLS verification
made when using the HTTPS protocol.Multiple credentials can be set in.cloudstack.ini. This allows selecting
the credentials or endpoint to use with a command-line flag.[cloudstack]endpoint=https://some-host/api/v1key=api keysecret=api secret[exoscale]endpoint=https://api.exoscale.ch/v1key=api keysecret=api secretUsage:$ cs listVirtualMachines --region=exoscaleOptionallyCLOUDSTACK_REGIONcan be used to overwrite the default regioncloudstack.For the power users that don’t want to put any secrets on disk,CLOUDSTACK_OVERRIDESlet you pick which key will be set from the
environment even if present in the ini file.PaginationCloudStack paginates requests.csis able to abstract away the pagination
logic to allow fetching large result sets in one go. This is done with thefetch_listparameter:$ cs listVirtualMachines fetch_list=trueOr in Python:cs.listVirtualMachines(fetch_list=True)Tracing HTTP requestsOnce in a while, it could be useful to understand, see what HTTP calls are made
under the hood. Thetraceflag (orCLOUDSTACK_TRACE) does just that:$ cs --trace listVirtualMachines

$ cs -t listZonesAsync clientcsprovides theAIOCloudStackclass for async/await calls in Python
3.5+.importasynciofromcsimportAIOCloudStack,read_configcs=AIOCloudStack(**read_config())asyncdefmain():vms=awaitcs.listVirtualMachines(fetch_list=True)print(vms)asyncio.run(main())Async deployment of multiple VMsimportasynciofromcsimportAIOCloudStack,read_configcs=AIOCloudStack(**read_config())machine={"zoneid":...,"serviceofferingid":...,"templateid":...}asyncdefmain():tasks=asyncio.gather(*(cs.deployVirtualMachine(name=f"vm-{i}",**machine,fetch_result=True)foriinrange(5)))results=awaittasks# Destroy all of them, but skip waiting on the job resultsawaitasyncio.gather(*(cs.destroyVirtualMachine(id=result['virtualmachine']['id'])forresultinresults))asyncio.run(main())Release Proceduremktmpenv -p /usr/bin/python3
pip install -U twine wheel build
cd exoscale/cs
rm -rf build dist
python -m build
twine upload dist/*LinksCloudStack API:http://cloudstack.apache.org/api.htmlExample of use:Get Started with the exoscale API client