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

feat: New xen orchestra module #8470

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

shinuza
Copy link
Contributor

@shinuza shinuza commented Jun 6, 2024

SUMMARY

Added a xen_orchestra module to create/start/restart/stop/delete virtual machines

ISSUE TYPE
  • New Module/Plugin Pull Request
COMPONENT NAME

xen_orchestra

@ansibullbot

This comment was marked as outdated.

@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 Jun 6, 2024
@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 Jun 7, 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! I've added some first comments.

Please note https://github.com/ansible-collections/community.general/blob/main/CONTRIBUTING.md#creating-new-modules-or-plugins, which has some more information on what you need to add/to for new modules.

plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
@shinuza
Copy link
Contributor Author

shinuza commented Jun 11, 2024

I've updated the code based on your comments, please note:

  • Some of the code comes from the inventory plugin for Xen Orchestra, meaning that some of your suggestions should probably be backported there.
  • This includes the minimum websocket-client version, which as you mentioned is 1.0.1 in the inventory code
  • Among these changes the use_ssl -> use_tls change would be breaking
  • I don't know at which point the code should be mutualized (e.g for future developments), or even if there are best-practices to mutualize code between the inventory plugins and modules.

@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 Jun 11, 2024
@felixfontein
Copy link
Collaborator

I've updated the code based on your comments, please note:

* Some of the code comes from the inventory plugin for Xen Orchestra, meaning that some of your suggestions should probably be backported there.

👍

* Among these changes the `use_ssl` -> `use_tls` change would be breaking

If applied to the inventory plugin, yes, but there an alias can be added for the old name to keep compatibility.

* I don't know at which point the code should be mutualized (e.g for future developments), or even if there are best-practices to mutualize code between the inventory plugins and modules.

There's plugins/docs_fragments/ for common documentation, and plugins/module_utils/ for shared code.

Generally sharing similar/equal docs and code is a good idea, instead of simply copying.

plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
plugins/modules/xen_orchestra.py Outdated Show resolved Hide resolved
vm_uid = module.params['vm_uid']

if state == 'stopped':
result = xen_orchestra.stop_vm(vm_uid)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Where are idempotency checks (is the VM already stopped)?

Copy link
Contributor Author

@shinuza shinuza Jun 27, 2024

Choose a reason for hiding this comment

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

See line 230, we set the task as changed=false if the api returns an error saying the VM is not in a paused, suspended or running state (meaning it's already stopped)

plugins/modules/xen_orchestra_instance.py Outdated Show resolved Hide resolved
Update version from 9.1.0 to 9.2.0

Co-authored-by: Felix Fontein <[email protected]>
@ansibullbot ansibullbot added the stale_ci CI is older than 7 days, rerun before merging label Jul 7, 2024
@shinuza
Copy link
Contributor Author

shinuza commented Jul 8, 2024

Hello,

Any more updates required? @felixfontein

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 @shinuza
Thanks for your contribution. There are few things that need tending to, see comments below. Additionally, per the collection guidelines, you must also include tests (preferably integration tests, but if not, at least unit tests).

template:
description:
- UID of a template to create Virtual Machine from.
- Muse be provided when O(state=present)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- Muse be provided when O(state=present)
- Must be provided when O(state=present).


if state == 'present':
result = xen_orchestra.create_vm()
module.exit_json(changed=True, vm_uid=result)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the VM is already present and no configuration changed, this should be False for idempotency.

raise self.module.fail_json(
'Could not delete vm: {0}'.format(answer['error']))

return answer['result']
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is that a boolean value? Because it is being passed back to the user as changed.

waited = 0
while waited < self.CALL_TIMEOUT:
response = json.loads(self.conn.recv())
if 'id' in response and response['id'] == id:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be simplified to:

Suggested change
if 'id' in response and response['id'] == id:
if response.get('id') == id:

vm_uid:
description:
- UID of the target Virtual Machine. Required when O(state=absent), O(state=started), O(state=stopped) or
O(state=restarted)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
O(state=restarted)
O(state=restarted).

@felixfontein
Copy link
Collaborator

Ping @shinuza

needs_info

@ansibullbot ansibullbot added the needs_info This issue requires further information. Please answer any outstanding questions label Aug 9, 2024
@ansibullbot
Copy link
Collaborator

@shinuza This pullrequest is waiting for your response. Please respond or the pullrequest will be closed.

click here for bot help

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 check-before-release PR will be looked at again shortly before release and merged if possible. module module needs_info This issue requires further information. Please answer any outstanding questions plugins plugin (any type) stale_ci CI is older than 7 days, rerun before merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants