various improvements

This commit is contained in:
ge
2023-11-23 02:34:02 +03:00
parent b9d089dd78
commit 05f90b14f2
200 changed files with 15968 additions and 84 deletions

View File

@ -1,3 +1,18 @@
# This file is part of Compute
#
# Compute is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from .guest_agent import GuestAgent
from .instance import Instance, InstanceConfig
from .schemas import InstanceSchema

View File

@ -1,3 +1,18 @@
# This file is part of Compute
#
# Compute is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""Interacting with the QEMU Guest Agent."""
import json

View File

@ -1,3 +1,18 @@
# This file is part of Compute
#
# Compute is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""Manage compute instances."""
__all__ = ['Instance', 'InstanceConfig', 'InstanceInfo']
@ -9,6 +24,7 @@ import libvirt
from lxml import etree
from lxml.builder import E
from compute.common import DeviceConfig, EntityConfig
from compute.exceptions import (
GuestAgentCommandNotSupportedError,
InstanceError,
@ -28,8 +44,8 @@ from .schemas import (
log = logging.getLogger(__name__)
class InstanceConfig:
"""Compute instance config builder."""
class InstanceConfig(EntityConfig):
"""Compute instance XML config builder."""
def __init__(self, schema: InstanceSchema):
"""
@ -181,10 +197,6 @@ class InstanceInfo(NamedTuple):
cputime: int
class DeviceConfig:
"""Abstract device config class."""
class Instance:
"""Manage compute instances."""
@ -492,7 +504,7 @@ class Instance:
return child[0].getparent() if child else None
def attach_device(
self, device: 'DeviceConfig', *, live: bool = False
self, device: DeviceConfig, *, live: bool = False
) -> None:
"""
Attach device to compute instance.
@ -517,7 +529,7 @@ class Instance:
self.domain.attachDeviceFlags(device.to_xml(), flags=flags)
def detach_device(
self, device: 'DeviceConfig', *, live: bool = False
self, device: DeviceConfig, *, live: bool = False
) -> None:
"""
Dettach device from compute instance.
@ -545,8 +557,8 @@ class Instance:
"""
Detach disk device by target name.
There is no ``attach_disk()`` method. Use :method:`attach_device`
with :class:`DiskConfig` as parameter.
There is no ``attach_disk()`` method. Use :func:`attach_device`
with :class:`DiskConfig` as argument.
:param name: Disk name e.g. 'vda', 'sda', etc. This name may
not match the name of the disk inside the guest OS.
@ -574,14 +586,14 @@ class Instance:
raise InstanceError(msg)
self.detach_device(DiskConfig(**disk_params), live=True)
def resize_volume(
def resize_disk(
self, name: str, capacity: int, unit: units.DataUnit
) -> None:
"""
Resize attached block device.
:param name: Disk device name e.g. `vda`, `sda`, etc.
:param capacity: New volume capacity.
:param capacity: New capacity.
:param unit: Capacity unit.
"""
self.domain.blockResize(
@ -590,6 +602,10 @@ class Instance:
flags=libvirt.VIR_DOMAIN_BLOCK_RESIZE_BYTES,
)
def get_disks(self) -> list[DiskConfig]:
"""Return list of attached disks."""
raise NotImplementedError
def pause(self) -> None:
"""Pause instance."""
if not self.is_running():
@ -600,9 +616,9 @@ class Instance:
"""Resume paused instance."""
self.domain.resume()
def list_ssh_keys(self, user: str) -> list[str]:
def get_ssh_keys(self, user: str) -> list[str]:
"""
Get list of SSH keys on guest for specific user.
Return list of SSH keys on guest for specific user.
:param user: Username.
"""
@ -617,7 +633,7 @@ class Instance:
"""
raise NotImplementedError
def remove_ssh_keys(self, user: str, ssh_keys: list[str]) -> None:
def delete_ssh_keys(self, user: str, ssh_keys: list[str]) -> None:
"""
Remove SSH keys from guest for specific user.
@ -632,7 +648,7 @@ class Instance:
"""
Set new user password in guest OS.
This action performs by guest agent inside guest.
This action performs by guest agent inside the guest.
:param user: Username.
:param password: Password.
@ -653,6 +669,7 @@ class Instance:
return self.domain.XMLDesc(flags)
def delete(self) -> None:
"""Undefine instance and delete local volumes."""
"""Undefine instance."""
# TODO @ge: delete local disks
self.shutdown(method='HARD')
self.domain.undefine()

View File

@ -1,3 +1,18 @@
# This file is part of Compute
#
# Compute is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
"""Compute instance related objects schemas."""
import re