-
Notifications
You must be signed in to change notification settings - Fork 53
Added OLA management #107
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
Open
Fry-4TF1V
wants to merge
1
commit into
synthesio:master
Choose a base branch
from
Fry-4TF1V:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Added OLA management #107
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/usr/bin/python | ||
Fry-4TF1V marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # -*- 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() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.