python-compute/README.md

156 lines
3.1 KiB
Markdown
Raw Normal View History

2023-11-06 18:38:24 +03:00
# Compute
2023-11-09 20:33:13 +03:00
Compute instances management library and tools.
2023-11-06 18:38:24 +03:00
## Docs
2023-11-09 01:17:50 +03:00
Run `make serve-docs`. See [Development](#development) below.
2023-11-06 18:38:24 +03:00
## Roadmap
- [x] Create instances
- [ ] CDROM
2023-11-09 20:33:13 +03:00
- [ ] cloud-init for provisioning instances
2023-11-06 18:38:24 +03:00
- [x] Instance power management
2023-11-09 22:35:19 +03:00
- [x] Instance pause and resume
2023-11-06 18:38:24 +03:00
- [x] vCPU hotplug
2023-11-09 22:35:19 +03:00
- [x] Memory hotplug
2023-11-06 18:38:24 +03:00
- [x] Hot disk resize [not tested]
- [ ] CPU topology customization
- [x] CPU customization (emulation mode, model, vendor, features)
- [ ] BIOS/UEFI settings
- [x] Device attaching
2023-11-11 02:28:46 +03:00
- [x] Device detaching
2023-11-06 18:38:24 +03:00
- [ ] GPU passthrough
- [ ] CPU guarantied resource percent support
- [x] QEMU Guest Agent management
- [ ] Instance resources usage stats
- [ ] SSH-keys management
2023-11-11 02:28:46 +03:00
- [x] Setting user passwords in guest
2023-11-06 18:38:24 +03:00
- [x] QCOW2 disks support
- [ ] ZVOL support
- [ ] Network disks support
- [ ] Images service integration (Images service is not implemented yet)
- [ ] Manage storage pools
2023-11-09 20:33:13 +03:00
- [ ] Idempotency
- [ ] CLI [in progress]
2023-11-09 22:35:19 +03:00
- [ ] HTTP API
- [ ] Instance migrations
- [ ] Instance snapshots
- [ ] Instance backups
- [ ] LXC
2023-11-09 01:17:50 +03:00
## Development
2023-11-09 20:33:13 +03:00
Python 3.11+ is required.
2023-11-09 01:17:50 +03:00
Install [poetry](https://python-poetry.org/), clone this repository and run:
```
poetry install --with dev --with docs
```
2023-11-23 02:34:02 +03:00
# Build Debian package
Install Docker first, then run:
```
make build-deb
```
`compute` and `compute-doc` packages will built. See packaging/build directory.
# Installation
Packages can be installed via `dpkg` or `apt-get`:
```
# apt-get install ./compute*.deb
```
After installation prepare environment, run following command to start libvirtd and create required storage pools:
```
# systemctl enable --now libvirtd.service
# virsh net-start default
# virsh net-autostart default
# for pool in images volumes; do
virsh pool-define-as $pool dir - - - - "/$pool"
virsh pool-build $pool
virsh pool-start $pool
done
```
Then set environment variables in your `~/.profile`, `~/.bashrc` or global in `/etc/profile.d/compute` or `/etc/bash.bashrc`:
```
export CMP_IMAGES_POOL=images
export CMP_VOLUMES_POOL=volumes
```
Configuration file is yet not supported.
Make sure the variables are exported to the environment:
```
printenv | grep CMP_
```
If the command didn't show anything _source_ your rc files or relogin.
# Basic usage
To get help run:
```
compute --help
```
Also you can use `compute` as generic Python library. For example:
```python
from compute import Session
with Session() as session:
instance = session.get_instance('myinstance')
if not instance.is_running():
instance.start()
else:
print('instance is already running')
```
# Create compute instances
2023-11-23 02:39:06 +03:00
Place your qcow2 image in `/images` directory. For example `debian_12.qcow2`.
2023-11-23 02:34:02 +03:00
Create `instance.yaml` file with following content:
```yaml
name: myinstance
memory: 2048 # memory in MiB
vcpus: 2
image: debian_12.qcow2
volumes:
- type: file
is_system: true
target: vda
capacity:
value: 10
unit: GiB
```
Refer to `Instance` class docs for more info. Full `instance.yaml` example will be provided later.
To initialise instance run:
```
compute -l debug init instance.yaml
```
Start instance:
```
compute start myinstance
```