Skip to content
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

Merged
merged 14 commits into from
Oct 5, 2024

Conversation

abakanovskii
Copy link
Contributor

@abakanovskii abakanovskii commented Sep 20, 2024

SUMMARY

Refactor one_image and one_image_info modules to support more parameters and make it more simillar to one_vnet and one_template to reuse already existing OpenNebula class from module_utils
Fixes #3578

ISSUE TYPE
  • Refactoring Pull Request
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 process
I also added persistent to images (see related issue) and tested all of these on my OpenNebula server and everything is working as intended

# Now this is much more verbose
- name: Gather facts about all images
  community.general.one_image_info:
  register: result

# As well as this
- name: Fetch the IMAGE by id
  community.general.one_image:
    id: 45
    state: present
  register: result

# Now this would work
- name: Make the IMAGE persistent
  community.general.one_image:
    id: 37
    persistent: true

@felixfontein felixfontein added check-before-release PR will be looked at again shortly before release and merged if possible. backport-9 Automatically create a backport for the stable-9 branch labels Sep 20, 2024
Copy link
Collaborator

@felixfontein felixfontein left a 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:

plugins/modules/one_image.py Show resolved Hide resolved
@ansibullbot

This comment was marked as outdated.

@ansibullbot
Copy link
Collaborator

@ansibullbot ansibullbot added ci_verified Push fixes to PR branch to re-run CI module module needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR plugins plugin (any type) labels Sep 20, 2024
@ansibullbot ansibullbot added integration tests/integration tests tests ci_verified Push fixes to PR branch to re-run CI and removed ci_verified Push fixes to PR branch to re-run CI labels Sep 20, 2024
@ansibullbot

This comment was marked as outdated.

@ansibullbot ansibullbot removed ci_verified Push fixes to PR branch to re-run CI needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR labels Sep 20, 2024
@abakanovskii abakanovskii changed the title One image update one_image/one_image_info: refactor Sep 20, 2024
Copy link
Collaborator

@russoz russoz left a 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.

changelogs/fragments/8889-refactor-one-image-modules.yml Outdated Show resolved Hide resolved
changelogs/fragments/8889-refactor-one-image-modules.yml Outdated Show resolved Hide resolved
Comment on lines 337 to 379
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
Copy link
Collaborator

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.

Copy link
Contributor Author

@abakanovskii abakanovskii Sep 23, 2024

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!

@ansibullbot ansibullbot added the module_utils module_utils label Sep 23, 2024
Copy link
Collaborator

@russoz russoz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

plugins/modules/one_image.py Show resolved Hide resolved
plugins/modules/one_image.py Outdated Show resolved Hide resolved
plugins/modules/one_image.py Show resolved Hide resolved
plugins/modules/one_image_info.py Show resolved Hide resolved
@felixfontein
Copy link
Collaborator

Looks good from my side. If nobody objects, I'll merge on the weekend.

@felixfontein felixfontein removed the check-before-release PR will be looked at again shortly before release and merged if possible. label Oct 5, 2024
@felixfontein felixfontein merged commit fea0ffa into ansible-collections:main Oct 5, 2024
141 checks passed
Copy link

patchback bot commented Oct 5, 2024

Backport to stable-9: 💚 backport PR created

✅ Backport PR branch: patchback/backports/stable-9/fea0ffa5aa8d90a01616e596e03c6e78fb3f887c/pr-8889

Backported as #8984

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

patchback bot pushed a commit that referenced this pull request Oct 5, 2024
* 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)
@felixfontein
Copy link
Collaborator

@abakanovskii thanks for your contribution!
@russoz thanks for reviewing!

felixfontein pushed a commit that referenced this pull request Oct 5, 2024
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-9 Automatically create a backport for the stable-9 branch integration tests/integration module_utils module_utils module module plugins plugin (any type) tests tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement persistent/non persistent flag for OpenNebula images
4 participants