Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions plugins/modules/dedicated_server_networkinterfacecontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@
options:
service_name:
required: true
description: The service_name
description: The service name
link_type:
required: true
description: The link type, public or private (vrack)

description: The link type
- public or public_lag
- private or private_lag (vrack)
- provisioning or provisioning_lag
- isolated (OVHcloud special mode)
'''

EXAMPLES = r'''
Expand All @@ -43,7 +46,7 @@ def run_module():
module_args = ovh_argument_spec()
module_args.update(dict(
service_name=dict(required=True),
link_type=dict(required=True)
link_type=dict(required=False)
))

module = AnsibleModule(
Expand All @@ -52,15 +55,23 @@ def run_module():
)
client = OVH(module)

link_type = module.params['link_type']
link_type = None
if module.params['link_type']:
link_type = module.params['link_type']
service_name = module.params['service_name']

result = client.wrap_call("GET", f"/dedicated/server/{service_name}/networkInterfaceController?linkType={link_type}")
# XXX: This is a hack, would be better to detect what kind of server you are using:
# If there is no result, maybe you have a server with multiples network interfaces on the same link (2x public + 2x vrack), like HGR
# In this case, retry with public_lag/private_lag linkType
if not result:
result = client.wrap_call("GET", f"/dedicated/server/{service_name}/networkInterfaceController?linkType={link_type}_lag")
# Return all mac addresses
if not link_type:
result = client.wrap_call("GET", f"/dedicated/server/{service_name}/networkInterfaceController")

# Return only specific type mac addresses
elif link_type:
result = client.wrap_call("GET", f"/dedicated/server/{service_name}/networkInterfaceController?linkType={link_type}")
# XXX: This is a hack, would be better to detect what kind of server you are using:
# If there is no result, maybe you have a server with multiples network interfaces on the same link (2x public + 2x vrack), like HGR
# In this case, retry with public_lag/private_lag linkType
if not result:
result = client.wrap_call("GET", f"/dedicated/server/{service_name}/networkInterfaceController?linkType={link_type}_lag")

module.exit_json(changed=False, msg=result)

Expand Down
93 changes: 93 additions & 0 deletions plugins/modules/dedicated_server_ola_configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule

DOCUMENTATION = '''
---
module: dedicated_server_ola_configure
short_description: Configure all network interfaces in OLA mode
description:
- Configure all network interfaces in an OVHcloud Link Aggregation mode to switch to full network private mode (vrack)
author: OVHcloud Professional Services
requirements:
- ovh >= 0.5.0
options:
service_name:
required: true
description: OVHcloud name of the server
aggregate_name:
required: false
default: "bond"
description: Name of the aggregate

'''

EXAMPLES = '''
- name: Configure all network interfaces in OLA mode
synthesio.ovh.dedicated_server_ola_configure:
service_name: "ns12345.ip-1-2-3.eu"
aggregate_name: "bond"
delegate_to: localhost
register: ola_config_task
'''

RETURN = '''
task:
description: OVHcloud task ID
type: integer
'''

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),
aggregate_name=dict(required=False, default="bond")
))

module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
client = OVH(module)

service_name = module.params['service_name']
aggregate_name = module.params['aggregate_name']

if module.check_mode:
module.exit_json(msg=f"OLA configuration in progress on {service_name} with aggregate name {aggregate_name} - (dry run mode)", changed=True)

virtualNetworkInterfaces = list()

macaddresses = client.wrap_call('GET', f'/dedicated/server/{service_name}/networkInterfaceController')
if len(macaddresses) >= 2:
for macaddress in macaddresses:
uuid = client.wrap_call('GET', f'/dedicated/server/{service_name}/networkInterfaceController/{macaddress}')
virtualNetworkInterfaces.append(uuid['virtualNetworkInterface'])
# Remove duplicate entries for Baremetal servers with 4 NICs
virtualNetworkInterfaces = list(set(virtualNetworkInterfaces))
else:
module.fail_json(msg=f"{service_name} doesn't have enough interfaces eligible to OLA, please remove vRack association or Additional IPs")

for virtualNetworkInterface in virtualNetworkInterfaces:
vrack = client.wrap_call('GET', f'/dedicated/server/{service_name}/virtualNetworkInterface/{virtualNetworkInterface}')
if vrack['vrack'] is not None:
module.fail_json(msg=f"{vrack['name']} on {service_name} is linked to a vRack, please remove vRack association first")

task = client.wrap_call('POST', f'/dedicated/server/{service_name}/ola/aggregation',name=aggregate_name, virtualNetworkInterfaces=virtualNetworkInterfaces)

module.exit_json(msg=f"OLA configuration in progress on {service_name} with name {aggregate_name} !", changed=True, task=task)


def main():
run_module()


if __name__ == '__main__':
main()
74 changes: 74 additions & 0 deletions plugins/modules/dedicated_server_ola_unconfigure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule

DOCUMENTATION = '''
---
module: dedicated_server_ola_unconfigure
short_description: Unconfigure all network interfaces in OLA mode
description:
- Unconfigure all private network interfaces in an OVHcloud Link Aggregation mode to switch to default network mode
author: OVHcloud Professional Services
requirements:
- ovh >= 0.5.0
options:
service_name:
required: true
description: OVHcloud name of the server

'''

EXAMPLES = '''
- name: Unconfigure all network interfaces in OLA mode
synthesio.ovh.dedicated_server_ola_unconfigure:
service_name: "ns12345.ip-1-2-3.eu"
delegate_to: localhost
register: ola_config_task
'''

RETURN = '''
task:
description: OVHcloud task ID
type: integer
'''

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
)
client = OVH(module)

service_name = module.params['service_name']

if module.check_mode:
module.exit_json(msg=f"OLA unconfiguration in progress on {service_name} - (dry run mode)", changed=True)

macaddresses = client.wrap_call('GET', f'/dedicated/server/{service_name}/networkInterfaceController?linkType=private_lag')
if len(macaddresses) > 0:
uuid = client.wrap_call('GET', f'/dedicated/server/{service_name}/networkInterfaceController/{macaddresses[0]}')
else:
module.fail_json(msg=f"{service_name} doesn't seems to have OLA configured, please check again")

task = client.wrap_call('POST', f'/dedicated/server/{service_name}/ola/reset', virtualNetworkInterface=uuid['virtualNetworkInterface'])

module.exit_json(msg=f"OLA unconfiguration in progress on {service_name} !", changed=True, task=task)


def main():
run_module()


if __name__ == '__main__':
main()
94 changes: 94 additions & 0 deletions plugins/modules/dedicated_server_ola_wait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

from ansible.module_utils.basic import AnsibleModule

DOCUMENTATION = '''
---
module: dedicated_server_ola_configure_wait
short_description: Wait until OLA configuration is done
description:
- Wait until OLA configuration is done
- Can be used to wait before running next task in your playbook
author: OVHcloud Professional Services
requirements:
- ovh >= 0.5.0
options:
service_name:
required: true
description: OVHcloud name of the server
task:
required: true
description: Task ID
max_retry:
required: false
description: Number of retry
default: 240
sleep:
required: false
description: Time to sleep between retries
default: 10
'''

EXAMPLES = '''
- name: Wait until OLA configuration is done
synthesio.ovh.dedicated_server_ola_configure_wait:
service_name: "ns12345.ip-1-2-3.eu"
task: "123456789"
max_retry: "240"
sleep: "10"
delegate_to: localhost
'''

RETURN = ''' # '''

from ansible_collections.synthesio.ovh.plugins.module_utils.ovh import OVH, ovh_argument_spec
import time


def run_module():
module_args = ovh_argument_spec()
module_args.update(dict(
service_name=dict(required=True),
task=dict(required=True),
max_retry=dict(required=False, default=240),
sleep=dict(required=False, default=10)
))

module = AnsibleModule(
argument_spec=module_args,
supports_check_mode=True
)
client = OVH(module)

service_name = module.params['service_name']
task = module.params['task']
max_retry = module.params['max_retry']
sleep = module.params['sleep']

if module.check_mode:
module.exit_json(msg="done - (dry run mode)", changed=False)

for i in range(1, int(max_retry)):
result = client.wrap_call('GET', f'/dedicated/server/{service_name}/task/{task}')

message = ""
# Get more details in task progression
if "done" in result['status']:
module.exit_json(msg=f"{result['status']}: {message}", changed=False)
else:
message = result['status']

time.sleep(float(sleep))
module.fail_json(msg="Max wait time reached, about %i x %i seconds" % (i, int(sleep)))


def main():
run_module()


if __name__ == '__main__':
main()
Loading