-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
one_image/one_image_info: refactor #8889
one_image/one_image_info: refactor #8889
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution! A first comment below:
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @abakanovskii , thanks for your contribution!
I am not familiar with Open Nebula's API, and I have not spent much time looking into this. That being said, I got a couple of adjustments listed below, the rest looks good but again, I am no expert.
plugins/modules/one_image_info.py
Outdated
def get_image_info(self, image): | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not compared line by line but this looks very much the same as the matching method in one_image.py
- if so, then they should be moved to the module_utils/opennebula.py
file and reused in both. Or, if there is a tiny difference between them, maybe a the bulk of the image info could go to a common function in the utils, while these functions here and in the other module just make these smaller adjustments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that seems like a good idea, I can do something similar with other one_X modules later, Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Looks good from my side. If nobody objects, I'll merge on the weekend. |
Backport to stable-9: 💚 backport PR created✅ Backport PR branch: Backported as #8984 🤖 @patchback |
* 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 fea0ffa)
@abakanovskii thanks for your contribution! |
…ctor (#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 fea0ffa) Co-authored-by: alexander <[email protected]>
SUMMARY
Refactor
one_image
andone_image_info
modules to support more parameters and make it more simillar toone_vnet
andone_template
to reuse already existing OpenNebula class frommodule_utils
Fixes #3578
ISSUE TYPE
COMPONENT NAME
one_image
one_image_info
ADDITIONAL INFORMATION
As i already mention the goal is to make these 2 modules use already existing OpenNebula class from
module_utils
to reuse already existing methods, i also added fully extended parameters that these 2 modules in return (using xsd scheme from https://github.com/privazio/pyone/blob/master/pyone/xsd/image.xsd)There were also some problems with images that have
id=0
because of incorrect if statements so i fixed them in processI also added
persistent
to images (see related issue) and tested all of these on my OpenNebula server and everything is working as intended