Unofficial Yandex.Cloud REST API Client
Project description
[Unofficial] Yandex.Cloud REST API Client
ALPHA VERSION
Probably, this REST API Client will make your life with Yandex.Cloud a little easier.
Installing
- Installing with pip:
pip3 install yandex-cloud-client
- Also, you can install from source with:
git clone https://github.com/akimrx/python-yc-client --recursive
cd python-yc-client
make install
or
git clone https://github.com/akimrx/python-yc-client --recursive
cd python-yc-client
python3 setup.py install
Getting started
Client and authorization
The first step is to import required client of the Yandex.Cloud Services.
Each client of a Yandex.Cloud service inherits authorization from the base client, which supports three methods:
from yandex_cloud_client import ComputeClient
client = ComputeClient(oauth_token='YOUR_OAUTH_TOKEN')
from yandex_cloud_client import ComputeClient
client = ComputeClient(iam_token='YOUR_IAM_TOKEN')
import json
from yandex_cloud_client import ComputeClient
with open('/path/to/key.json', 'r') as infile:
credentials = json.load(infile)
client = ComputeClient(service_account_key=credentials)
You can get
key.json
from Yandex Cloud CLI:yc iam key create --service-account-name my-robot -o my-robot-key.json
Basic example for Instance from Compute Cloud Service
from yandex_cloud_client import ComputeClient
compute = ComputeClient(oauth_token='YOUR_OAUTH_TOKEN')
def show_instance_and_restart(instance_id):
instance = compute.instance(instance_id, metadata=True)
print('Name:', instance.name)
print('Cores:', instance.resources.cores)
print('Memory:', instance.resources.memory)
print('SSH-keys:', instance.metadata.ssh_keys)
if instance.running:
operation = instance.restart()
if operation.completed:
print(f'Instance {instance.name} restarted!')
print('Current instance state:', instance.status)
def boot_disk_snapshot(instance_id):
instance = compute.instance(instance_id)
if not instance.stopped: # also, you can use instance.status != 'STOPPED'
print('Stopping instance..')
instance.stop()
print('Creating snapshot for boot disk..')
instance.boot_disk.create_snapshot()
print('Starting instance without awaiting complete.')
instance.start(await_complete=False)
if __name__ == '__main__':
show_instance_and_restart('YOUR_INSTANCE_ID')
boot_disk_snapshot('YOUR_INSTANCE_ID')
See more examples here
Logging
This library uses the logging
module.
Example of usage:
import logging
logging.basicConfig(level=logging.INFO,
format='[%(levelname)s] %(message)s')
logger = logging.getLogger(__name__)
Borrowed arch design
The client was written under the inspiration of architecture design:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Close
Hashes for yandex-cloud-client-1.0.2b0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c560e31c180f1e3320d7e58eab93d501a407951917ec272d4b6d7fb893386f37 |
|
MD5 | 895fcc60e7f8779b6ddbdca66e319118 |
|
BLAKE2b-256 | 1a96721598dba184a2247057203742e20351f7d799a54c844470eb35c2680a36 |
Close
Hashes for yandex_cloud_client-1.0.2b0-py3.6.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 32e8564f6df8c0e46e850b8b649b0d58b744877de7c37f707e1f529a563b0ea2 |
|
MD5 | c0f9a2b05eb3f59f7e31babb55a9cf35 |
|
BLAKE2b-256 | ab8275d0dc4ccfbf0b916028d25e5e9917a2e6cb34ca636e47cb0726a8c7f06e |
Close
Hashes for yandex_cloud_client-1.0.2b0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2763dc8c1cd8cb98b9098b50b9fbcbe7e3652bf9eaed319edba406d1cc9c1c7 |
|
MD5 | 94edff906019276da674faed890381f9 |
|
BLAKE2b-256 | 7de7f1d1eb9ee36419d1fbab2bdb487765817fbcec140fee7db65ee26ec83fb9 |