mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
[PR #8889/fea0ffa5 backport][stable-9] one_image/one_image_info: refactor (#8984)
one_image/one_image_info: refactor (#8889)
* Refactor one_image
* Refactor one_image_info
* Add examples one_image
* Add CHANGELOG fragment
* Add integration tests for one_image
* Add integration tests for one_image_info
* Update one_image DOC
* Update one_image_info DOC
* Update one_image DOC
* Update one_image_info DOC
* Fix f-strings for one_image
* Update CHANGELOG fragment
* PR fixes
* PR fixes
(cherry picked from commit fea0ffa5aa
)
Co-authored-by: alexander <79072457+abakanovskii@users.noreply.github.com>
This commit is contained in:
parent
d4c29e19c0
commit
02f123877a
8 changed files with 1130 additions and 383 deletions
|
@ -16,6 +16,7 @@ from ansible.module_utils.six import string_types
|
|||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
|
||||
IMAGE_STATES = ['INIT', 'READY', 'USED', 'DISABLED', 'LOCKED', 'ERROR', 'CLONE', 'DELETE', 'USED_PERS', 'LOCKED_USED', 'LOCKED_USED_PERS']
|
||||
HAS_PYONE = True
|
||||
|
||||
try:
|
||||
|
@ -347,3 +348,90 @@ class OpenNebulaModule:
|
|||
result: the Ansible result
|
||||
"""
|
||||
raise NotImplementedError("Method requires implementation")
|
||||
|
||||
def get_image_list_id(self, image, element):
|
||||
"""
|
||||
This is a helper function for get_image_info to iterate over a simple list of objects
|
||||
"""
|
||||
list_of_id = []
|
||||
|
||||
if element == 'VMS':
|
||||
image_list = image.VMS
|
||||
if element == 'CLONES':
|
||||
image_list = image.CLONES
|
||||
if element == 'APP_CLONES':
|
||||
image_list = image.APP_CLONES
|
||||
|
||||
for iter in image_list.ID:
|
||||
list_of_id.append(
|
||||
# These are optional so firstly check for presence
|
||||
getattr(iter, 'ID', 'Null'),
|
||||
)
|
||||
return list_of_id
|
||||
|
||||
def get_image_snapshots_list(self, image):
|
||||
"""
|
||||
This is a helper function for get_image_info to iterate over a dictionary
|
||||
"""
|
||||
list_of_snapshots = []
|
||||
|
||||
for iter in image.SNAPSHOTS.SNAPSHOT:
|
||||
list_of_snapshots.append({
|
||||
'date': iter['DATE'],
|
||||
'parent': iter['PARENT'],
|
||||
'size': iter['SIZE'],
|
||||
# These are optional so firstly check for presence
|
||||
'allow_orhans': getattr(image.SNAPSHOTS, 'ALLOW_ORPHANS', 'Null'),
|
||||
'children': getattr(iter, 'CHILDREN', 'Null'),
|
||||
'active': getattr(iter, 'ACTIVE', 'Null'),
|
||||
'name': getattr(iter, 'NAME', 'Null'),
|
||||
})
|
||||
return list_of_snapshots
|
||||
|
||||
def get_image_info(self, image):
|
||||
"""
|
||||
This method is used by one_image and one_image_info modules to retrieve
|
||||
information from XSD scheme of an image
|
||||
Returns: a copy of the parameters that includes the resolved parameters.
|
||||
"""
|
||||
info = {
|
||||
'id': image.ID,
|
||||
'name': image.NAME,
|
||||
'state': IMAGE_STATES[image.STATE],
|
||||
'running_vms': image.RUNNING_VMS,
|
||||
'used': bool(image.RUNNING_VMS),
|
||||
'user_name': image.UNAME,
|
||||
'user_id': image.UID,
|
||||
'group_name': image.GNAME,
|
||||
'group_id': image.GID,
|
||||
'permissions': {
|
||||
'owner_u': image.PERMISSIONS.OWNER_U,
|
||||
'owner_m': image.PERMISSIONS.OWNER_M,
|
||||
'owner_a': image.PERMISSIONS.OWNER_A,
|
||||
'group_u': image.PERMISSIONS.GROUP_U,
|
||||
'group_m': image.PERMISSIONS.GROUP_M,
|
||||
'group_a': image.PERMISSIONS.GROUP_A,
|
||||
'other_u': image.PERMISSIONS.OTHER_U,
|
||||
'other_m': image.PERMISSIONS.OTHER_M,
|
||||
'other_a': image.PERMISSIONS.OTHER_A
|
||||
},
|
||||
'type': image.TYPE,
|
||||
'disk_type': image.DISK_TYPE,
|
||||
'persistent': image.PERSISTENT,
|
||||
'regtime': image.REGTIME,
|
||||
'source': image.SOURCE,
|
||||
'path': image.PATH,
|
||||
'fstype': getattr(image, 'FSTYPE', 'Null'),
|
||||
'size': image.SIZE,
|
||||
'cloning_ops': image.CLONING_OPS,
|
||||
'cloning_id': image.CLONING_ID,
|
||||
'target_snapshot': image.TARGET_SNAPSHOT,
|
||||
'datastore_id': image.DATASTORE_ID,
|
||||
'datastore': image.DATASTORE,
|
||||
'vms': self.get_image_list_id(image, 'VMS'),
|
||||
'clones': self.get_image_list_id(image, 'CLONES'),
|
||||
'app_clones': self.get_image_list_id(image, 'APP_CLONES'),
|
||||
'snapshots': self.get_image_snapshots_list(image),
|
||||
'template': image.TEMPLATE,
|
||||
}
|
||||
return info
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue