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

Initial commit for Scaleway Compute #38285

Merged
merged 1 commit into from
Apr 9, 2018

Conversation

remyleone
Copy link
Contributor

SUMMARY

This PR adds support for the Scaleway Compute API.
It can create, start, stop, restart and destroy Scaleway Compute instances.

It also got a playbook to test the different steps.

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

scaleway_compute

ANSIBLE VERSION
ansible 2.6.0 (scaleway_compute 6ecb37354e) last updated 2018/04/04 18:20:23 (GMT +200)
  config file = None
  configured module search path = [u'/Users/sieben/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/sieben/workspace/ansible/lib/ansible
  executable location = /Users/sieben/workspace/ansible/bin/ansible
  python version = 2.7.14 (default, Mar  9 2018, 23:57:12) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]

@ansibot ansibot added cloud core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests. labels Apr 4, 2018
compute_api.module.fail_json(msg="Error while checking if attributes should be changed")


def server_change_attributes():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function is being worked on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done;

@remyleone
Copy link
Contributor Author

Would you suggest using an object containing the different methods? Pro: it would avoid passing the compute_api object around. Cons: This class might get quite big...

@remyleone remyleone changed the title Initial commit for Scaleway Compute [WIP] - Initial commit for Scaleway Compute Apr 5, 2018
@ansibot ansibot added the WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. label Apr 5, 2018
)


def print_warning(compute_api, msg):
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if module.debug should be used instead.

return self.status_code in (200, 201, 202, 204)


class ScalewayComputeAPI(object):
Copy link
Contributor

Choose a reason for hiding this comment

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

This class should be moved to module_utils/scaleway.py and reused by scaleway_sshkey module.

return self.send("UPDATE", path, data, headers)


def is_present(compute_api, server):
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is unused and must be removed.


if wait:
print_warning(compute_api, "(create_server) Wait is enabled")
wait_to_complete_state_transition(compute_api=compute_api, server=target_server)
Copy link
Contributor

Choose a reason for hiding this comment

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

test of wait parameter could be moved inside the wait_to_complete_state_transition method.

return response


def start_server(compute_api, server):
Copy link
Contributor

Choose a reason for hiding this comment

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

methods start_server/stop_server/restart_server are almost the same and could be factorized.


if not query_results:
changed = True
if compute_api.module.check_mode:
Copy link
Contributor

Choose a reason for hiding this comment

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

Here and below: I would prefer using something like return changed, ... than calling compute_api.module.exit_json because the caller calls exit_json anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

msg = 'Error while stopping server [{0}: {1}]'.format(response.status_code, response.json)
compute_api.module.fail_json(msg=msg)

return changed, {"status": "stopped"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not a string be used instead of {"status": "stopped"} (the same for restart_strategy method) (because dict is used as msg parameter there) ?

required=True,
),
image=dict(required=True),
name=dict(),
Copy link
Contributor

Choose a reason for hiding this comment

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

In the module documentation name is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A default name will be provided if a name is missing, therefore, it's not a required parameter. I've fixed the documentation.

@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Apr 5, 2018
@maxamillion
Copy link
Contributor

+1 the the feedback from @pilou- and other than that I think the code looks good. Please let me know when it's complete (no longer a Work In Progress) and I'm happy to provide a final review.

@remyleone remyleone force-pushed the scaleway_compute branch 5 times, most recently from 09108b3 to 5281a87 Compare April 6, 2018 12:22
@ansibot
Copy link
Contributor

ansibot commented Apr 6, 2018

The test ansible-test sanity --test pep8 [explain] failed with 2 errors:

lib/ansible/modules/cloud/scaleway/scaleway_compute.py:522:86: E128 continuation line under-indented for visual indent
lib/ansible/modules/cloud/scaleway/scaleway_compute.py:530:86: E128 continuation line under-indented for visual indent

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Apr 6, 2018
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Apr 6, 2018
@ansibot ansibot added needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Apr 6, 2018
@remyleone remyleone changed the title [WIP] - Initial commit for Scaleway Compute Initial commit for Scaleway Compute Apr 6, 2018
@remyleone
Copy link
Contributor Author

@maxamillion I think the patch is ready for its final review :)

@ansibot ansibot removed the WIP This issue/PR is a work in progress. Nevertheless it was shared for getting input from peers. label Apr 6, 2018
@ansibot
Copy link
Contributor

ansibot commented Apr 6, 2018

The test ansible-test sanity --test ansible-doc --python 2.6 [explain] failed with 1 error:

lib/ansible/modules/cloud/scaleway/scaleway_compute.py:0:0: has a documentation error formatting or is missing documentation.

The test ansible-test sanity --test compile --python 2.6 [explain] failed with 1 error:

lib/ansible/modules/cloud/scaleway/scaleway_compute.py:554:11: SyntaxError: for x in PATCH_MUTABLE_SERVER_ATTRIBUTES

The test ansible-test sanity --test import --python 2.6 [explain] failed with 1 error:

lib/ansible/modules/cloud/scaleway/scaleway_compute.py:554:11: SyntaxError: invalid syntax

The test ansible-test sanity --test pep8 [explain] failed with 1 error:

lib/ansible/modules/cloud/scaleway/scaleway_compute.py:215:1: E303 too many blank lines (3)

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Apr 6, 2018
@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Apr 6, 2018
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Apr 6, 2018
@maxamillion maxamillion merged commit eccccfe into ansible:devel Apr 9, 2018
ilicmilan pushed a commit to ilicmilan/ansible that referenced this pull request Nov 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cloud core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants