-
Notifications
You must be signed in to change notification settings - Fork 53
New functionalities and modules #106
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
base: master
Are you sure you want to change the base?
Changes from 12 commits
df699f9
afa0b3a
984273c
40bd48f
e601fe4
3c7ebf2
5b3619a
626af5c
52fc42f
7bfd36a
2a11c41
ff10451
5d3e51d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/python | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
|
|
||
| from ansible.module_utils.basic import AnsibleModule | ||
|
|
||
| __metaclass__ = type | ||
|
|
||
| DOCUMENTATION = ''' | ||
| --- | ||
| module: dedicated_server_compatible_templates | ||
| short_description: Retrieve all compatible templates for a OVH dedicated server | ||
| description: | ||
| - This module retrieves all compatibile templates for a OVH dedicated server | ||
| author: Saul Bertuccio | ||
| requirements: | ||
| - ovh >= 0.5.0 | ||
| options: | ||
| service_name: | ||
| required: true | ||
| description: The service_name | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for snake case here: |
||
| ''' | ||
|
|
||
| EXAMPLES = r''' | ||
| - name: Retrieve all compatible templates for an OVH dedicated server | ||
| synthesio.ovh.dedicated_server_compatibile_templates: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: |
||
| service_name: "{{ service_name }}" | ||
| delegate_to: localhost | ||
| register: dedicated_templates | ||
| ''' | ||
|
|
||
| RETURN = ''' # ''' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are barely not using this, but your module is returning a dictionary |
||
|
|
||
| from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, ovh_argument_spec | ||
|
|
||
|
|
||
| def run_module(): | ||
| module_args = ovh_argument_spec() | ||
| module_args.update(dict( | ||
| service_name=dict(required=True) | ||
| )) | ||
|
|
||
| module = AnsibleModule( | ||
| argument_spec=module_args, | ||
| supports_check_mode=True | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no support for check mode in this module |
||
| ) | ||
| client = OVH(module) | ||
|
|
||
| service_name = module.params['service_name'] | ||
| result = client.wrap_call("GET", f"/dedicated/server/{service_name}/install/compatibleTemplates") | ||
|
|
||
| module.exit_json(changed=False, **result) | ||
|
|
||
| def main(): | ||
| run_module() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
|
|
||
| from ansible.module_utils.basic import AnsibleModule | ||
|
|
||
| DOCUMENTATION = ''' | ||
| DOCUMENTATION = """ | ||
| --- | ||
| module: dedicated_server_install | ||
| short_description: Install a new dedicated server | ||
|
|
@@ -25,6 +25,9 @@ | |
| template: | ||
| required: true | ||
| description: template to use to spawn the server | ||
| disk_group_id: | ||
| required: false | ||
| description: The disk group ID to use for OS installation | ||
| soft_raid_devices: | ||
| required: false | ||
| description: number of devices in the raid software | ||
|
|
@@ -35,7 +38,7 @@ | |
| required: false | ||
| description: enable (md) or disable (jbod) software raid | ||
|
|
||
| ''' | ||
| """ | ||
|
|
||
| EXAMPLES = r''' | ||
| - name: Install a new dedicated server | ||
|
|
@@ -56,18 +59,22 @@ | |
|
|
||
| from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, ovh_argument_spec | ||
|
|
||
|
|
||
| def run_module(): | ||
| module_args = ovh_argument_spec() | ||
| module_args.update(dict( | ||
| service_name=dict(required=True), | ||
| hostname=dict(required=True), | ||
| template=dict(required=True), | ||
| soft_raid_devices=dict(required=False, default=None), | ||
| partition_scheme_name=dict(required=False, default="default"), | ||
| raid=dict(choices=['enabled', 'disabled'], default='enabled', required=False), | ||
| user_metadata=dict(type="list", requirements=False, default=None) | ||
| )) | ||
| module_args.update( | ||
| dict( | ||
| service_name=dict(required=True), | ||
| hostname=dict(required=True), | ||
| template=dict(required=True), | ||
| disk_group_id=dict(required=False, default=1), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default should be |
||
| soft_raid_devices=dict(required=False, default=None), | ||
| partition_scheme_name=dict(required=False, default="default"), | ||
| raid=dict( | ||
| choices=["enabled", "disabled"], default="enabled", required=False | ||
| ), | ||
| user_metadata=dict(type="list", requirements=False, default=None), | ||
| ) | ||
| ) | ||
|
|
||
| module = AnsibleModule( | ||
| argument_spec=module_args, | ||
|
|
@@ -82,6 +89,7 @@ def run_module(): | |
| raid = module.params['raid'] | ||
| partition_scheme_name = module.params['partition_scheme_name'] | ||
| user_metadata = module.params['user_metadata'] | ||
| disk_group_id = module.params["disk_group_id"] | ||
|
|
||
| if module.check_mode: | ||
| module.exit_json(msg=f"Installation in progress on {service_name} as {hostname} with template {template} - (dry run mode)", | ||
|
|
@@ -99,12 +107,15 @@ def run_module(): | |
| elif raid == 'disabled': | ||
| no_raid = True | ||
|
|
||
| details = {"details": | ||
| {"language": "en", | ||
| "customHostname": hostname, | ||
| "softRaidDevices": soft_raid_devices, | ||
| "noRaid": no_raid} | ||
| } | ||
| details = { | ||
| "details": { | ||
| "language": "en", | ||
| "customHostname": hostname, | ||
| "softRaidDevices": soft_raid_devices, | ||
| "noRaid": no_raid, | ||
| "diskGroupId": disk_group_id, | ||
| } | ||
| } | ||
|
|
||
| client.wrap_call( | ||
| "POST", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/python | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
|
|
||
| from ansible.module_utils.basic import AnsibleModule | ||
|
|
||
| __metaclass__ = type | ||
|
|
||
| DOCUMENTATION = ''' | ||
| --- | ||
| module: dedicated_server_specification_hardware | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This module should rather be called |
||
| short_description: Retrieve all hardware specification for a OVH dedicated server | ||
| description: | ||
| - This module retrieves all hardware information for a OVH dedicated server | ||
| author: Saul Bertuccio | ||
| requirements: | ||
| - ovh >= 0.5.0 | ||
| options: | ||
| service_name: | ||
| required: true | ||
| description: The service_name | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo: |
||
| ''' | ||
|
|
||
| EXAMPLES = r''' | ||
| - name: Retrieve all hardwared information for an OVH dedicated server | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo: |
||
| synthesio.ovh.dedicated_server_info: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrong module name |
||
| service_name: "{{ service_name }}" | ||
| delegate_to: localhost | ||
| register: dedicated_hardware | ||
| ''' | ||
|
|
||
| RETURN = ''' # ''' | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A dictionary is returned by the module |
||
|
|
||
| from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, ovh_argument_spec | ||
|
|
||
| def run_module(): | ||
| module_args = ovh_argument_spec() | ||
| module_args.update(dict( | ||
| service_name=dict(required=True) | ||
| )) | ||
|
|
||
| module = AnsibleModule( | ||
| argument_spec=module_args, | ||
| supports_check_mode=True | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No check mode here |
||
| ) | ||
| client = OVH(module) | ||
|
|
||
| service_name = module.params['service_name'] | ||
| result = client.wrap_call("GET", f"/dedicated/server/{service_name}/specifications/hardware") | ||
|
|
||
| module.exit_json(changed=False, **result) | ||
|
|
||
|
|
||
| def main(): | ||
| run_module() | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,12 @@ | |
| required: true | ||
| description: | ||
| - The region where the instance is deployed | ||
| force_delete: | ||
| required: false | ||
| description: | ||
| - Force the instance deletion even if it is not in ACTIVE status | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's |
||
|
|
||
|
|
||
| """ | ||
|
|
||
| EXAMPLES = """ | ||
|
|
@@ -56,6 +62,7 @@ def run_module(): | |
| name=dict(required=True), | ||
| service_name=dict(required=True), | ||
| region=dict(required=True), | ||
| force_delete=dict(required=False, default=False) | ||
| ) | ||
| ) | ||
| module = AnsibleModule(argument_spec=module_args, supports_check_mode=True) | ||
|
|
@@ -64,6 +71,7 @@ def run_module(): | |
| name = module.params["name"] | ||
| service_name = module.params["service_name"] | ||
| region = module.params["region"] | ||
| force_delete = module.params["force_delete"] | ||
|
|
||
| instances_list = client.wrap_call( | ||
| "GET", f"/cloud/project/{service_name}/instance", region=region | ||
|
|
@@ -76,7 +84,7 @@ def run_module(): | |
| instance_details = client.wrap_call( | ||
| "GET", f"/cloud/project/{service_name}/instance/{instance_id}" | ||
| ) | ||
| if instance_details["status"] == "ACTIVE": | ||
| if instance_details["status"] == "ACTIVE" and not force_delete: | ||
| module.fail_json(msg="Instance must not be active to be deleted", changed=False) | ||
|
|
||
| client.wrap_call( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #!/usr/bin/python | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| from __future__ import (absolute_import, division, print_function) | ||
|
|
||
| from ansible.module_utils.basic import AnsibleModule | ||
|
|
||
| __metaclass__ = type | ||
|
|
||
| DOCUMENTATION = ''' | ||
| --- | ||
| module: public_cloud_instance_manage | ||
| short_description: Start or stop a OVH public cloud instance | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| description: | ||
| - This module perform a Start/Stop/Shelve/Unshelve of an OVH public cloud instance | ||
| author: Saul Bertuccio <[email protected]> | ||
| requirements: | ||
| - ovh >= 0.5.0 | ||
| options: | ||
| service_name: | ||
| required: true | ||
| description: The service_name | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| instance_id: | ||
| required: true | ||
| description: The instance uuid | ||
| instance_action: | ||
| required: true | ||
| description: start, stop, shelve, unshelve | ||
| ''' | ||
|
|
||
| EXAMPLES = r''' | ||
| - name: Stop a OVH public cloud instance | ||
| synthesio.ovh.public_cloud_instance_manage: | ||
| instance_id: "{{ instance_id }}" | ||
| service_name: "{{ service_name }}" | ||
| instance_action: stopped | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the option for this is |
||
| delegate_to: localhost | ||
| ''' | ||
|
|
||
| RETURN = ''' # ''' | ||
|
|
||
| from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, ovh_argument_spec | ||
|
|
||
| def run_module(): | ||
| module_args = ovh_argument_spec() | ||
| module_args.update(dict( | ||
| service_name=dict(required=True), | ||
| instance_id=dict(required=True), | ||
| instance_action=dict(required=True, choices=["start", "stop", "shelve", "unshelve"]) | ||
| )) | ||
|
|
||
| module = AnsibleModule( | ||
| argument_spec=module_args, | ||
| supports_check_mode=True | ||
| ) | ||
| client = OVH(module) | ||
|
|
||
| instance_id = module.params['instance_id'] | ||
| service_name = module.params['service_name'] | ||
| instance_action = module.params['instance_action'] | ||
|
|
||
| # Set the route depending on the action | ||
| if instance_action == "start": | ||
| route = f"/cloud/project/{service_name}/instance/{instance_id}/start" | ||
| elif instance_state == "stop": | ||
| route = f"/cloud/project/{service_name}/instance/{instance_id}/stop" | ||
| elif instance_state == "shelve": | ||
| route = f"/cloud/project/{service_name}/instance/{instance_id}/shelve" | ||
| elif instance_state == "unshelve": | ||
| route = f"/cloud/project/{service_name}/instance/{instance_id}/unshelve" | ||
| else: | ||
| module.fail_json(msg=f"Instance action {instance_action} is unknown", changed=False) | ||
|
|
||
balucio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Do the call | ||
| client.wrap_call("POST", route) | ||
|
|
||
| message = f"Action {instance_action} performed on {instance_id}. This might take a couple of minutes." | ||
|
|
||
| module.exit_json( | ||
| result=message, | ||
| changed=True, | ||
| ) | ||
|
|
||
| def main(): | ||
| run_module() | ||
|
|
||
| if __name__ == '__main__': | ||
| main() | ||
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.
Typo:
compatible