This commit is contained in:
2025-02-07 13:04:30 +03:00
parent 5f3df12742
commit e537eadda6
22 changed files with 9623 additions and 84 deletions

View File

@@ -562,15 +562,16 @@ class DecortController(object):
else:
self.amodule.exit_json(**self.result)
def message(self, msg: str):
def message(self, msg: str | None = None, warning: bool = False):
"""
Append message to the new line of the string
`self.result['msg']`.
"""
if self.result.get('msg'):
self.result['msg'] += f'\n{msg}'
key_name = 'warning' if warning else 'msg'
if self.result.get(key_name):
self.result[key_name] += f'\n{msg}'
else:
self.result['msg'] = msg
self.result[key_name] = msg
def pack_amodule_init_args(self, **kwargs) -> dict:
"""
@@ -1435,7 +1436,7 @@ class DecortController(object):
def kvmvm_provision(self, rg_id,
comp_name,
cpu, ram,
boot_disk,
boot_disk,
image_id,
chipset: Literal['Q35', 'i440fx'] = 'i440fx',
description="",
@@ -1445,7 +1446,8 @@ class DecortController(object):
start_on_create=True,
cpu_pin: bool = False,
hp_backed: bool = False,
numa_affinity: Literal['none', 'loose', 'strict'] = 'none'):
numa_affinity: Literal['none', 'loose', 'strict'] = 'none',
preferred_cpu_cores: list[int] | None = None):
"""Manage KVM VM provisioning. To remove existing KVM VM compute instance use compute_remove method,
to resize use compute_resize, to manage power state use compute_powerstate method.
@@ -1482,6 +1484,7 @@ class DecortController(object):
'interfaces': '[]', # we create VM without any network connections
'chipset': chipset,
'withoutBootDisk': not boot_disk,
'preferredCpu': preferred_cpu_cores,
}
if description:
api_params['desc'] = description
@@ -1983,6 +1986,7 @@ class DecortController(object):
numa_affinity: Optional[str] = None,
description: Optional[str] = None,
auto_start: Optional[bool] = None,
preferred_cpu_cores: list[int] | None = None,
):
OBJ = 'compute'
@@ -1998,6 +2002,9 @@ class DecortController(object):
'numaAffinity': numa_affinity,
'desc': description,
'autoStart': auto_start,
'preferredCpu': (
[-1] if preferred_cpu_cores == [] else preferred_cpu_cores
),
},
)
@@ -2011,6 +2018,7 @@ class DecortController(object):
'numa_affinity': numa_affinity,
'description': description,
'auto_start': auto_start,
'preferred_cpu_cores': preferred_cpu_cores,
}
for param, value in params_to_check.items():
if value is not None:
@@ -2075,6 +2083,19 @@ class DecortController(object):
return api_resp.json()
@waypoint
@checkmode
def compute_rollback(self, compute_id: int, snapshot_label: str):
self.decort_api_call(
arg_req_function=requests.post,
arg_api_name='/restmachine/cloudapi/compute/snapshotRollback',
arg_params={
'computeId': compute_id,
'label': snapshot_label,
},
)
self.set_changed()
###################################
# OS image manipulation methods
###################################