Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion igvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Copyright (c) 2024 InnoGames GmbH
"""

VERSION = (2, 2, 5)
VERSION = (2, 3, 0)
9 changes: 4 additions & 5 deletions igvm/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from logging import StreamHandler, root as root_logger
import time

from fabric.network import disconnect_all
from igvm.host import disconnect_all

from igvm.commands import (
change_address,
Expand Down Expand Up @@ -60,7 +60,7 @@ def format_help(self):
out.append(ColorFormatters.BOLD.format(choice))
if subparser.get_default('func').__doc__:
out.append('\n'.join(
'\t{}'.format(l.strip()) for l in subparser
f'\t{line.strip()}' for line in subparser
.get_default('func').__doc__.strip().splitlines()
))
out.append('\n\t{}'.format(subparser.format_usage()))
Expand Down Expand Up @@ -495,9 +495,8 @@ def main():
try:
args.pop('func')(**args)
finally:
# Fabric requires the disconnect function to be called after every
# use. We are also taking our chance to disconnect from
# the hypervisors.
# Disconnect all SSH connections. We are also taking our chance
# to disconnect from the hypervisors.
disconnect_all()
close_virtconns()

Expand Down
28 changes: 28 additions & 0 deletions igvm/colors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""igvm - Color output helpers

Copyright (c) 2026 InnoGames GmbH

Replacement for fabric.colors which is not available in fabric 3.x.
"""


def _wrap(code: int, text: str, bold: bool = False) -> str:
if bold:
return f'\033[1;{code}m{text}\033[0m'
return f'\033[{code}m{text}\033[0m'


def green(text: str, bold: bool = False) -> str:
return _wrap(32, text, bold)


def red(text: str, bold: bool = False) -> str:
return _wrap(31, text, bold)


def yellow(text: str, bold: bool = False) -> str:
return _wrap(33, text, bold)


def white(text: str, bold: bool = False) -> str:
return _wrap(37, text, bold)
22 changes: 3 additions & 19 deletions igvm/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
from adminapi import parse
from adminapi.dataset import Query, DatasetError
from adminapi.filters import Any, BaseFilter, StartsWith, Contains
from fabric.colors import green, red, white, yellow
from fabric.network import disconnect_all
from igvm.colors import green, red, white, yellow
from igvm.host import disconnect_all
from jinja2 import Environment, PackageLoader
from libvirt import libvirtError

Expand All @@ -28,7 +28,6 @@
InconsistentAttributeError,
InvalidStateError, NetworkError,
)
from igvm.host import with_fabric_settings
from igvm.hypervisor import Hypervisor
from igvm.hypervisor_preferences import sort_by_preference
from igvm.settings import (
Expand Down Expand Up @@ -63,7 +62,6 @@ def _check_defined(vm, fail_hard=True):
log.info(error)


@with_fabric_settings
def evacuate(
hv_hostname: str,
target_hv_query: Optional[str] = None,
Expand Down Expand Up @@ -121,7 +119,6 @@ def evacuate(
)


@with_fabric_settings
def vcpu_set(vm_hostname, count, offline=False):
"""Change the number of CPUs in a VM"""
with ExitStack() as es:
Expand Down Expand Up @@ -182,7 +179,6 @@ def vcpu_set(vm_hostname, count, offline=False):
vm.start()


@with_fabric_settings
def mem_set(vm_hostname, size, offline=False):
"""Change the memory size of a VM

Expand Down Expand Up @@ -231,7 +227,6 @@ def mem_set(vm_hostname, size, offline=False):
vm.start()


@with_fabric_settings
def disk_set(vm_hostname, size):
"""Change the disk size of a VM

Expand Down Expand Up @@ -272,7 +267,6 @@ def disk_set(vm_hostname, size):
vm.dataset_obj.commit()


@with_fabric_settings
def change_address(
vm_hostname, new_address,
offline=False, migrate=False, allow_reserved_hv=False,
Expand Down Expand Up @@ -351,7 +345,6 @@ def change_address(
vm.start()


@with_fabric_settings
def vm_build(
vm_hostname: str,
run_puppet: bool = True,
Expand Down Expand Up @@ -455,7 +448,6 @@ def vm_build(
vm.dataset_obj.commit()


@with_fabric_settings # NOQA: C901
def vm_migrate(
vm_hostname: str = None,
vm_object=None,
Expand Down Expand Up @@ -513,7 +505,7 @@ def vm_migrate(
# likely that a specific hypervisor was requested. Any other filter
# could resolve to multiple HVs.
and (not isinstance(hv_filter['hostname'], BaseFilter)
or type(hv_filter['hostname']) == BaseFilter)
or type(hv_filter['hostname']) is BaseFilter)
):
hypervisor = es.enter_context(_get_hypervisor(
hv_filter['hostname'],
Expand Down Expand Up @@ -616,7 +608,6 @@ def _reset_hypervisor():
previous_hypervisor.undefine_vm(_vm)


@with_fabric_settings
def vm_start(vm_hostname):
"""Start a VM"""
with _get_vm(vm_hostname) as vm:
Expand All @@ -635,7 +626,6 @@ def vm_start(vm_hostname):
)


@with_fabric_settings
def vm_stop(vm_hostname, force=False):
"""Gracefully stop a VM"""
with _get_vm(vm_hostname, allow_retired=True) as vm:
Expand All @@ -660,7 +650,6 @@ def vm_stop(vm_hostname, force=False):
log.info('"{}" is stopped.'.format(vm.fqdn))


@with_fabric_settings
def vm_restart(vm_hostname, force=False, no_redefine=False):
"""Restart a VM

Expand Down Expand Up @@ -696,7 +685,6 @@ def vm_restart(vm_hostname, force=False, no_redefine=False):
log.info('"{}" is restarted.'.format(vm.fqdn))


@with_fabric_settings
def vm_delete(vm_hostname, retire=False):
"""Delete the VM from the hypervisor and from serveradmin

Expand Down Expand Up @@ -762,7 +750,6 @@ def vm_delete(vm_hostname, retire=False):
)


@with_fabric_settings
def vm_sync(vm_hostname):
"""Synchronize VM resource attributes to Serveradmin

Expand Down Expand Up @@ -822,7 +809,6 @@ def vm_define(vm_hostname):
vm_hostname, vm_dataset_obj['hypervisor']['hostname']))


@with_fabric_settings # NOQA: C901
def host_info(vm_hostname):
"""Extract runtime information about a VM

Expand Down Expand Up @@ -933,7 +919,6 @@ def _progress_bar(free_key, capacity_key, result_key, unit):
print('{} : {}'.format(k.ljust(max_key_len), value))


@with_fabric_settings
def vm_rename(vm_hostname, new_hostname, offline=False):
"""Redefine the VM on the same hypervisor with a different name

Expand Down Expand Up @@ -971,7 +956,6 @@ def vm_rename(vm_hostname, new_hostname, offline=False):
vm.aws_rename(new_hostname)


@with_fabric_settings
def clean_cert(hostname: str):
"""Revoke and delete a Puppet certificate from the Puppet CA"""
vm = Query({'hostname': hostname}, ['hostname', 'puppet_ca']).get()
Expand Down
2 changes: 0 additions & 2 deletions igvm/drbd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Copyright (c) 2018 InnoGames GmbH
"""

from adminapi import api
from contextlib import contextmanager
from igvm.exceptions import RemoteCommandError
from igvm.settings import DEFAULT_VG_NAME
Expand Down Expand Up @@ -188,7 +187,6 @@ def get_host_config(self):
addr=self.hv.dataset_obj['intern_ip'],
port=self.get_device_port(),
dm_minor=self.get_device_minor(),
lv_name=self.lv_name,
disk=(
'mapper/{}_orig'.format(self.lv_name)
if self.master_role
Expand Down
Loading