This commit is contained in:
2026-02-11 13:50:28 +03:00
parent 8c554c8edd
commit e54a9591e4
44 changed files with 6329 additions and 6756 deletions

View File

@@ -30,9 +30,10 @@ class DecortVMSnapshot(DecortController):
self.exit(fail=True)
self.vm_name = self.vm_facts['name']
self.vm_snapshots = self.vm_facts['snapSets']
self.vm_snapshots = self.api.ca.compute.snapshot_list(
vm_id=self.vm_id).data
self.vm_snapshot_labels = [
snapshot['label'] for snapshot in self.vm_snapshots
snapshot.label for snapshot in self.vm_snapshots
]
self.new_snapshot_label = None
@@ -102,21 +103,23 @@ class DecortVMSnapshot(DecortController):
if check_error:
self.exit(fail=True)
@DecortController.handle_sdk_exceptions
def run(self):
self.get_info(first_run=True)
self.get_info()
self.check_amodule_args_for_change()
self.change()
self.exit()
def get_info(self, first_run: bool = False):
if not first_run:
self.vm_snapshots = self.snapshot_list(
compute_id=self.aparams_vm_id,
)
def get_info(self, update_vm_snapshots: bool = False):
if update_vm_snapshots:
self.vm_snapshots = self.api.cloudapi.compute.snapshot_list(
vm_id=self.aparams_vm_id,
).data
label = self.new_snapshot_label or self.aparams_label
for snapshot in self.vm_snapshots:
if snapshot['label'] == label:
self.facts = snapshot
if snapshot.label == label:
self.facts = snapshot.model_dump()
if self.aparams['usage']:
self.facts['stored'] = self.get_snapshot_usage()
self.facts['vm_id'] = self.aparams_vm_id
@@ -134,11 +137,11 @@ class DecortVMSnapshot(DecortController):
self.abort_merge()
def create(self):
self.snapshot_create(
compute_id=self.aparams_vm_id,
self.sdk_checkmode(self.api.cloudapi.compute.snapshot_create)(
vm_id=self.aparams_vm_id,
label=self.new_snapshot_label,
)
self.get_info()
self.get_info(update_vm_snapshots=True)
def delete(self):
self.snapshot_delete(
@@ -149,7 +152,7 @@ class DecortVMSnapshot(DecortController):
def abort_merge(self):
self.snapshot_abort_merge(
vm_id=self.aparams_vm_id,
vm_id=self.aparams_vm_id,
label=self.aparams_label,
)
self.get_info()
@@ -161,7 +164,7 @@ class DecortVMSnapshot(DecortController):
label=label,
)
return common_snapshots_usage_info['stored']
def check_amodule_args_for_change(self):
check_errors = False
@@ -171,7 +174,7 @@ class DecortVMSnapshot(DecortController):
):
check_errors = True
self.message(
f'Check for parameter "state" failed: '
'Check for parameter "state" failed: '
'Merge can be aborted only for VM in "MERGE" tech status.'
)
@@ -179,7 +182,6 @@ class DecortVMSnapshot(DecortController):
self.exit(fail=True)
def main():
DecortVMSnapshot().run()