Compare commits

...

7 Commits

Author SHA1 Message Date
ge
90de626999 bump version to 0.1.0-dev5 2024-05-17 00:07:51 +03:00
ge
9b8b7be2d7 fix build issue 2024-05-17 00:06:14 +03:00
ge
7289248925 fix creating instances from ISO and existing volumes 2024-05-17 00:05:38 +03:00
ge
197e272f3e do not delete volumes from images pool 2024-05-17 00:04:27 +03:00
ge
baa511f678 fix logs 2024-05-17 00:03:29 +03:00
ge
32b9600554 add computed.toml 2024-04-22 14:06:29 +03:00
ge
71ef774060 upd deps 2024-01-16 22:51:45 +03:00
10 changed files with 38 additions and 18 deletions

View File

@ -15,7 +15,7 @@
"""Compute instances management library."""
__version__ = '0.1.0-dev4'
__version__ = '0.1.0-dev5'
from .config import Config
from .instance import CloudInit, Instance, InstanceConfig, InstanceSchema

View File

@ -788,6 +788,12 @@ class Instance:
disk.source,
)
continue
if volume.storagePoolLookupByVolume().name() == 'images':
log.info(
'Volume %s skipped because it is from images pool',
volume.path(),
)
continue
log.info('Delete volume: %s', volume.path())
volume.delete()
log.info('Undefine instance')

View File

@ -17,6 +17,7 @@
import logging
from contextlib import AbstractContextManager
from pathlib import Path
from types import TracebackType
from typing import Any, NamedTuple
from uuid import uuid4
@ -245,11 +246,17 @@ class Session(AbstractContextManager):
log.info('Volume %s is CDROM device', volume_name)
elif volume.source is not None:
log.info('Using volume %s as source', volume_name)
volume_source = volume.source
if volume.capacity:
capacity = units.to_bytes(
volume.capacity.value, volume.capacity.unit
)
log.info('Getting volume %s', volume.source)
vol = volumes_pool.get_volume(Path(volume_name).name)
log.info(
'Resize volume to specified size: %s',
capacity,
)
vol.resize(capacity, unit=units.DataUnit.BYTES)
else:
capacity = units.to_bytes(
volume.capacity.value, volume.capacity.unit
@ -259,7 +266,7 @@ class Session(AbstractContextManager):
path=str(volumes_pool.path.joinpath(volume_name)),
capacity=capacity,
)
volume_source = volume_config.path
volume.source = volume_config.path
log.debug('Volume config: %s', volume_config)
if volume.is_system is True and data.image:
log.info(
@ -269,21 +276,20 @@ class Session(AbstractContextManager):
image = images_pool.get_volume(data.image)
log.info('Cloning image into volumes pool...')
vol = volumes_pool.clone_volume(image, volume_config)
log.info(
'Resize cloned volume to specified size: %s',
capacity,
)
vol.resize(capacity, unit=units.DataUnit.BYTES)
else:
log.info('Create volume %s', volume_config.name)
volumes_pool.create_volume(volume_config)
if capacity is not None:
log.info(
'Resize cloned volume to specified size: %s',
capacity,
)
vol.resize(capacity, unit=units.DataUnit.BYTES)
log.info('Attaching volume to instance...')
instance.attach_device(
DiskConfig(
type=volume.type,
device=volume.device,
source=volume_source,
source=volume.source,
target=volume.target,
is_readonly=volume.is_readonly,
bus=volume.bus,

View File

@ -119,7 +119,7 @@ class StoragePool:
'src_pool=%s src_vol=%s dst_pool=%s dst_vol=%s',
src.pool_name,
src.name,
self.pool.name,
self.pool.name(),
dst.name,
)
vol = self.pool.createXMLFrom(
@ -134,7 +134,9 @@ class StoragePool:
def get_volume(self, name: str) -> Volume | None:
"""Lookup and return Volume instance or None."""
log.info(
'Lookup for storage volume vol=%s in pool=%s', name, self.pool.name
'Lookup for storage volume vol=%s in pool=%s',
name,
self.pool.name(),
)
try:
vol = self.pool.storageVolLookupByName(name)

View File

@ -6,7 +6,7 @@ sys.path.insert(0, os.path.abspath('../..'))
project = 'Compute'
copyright = '2023, Compute Authors'
author = 'Compute Authors'
release = '0.1.0-dev4'
release = '0.1.0-dev5'
# Sphinx general settings
extensions = [

View File

@ -19,4 +19,4 @@ build: clean
$(DOCKER_CMD) run --rm -i -v $$PWD/$(BUILDDIR):/mnt --ulimit "nofile=1024:1048576" \
$(DOCKER_IMG) makepkg --nodeps --clean
# Remove unwanted files from build dir
rm $(BUILDDIR)/compute*.tar.gz $(BUILDDIR)/PKGBUILD
find $(BUILDDIR) ! -name '*.pkg.tar.zst' -type f -exec rm -f {} +

View File

@ -1,16 +1,21 @@
pkgname=compute
pkgver='0.1.0-dev4'
pkgver='%placeholder%'
pkgrel=1
pkgdesc='Compute instances management library'
arch=(any)
url=https://get.lulzette.ru/hstack/compute
license=('GPL-3-or-later')
makedepends=(python python-pip)
depends=(python libvirt libvirt-python qemu-base qemu-system-x86 qemu-img dnsmasq iptables-nft)
depends=(python libvirt libvirt-python qemu-base qemu-system-x86 qemu-img)
optdepends=(
'dnsmasq: required for default NAT/DHCP'
'iptables-nft: required for default NAT'
)
provides=(compute)
conflicts=()
package() {
pip install --no-cache-dir --no-deps --root $pkgdir ../$pkgname-*.tar.gz
install -Dm644 ../completion.bash $pkgdir/usr/share/bash-completion/completions/compute
install -Dm644 $pkgdir/usr/lib/*/site-packages/computed.toml $pkgdir/etc/compute/computed.toml
}

View File

@ -16,7 +16,7 @@ build: clean
cp -v ../../dist/compute-*[.tar.gz] $(BUILDDIR)/
cp -r ../../docs $(BUILDDIR)/
cp ../../extra/completion.bash $(BUILDDIR)/compute.bash-completion
if [ -f build.sh.bak ]; then mv build.sh{.bak,}; fi
if [ -f build.sh.bak ]; then mv build.sh.bak build.sh; fi
cp build.sh{,.bak}
awk '/authors/{gsub(/[\[\]]/,"");print $$3" "$$4}' ../pyproject.toml \
| sed "s/['<>]//g" \

View File

@ -38,6 +38,7 @@ Depends:
python3-pydantic,
mtools,
dosfstools,
Recommends:
dnsmasq,
dnsmasq-base
Suggests:

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = 'compute'
version = '0.1.0-dev4'
version = '0.1.0-dev5'
description = 'Compute instances management library'
license = 'GPL-3.0-or-later'
authors = ['ge <ge@nixhacks.net>']