Skip to content
60 changes: 60 additions & 0 deletions plugins/modules/dedicated_server_compatible_templates.py
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: compatible

author: Saul Bertuccio
requirements:
- ovh >= 0.5.0
options:
service_name:
required: true
description: The service_name
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for snake case here: service name

'''

EXAMPLES = r'''
- name: Retrieve all compatible templates for an OVH dedicated server
synthesio.ovh.dedicated_server_compatibile_templates:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: compatible

service_name: "{{ service_name }}"
delegate_to: localhost
register: dedicated_templates
'''

RETURN = ''' # '''
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()
47 changes: 29 additions & 18 deletions plugins/modules/dedicated_server_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from ansible.module_utils.basic import AnsibleModule

DOCUMENTATION = '''
DOCUMENTATION = """
---
module: dedicated_server_install
short_description: Install a new dedicated server
Expand All @@ -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
Expand All @@ -35,7 +38,7 @@
required: false
description: enable (md) or disable (jbod) software raid

'''
"""

EXAMPLES = r'''
- name: Install a new dedicated server
Expand All @@ -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),
Copy link
Collaborator

Choose a reason for hiding this comment

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

The default should be null as shown in the request body schema in the documentation of the call

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,
Expand All @@ -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)",
Expand All @@ -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",
Expand Down
60 changes: 60 additions & 0 deletions plugins/modules/dedicated_server_specification_hardware.py
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

This module should rather be called dedicated_server_hardware_specification 🤔 ?
(the file name too)

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Typo: service name

'''

EXAMPLES = r'''
- name: Retrieve all hardwared information for an OVH dedicated server
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo: hardware and informations

synthesio.ovh.dedicated_server_info:
Copy link
Collaborator

Choose a reason for hiding this comment

The 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 = ''' # '''
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()
10 changes: 9 additions & 1 deletion plugins/modules/public_cloud_instance_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's even if it is in ACTIVE status?



"""

EXAMPLES = """
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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(
Expand Down
88 changes: 88 additions & 0 deletions plugins/modules/public_cloud_instance_manage.py
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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Start/Stop/Shelve/Unshelve

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

service name

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
Copy link
Collaborator

Choose a reason for hiding this comment

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

the option for this is stop

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)

# 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()