K2 Cloud API Client
In this article:
K2 Cloud API Client#
Important
Python 3 version ≥ 3.7 is required to work with the K2 Cloud API client.
To work with various K2 Cloud API, you can use utilities from the c2-client package.
The package includes the following utilities:
c2-as— a client for Auto Scaling API;c2-ct— command-line client for CloudTrail API;c2-cw— command-line client for CloudWatch API;c2-dc— command-line client for DirectConnect API;c2-ec2— command-line client for EC2 API;c2-eks— command-line client for the EKS API;c2-elb— command-line client for the Elastic Load Balancing API;c2-iam— client to IAM API;c2-paas— command-line client for PaaS API;c2-route53— command-line client for Route53 API;c2rc-convert— utility for converting settings to be used in Windows.
To manage resources in K2 Cloud via API, you should use the customized version of the libraries python-botocore and python-boto3.
Installation#
All operation systems#
The c2-client package uses the customized versions of boto3 and botocore from the repositories C2Devel/boto3 and C2Devel/botocore. To isolate the dependencies used, install a virtual environment.
Clone the repository.
git clone https://github.com/C2Devel/c2-client.git && cd c2-client
Install the virtual environment (for Linux-based systems).
python3 -m venv .venv && source .venv/bin/activate
Install the package in the editing mode along with the dependencies from
requirements.txt.pip install -e . -r requirements.txt
Use#
Get API access settings in the cloud management console. Click the user login in the top right corner, select Profile Get API access settings.
In the C2_PROJECT variable, specify your project ID.
Add the settings you have got to environment variables:
For Windows, convert the settings file and export environment variables:
C:\> c2rc-convert path\to\c2rc.sh path\to\c2rc.bat
C:\> call path\to\c2rc.bat
For Linux, export environment variables:
source path/to/c2rc.sh
Now you can use the utilities according to documentation. For example:
c2-ec2 DescribeAvailabilityZones
c2-eks DescribeCluster name backend_production