From c6a0236d8841305c2d48b852b2164a421418fe00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrkan=20G=C3=BCr?= Date: Fri, 5 Apr 2024 20:48:58 +0200 Subject: [PATCH] vcpu_set: Implement plus-minus operators --- igvm/cli.py | 3 +-- igvm/commands.py | 6 +++++- tests/test_integration.py | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/igvm/cli.py b/igvm/cli.py index 0173f29e..e9f64366 100644 --- a/igvm/cli.py +++ b/igvm/cli.py @@ -319,8 +319,7 @@ def parse_args(): ) subparser.add_argument( 'count', - type=int, - help='New number of CPUs', + help='New number of CPUs, integers with optional prefix + or -', ) subparser.add_argument( '--offline', diff --git a/igvm/commands.py b/igvm/commands.py index 86738f3f..f8a4aaa6 100644 --- a/igvm/commands.py +++ b/igvm/commands.py @@ -141,7 +141,11 @@ def vcpu_set(vm_hostname, count, offline=False): ) offline = False - if count == vm.dataset_obj['num_cpu']: + if str(count).startswith('+'): + count = vm.dataset_obj['num_cpu'] + int(str(count)[1:]) + elif str(count).startswith('-'): + count = vm.dataset_obj['num_cpu'] - int(str(count)[1:]) + elif count == vm.dataset_obj['num_cpu']: raise Warning('CPU count is the same.') if offline: diff --git a/tests/test_integration.py b/tests/test_integration.py index e54146b7..8449b893 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -481,6 +481,14 @@ def _get_cpus_vm(): with self.assertRaises(IGVMError): vcpu_set(VM_HOSTNAME, -5, offline=True) + vcpu_set(VM_HOSTNAME, +2) + self.assertEqual(_get_cpus_hv(), 4) + self.assertEqual(_get_cpus_vm(), 4) + + vcpu_set(VM_HOSTNAME, -2, offline=True) + self.assertEqual(_get_cpus_hv(), 2) + self.assertEqual(_get_cpus_vm(), 2) + def test_sync(self): obj = ( Query({'hostname': VM_HOSTNAME}, ['disk_size_gib', 'memory']).get()