Simple tools for Yandex.Cloud
Required Python 3.6+
Since July 2020, this project is DEPRECATED.
Please pay attention to python-yc-client
The reasons why the project is no longer supported are:
- legacy
- the development of a more convenient client for Yandex.Cloud.
All the functionality that was implemented in this project has been improved and transferred to the examples for the new client:
Automatically create snapshots for VM from config file (only boot-disks). Sequence for running instances: stop VM – create snapshot – start VM, for stopped instances just create snapshot.
Automatic deletion of snapshots older than N days for instances from config. The lifetime is specified in the config file.
pip install -r requirements.txt
- Create config dir
mkdir -p ~/.ya-tools - Edit
vim ydnx.cfg.example - Insert OAuth-token into config file.
- Enter instance ID into config file. For multiple instances enter space separated IDs (without the quotes).
- Enter snapshots lifetime in days.
- Move file
mv yndx.cfg.example ~/.ya-tools/yndx.cfgExample config file:
[Auth]
OAuth_token = AQAAAAYqwerty1qwerty2qwerty3
[Instances]
# Space separated instance IDs
IDs = efqwer2tyu3qwert7yz ef1xzcvbnm2qwerty1qwe
[Snapshots]
# Specify the lifetime of snapshots in days
Lifetime = 14
...
akimrx@thinkpad:~/github/yandex-cloud-tools$ ./snaps.py --help
usage: snaps.py [-h] [-v] [-c] [-d] [-f]
Snapshots-tools. To work, you must add instances id to the config file (space separated if multiple)
optional arguments:
-h, --help show this help message and exit
-v, --version show program's version number and exit
-c, --create create snapshots for VMs
-d, --delete delete all old snapshots for instances
-f, --full create snapshots and delete old snapshots for instances
--async use this arg only if disks count <= 15 (active-operations-count limit)
- Log file path:
path/to/yandex-cloud-tools/logs/snaps.log
You can run the script manually as needed, or create a task in the scheduler Cron.
- Create config dir
mkdir -p ~/.ya-tools - Edit
vim ydnx.cfg.example - Insert OAuth-token into config file.
- Enter instance ID into config file. For multiple instances enter space separated IDs (without the quotes).
- Enter snapshots lifetime in days.
- Move file
mv yndx.cfg.example ~/.ya-tools/yndx.cfgExample config file:
[Auth]
OAuth_token = AQAAAAYqwerty1qwerty2qwerty3
...
[Watchdog]
targets = efqwer2tyu3qwert7yz ef1xzcvbnm2qwerty1qwe
delay = 60
Just run script python3 watchdog.py.
Log file path: path/to/yandex-cloud-tools/logs/watchdog.log
- Create service file
sudo vim /etc/systemd/system/yc-watchdog.serviceand paste:
[Unit]
Description=YC-Watchdog
After=multi-user.target
[Service]
Type=simple
WorkingDirectory=/path/to/yandex-cloud-tools/
ExecStart=/usr/bin/python3 /path/to/yandex-cloud-tools/watchdog.py
Restart=always
RestartSec=5
StandardError=/var/log/yc-watchdog.log
[Install]
WantedBy=multi-user.target
- Enable and start daemon:
sudo systemctl daemon-reload
sudo systemctl enable yc-watchdog
sudo systemctl start yc-watchdog