-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
353 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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,53 @@ | ||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.api import \ | ||
Session | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.helper.main import \ | ||
validate_int_fields, is_unset | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.cls import BaseModule | ||
|
||
|
||
class Lagg(BaseModule): | ||
CMDS = { | ||
'add': 'addItem', | ||
'del': 'delItem', | ||
'set': 'setItem', | ||
'search': 'get', | ||
} | ||
API_KEY_PATH = 'lagg.lagg' | ||
API_MOD = 'interfaces' | ||
API_CONT = 'lagg_settings' | ||
API_CMD_REL = 'reconfigure' | ||
FIELDS_CHANGE = ['members', 'primary_member', 'proto', 'lacp_fast_timeout', 'use_flowid', 'lagghash', 'lacp_strict', 'mtu', 'description'] | ||
FIELDS_ALL = ['device'] | ||
FIELDS_ALL.extend(FIELDS_CHANGE) | ||
FIELDS_TRANSLATE = { | ||
'device': 'laggif', | ||
'description': 'descr', | ||
} | ||
FIELDS_TYPING = { | ||
'bool': ['lacp_fast_timeout'], | ||
'list': ['members', 'lagghash'], | ||
'select': ['members', 'primary_member', 'proto', 'use_flowid', 'lagghash', 'lacp_strict'], | ||
} | ||
INT_VALIDATIONS = { | ||
'mtu': {'min': 576, 'max': 65535}, | ||
} | ||
EXIST_ATTR = 'lagg' | ||
|
||
def __init__(self, module: AnsibleModule, result: dict, session: Session = None): | ||
BaseModule.__init__(self=self, m=module, r=result, s=session) | ||
self.lagg = {} | ||
|
||
def check(self) -> None: | ||
if self.p['state'] == 'present': | ||
if is_unset(self.p['members']): | ||
self.m.fail_json("You need to provide a list of 'members' to create a lagg!") | ||
|
||
|
||
validate_int_fields(module=self.m, data=self.p, field_minmax=self.INT_VALIDATIONS) | ||
|
||
self._base_check() | ||
|
||
def update(self) -> None: | ||
self.b.update(enable_switch=False) |
This file contains 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,107 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# Copyright: (C) 2024, AnsibleGuy <[email protected]> | ||
# GNU General Public License v3.0+ (see https://www.gnu.org/licenses/gpl-3.0.txt) | ||
|
||
# see: https://docs.opnsense.org/development/api/core/interfaces.html | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
|
||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.handler import \ | ||
module_dependency_error, MODULE_EXCEPTIONS | ||
|
||
try: | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.helper.wrapper import module_wrapper | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.defaults.main import \ | ||
OPN_MOD_ARGS, STATE_ONLY_MOD_ARG, RELOAD_MOD_ARG | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.main.interface_lagg import Lagg | ||
|
||
except MODULE_EXCEPTIONS: | ||
module_dependency_error() | ||
|
||
|
||
# DOCUMENTATION = 'https://opnsense.ansibleguy.net/en/latest/modules/interface.html' | ||
# EXAMPLES = 'https://opnsense.ansibleguy.net/en/latest/modules/interface.html' | ||
|
||
|
||
def run_module(): | ||
module_args = dict( | ||
device=dict( | ||
type='str', required=False, aliases=['laggif'], | ||
description="Optional 'device' of the entry. Needs to start with 'lagg'", | ||
), | ||
members=dict( | ||
type='list', elements='str', required=False, aliases=['port', 'int', 'if'], | ||
description='Existing LAGG capable interface - you must provide the network ' | ||
"port as shown in 'Interfaces - Assignments - Network port'" | ||
), | ||
primary_member=dict( | ||
type='list', elements='str', required=False, | ||
description='This interface will be added first in the lagg making it the primary one ' | ||
"- you must provide the network port as shown in 'Interfaces - Assignments - Network port'" | ||
), | ||
proto=dict( | ||
type='str', required=False, aliases=['p'], default='lacp', | ||
choices=['none', 'lacp', 'failover', 'fec', 'loadbalance', 'roundrobin'], | ||
description="The protocol to use." | ||
), | ||
lacp_fast_timeout=dict(type='bool', required=False, default=False, | ||
description='Enable lacp fast-timeout on the interface.' | ||
), | ||
use_flowid=dict( | ||
type='str', required=False, choices=['default', 'yes', 'no'], | ||
description='Use the RSS hash from the network card if available, otherwise a hash is locally calculated. ' | ||
'The default depends on the system tunable in net.link.lagg.default_use_flowid.' | ||
), | ||
lagghash=dict( | ||
type='list', elements='str', required=False, default=['l2'], | ||
choices=['l2', 'l3', 'l4'], | ||
description='Set the packet layers to hash for aggregation protocols which load balance.' | ||
), | ||
lacp_strict=dict( | ||
type='str', required=False, | ||
choices=['default', 'yes', 'no'], | ||
description='Enable lacp strict compliance on the interface. The default depends on the ' | ||
'system tunable in net.link.lagg.lacp.default_strict_mode.', | ||
), | ||
mtu=dict( | ||
type='int', required=False, | ||
description='If you leave this field blank, the smallest mtu of this laggs children will be used.' | ||
), | ||
description=dict(type='str', required=False, aliases=['desc', 'name']), | ||
match_fields=dict( | ||
type='list', required=False, elements='str', | ||
description='Fields that are used to match configured LAGG with the running config - ' | ||
"if any of those fields are changed, the module will think it's a new entry", | ||
choices=['device', 'members', 'primary_member', 'proto', 'description'], | ||
default=['members'], | ||
), | ||
**RELOAD_MOD_ARG, | ||
**STATE_ONLY_MOD_ARG, | ||
**OPN_MOD_ARGS, | ||
) | ||
|
||
result = dict( | ||
changed=False, | ||
diff={ | ||
'before': {}, | ||
'after': {}, | ||
} | ||
) | ||
|
||
module = AnsibleModule( | ||
argument_spec=module_args, | ||
supports_check_mode=True, | ||
) | ||
|
||
module_wrapper(Lagg(module=module, result=result)) | ||
module.exit_json(**result) | ||
|
||
|
||
def main(): | ||
run_module() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains 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 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 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 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
Oops, something went wrong.