This commit is contained in:
2026-09-18 12:19:28 +03:00
parent b2cb33e9a8
commit 1c0e5cfdb3
27 changed files with 1045 additions and 753 deletions

View File

@@ -46,9 +46,9 @@ class decort_image(DecortController):
)
if self.virt_image_info:
_, linked_image_info = self._image_get_by_id(
image_id=self.virt_image_info['linkTo']
image_id=self.virt_image_info['link_to']
)
self.acc_id = linked_image_info['accountId']
self.acc_id = linked_image_info['account_id']
if (
self.aparams['virt_name'] is not None
and self.aparams['virt_name']
@@ -61,10 +61,10 @@ class decort_image(DecortController):
or self.aparams['image_name'] is not None
):
self.validated_image_id, self.image_info = (
self.decort_image_find(amodule)
self.decort_image_find(amodule, fail_if_not_found=False)
)
if self.image_info:
self.acc_id = self.image_info['accountId']
self.acc_id = self.image_info['account_id']
if (
amodule.params['image_name']
and amodule.params['image_name'] != self.image_info['name']
@@ -72,6 +72,23 @@ class decort_image(DecortController):
decort_image.decort_image_rename(self,amodule)
self.result['msg'] = ("Image renamed successfully")
if (
self.validated_image_id == 0
and self.aparams['image_id']
and not self.validated_virt_image_id
and not self.aparams['virt_name']
):
if self.aparams['state'] == 'absent':
self.exit()
else:
self.message(
self.MESSAGES.obj_not_found(
obj='image',
id=self.aparams['image_id'],
)
)
self.exit(fail=True)
if self.validated_image_id:
self.check_amodule_args_for_change()
elif self.validated_virt_image_id:
@@ -81,12 +98,13 @@ class decort_image(DecortController):
else:
self.check_amodule_args_for_create_image()
def decort_image_find(self, amodule):
def decort_image_find(self, amodule, fail_if_not_found=True):
# function that finds the OS image
image_id, image_facts = self.image_find(image_id=amodule.params['image_id'], image_name=self.validated_image_name,
account_id=self.validated_account_id, rg_id=0,
sepid=amodule.params['sep_id'],
pool=amodule.params['pool'])
pool=amodule.params['pool'],
fail_if_not_found=fail_if_not_found,)
return image_id, image_facts
def decort_virt_image_find(self, amodule):
@@ -150,28 +168,30 @@ class decort_image(DecortController):
)
# function that creates OS image
image_facts = self.image_create(
img_name=self.validated_image_name,
url=amodule.params['url'],
self.sdk_checkmode(self.api.ca.image.create)(
name=self.validated_image_name,
download_url=amodule.params['url'],
boot_mode=boot_mode,
boot_loader_type=loader_type,
hot_resize=hot_resize,
username=amodule.params['image_username'],
password=amodule.params['image_password'],
os_user_name=amodule.params['image_username'],
os_password=amodule.params['image_password'],
account_id=self.validated_account_id,
usernameDL=amodule.params['usernameDL'],
passwordDL=amodule.params['passwordDL'],
sepId=amodule.params['sepId'],
poolName=amodule.params['poolName'],
download_user_name=amodule.params['usernameDL'],
download_password=amodule.params['passwordDL'],
sep_id=amodule.params['sepId'],
sep_pool_name=amodule.params['poolName'],
network_interface_naming=network_interface_naming,
storage_policy_id=amodule.params['storage_policy_id'],
)
self.result['changed'] = True
return image_facts
return
def decort_virt_image_link(self,amodule):
# function that links an OS image to a virtual one
self.virt_image_link(imageId=self.validated_virt_image_id, targetId=self.target_image_id)
self.sdk_checkmode(self.api.ca.image.link)(
virtual_image_id=self.validated_virt_image_id,
target_image_id=self.target_image_id,
)
image_id, image_facts = decort_image.decort_virt_image_find(self, amodule)
self.result['facts'] = decort_image.decort_image_package_facts(image_facts, amodule.check_mode)
self.result['msg'] = ("Image '{}' linked to virtual image '{}'").format(self.target_image_id,
@@ -189,9 +209,9 @@ class decort_image(DecortController):
def decort_virt_image_create(self,amodule):
# function that creates a virtual image
image_facts = self.virt_image_create(
self.sdk_checkmode(self.api.ca.image.create_virtual)(
name=amodule.params['virt_name'],
target_id=self.target_image_id,
target_image_id=self.target_image_id,
account_id=self.aparams['account_id'],
)
image_id, image_facts = decort_image.decort_virt_image_find(self, amodule)
@@ -250,14 +270,14 @@ class decort_image(DecortController):
ret_dict['id'] = arg_image_facts['id']
ret_dict['name'] = arg_image_facts['name']
ret_dict['size'] = arg_image_facts['size']
ret_dict['size'] = arg_image_facts['size_gb']
# ret_dict['arch'] = arg_image_facts['architecture']
ret_dict['sep_id'] = arg_image_facts['sepId']
ret_dict['pool'] = arg_image_facts['pool']
ret_dict['sep_id'] = arg_image_facts['sep_id']
ret_dict['pool'] = arg_image_facts['sep_pool_name']
ret_dict['state'] = arg_image_facts['status']
ret_dict['linkto'] = arg_image_facts['linkTo']
ret_dict['accountId'] = arg_image_facts['accountId']
ret_dict['boot_mode'] = arg_image_facts['bootType']
ret_dict['linkto'] = arg_image_facts['link_to']
ret_dict['accountId'] = arg_image_facts['account_id']
ret_dict['boot_mode'] = arg_image_facts['boot_mode']
ret_dict['boot_loader_type'] = ''
match arg_image_facts['type']:
@@ -268,13 +288,13 @@ class decort_image(DecortController):
ret_dict['boot_loader_type'] = boot_loader_type
ret_dict['network_interface_naming'] = arg_image_facts[
'networkInterfaceNaming'
'network_interface_naming'
]
ret_dict['hot_resize'] = arg_image_facts['hotResize']
ret_dict['hot_resize'] = arg_image_facts['hot_resize']
ret_dict['storage_policy_id'] = arg_image_facts['storage_policy_id']
ret_dict['to_clean'] = arg_image_facts['to_clean']
ret_dict['independent'] = arg_image_facts['independent']
ret_dict['links_to'] = arg_image_facts['linksTo']
ret_dict['links_to'] = arg_image_facts['links_to']
return ret_dict
@property
@@ -502,7 +522,7 @@ class decort_image(DecortController):
and amodule.params['storage_policy_id']
!= image_facts['storage_policy_id']
):
self.image_change_storage_policy(
self.sdk_checkmode(self.api.ca.image.change_storage_policy)(
image_id=self.validated_virt_image_id,
storage_policy_id=amodule.params['storage_policy_id'],
)
@@ -510,7 +530,7 @@ class decort_image(DecortController):
if amodule.params['state'] == "absent" and self.validated_virt_image_id:
amodule.image_id_delete = self.validated_virt_image_id
image_id, image_facts = self.decort_virt_image_find(amodule)
if image_facts['status'] != 'PURGED':
if image_facts['status'] != sdk_types.ImageStatus.PURGED:
self.decort_image_delete(amodule)
elif amodule.params['image_name'] or amodule.params['image_id']:
@@ -530,7 +550,10 @@ class decort_image(DecortController):
elif amodule.params['state'] == "absent" and self.validated_image_id:
amodule.image_id_delete = self.validated_image_id
image_id, image_facts = self.decort_image_find(amodule)
if image_facts['status'] != 'DESTROYED':
if image_facts['status'] not in [
sdk_types.ImageStatus.DESTROYED,
sdk_types.ImageStatus.PURGED,
]:
self.decort_image_delete(amodule)
if self.validated_image_id:
@@ -539,7 +562,7 @@ class decort_image(DecortController):
and amodule.params['storage_policy_id']
!= image_facts['storage_policy_id']
):
self.image_change_storage_policy(
self.sdk_checkmode(self.api.ca.image.change_storage_policy)(
image_id=self.validated_image_id,
storage_policy_id=amodule.params['storage_policy_id'],
)