-
-
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.
Merge pull request #152 from scsitteam/interface_gre
Implement GRE Interfaces
- Loading branch information
Showing
9 changed files
with
355 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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 | ||
from ansible_collections.ansibleguy.opnsense.plugins.module_utils.base.cls import BaseModule | ||
|
||
|
||
class Gre(BaseModule): | ||
FIELD_ID = 'description' | ||
CMDS = { | ||
'add': 'addItem', | ||
'del': 'delItem', | ||
'set': 'setItem', | ||
'search': 'get', | ||
'toggle': 'toggleItem', | ||
} | ||
API_KEY_PATH = 'gre.gre' | ||
API_MOD = 'interfaces' | ||
API_CONT = 'gre_settings' | ||
FIELDS_CHANGE = ['local', 'remote', 'tunnel_local', 'tunnel_remote', 'tunnel_remote_net'] | ||
FIELDS_ALL = [FIELD_ID] | ||
FIELDS_ALL.extend(FIELDS_CHANGE) | ||
FIELDS_TRANSLATE = { | ||
'description': 'descr', | ||
'local': 'local-addr', | ||
'remote': 'remote-addr', | ||
'tunnel_local': 'tunnel-local-addr', | ||
'tunnel_remote': 'tunnel-remote-addr', | ||
'tunnel_remote_net': 'tunnel-remote-net', | ||
} | ||
FIELDS_TYPING = { | ||
'bool': [], | ||
'list': [], | ||
'select': [], | ||
'int': ['tunnel_remote_net'], | ||
} | ||
INT_VALIDATIONS = { | ||
'tunnel_remote_net': {'min': 1, 'max': 128}, | ||
} | ||
EXIST_ATTR = 'gre' | ||
|
||
def __init__(self, module: AnsibleModule, result: dict, session: Session = None): | ||
BaseModule.__init__(self=self, m=module, r=result, s=session) | ||
self.gre = {} | ||
|
||
def check(self) -> None: | ||
if self.p['state'] == 'present': | ||
validate_int_fields(module=self.m, data=self.p, field_minmax=self.INT_VALIDATIONS) | ||
|
||
self._base_check() |
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,82 @@ | ||
#!/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) | ||
|
||
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_gre import Gre | ||
|
||
except MODULE_EXCEPTIONS: | ||
module_dependency_error() | ||
|
||
|
||
# DOCUMENTATION = 'https://opnsense.ansibleguy.net/modules/interface.html' | ||
# EXAMPLES = 'https://opnsense.ansibleguy.net/modules/interface.html' | ||
|
||
|
||
def run_module(): | ||
module_args = dict( | ||
description=dict( | ||
type='str', required=True, aliases=['desc'], | ||
description='The unique description used to match the configured entries to the existing ones.', | ||
), | ||
local=dict( | ||
type='str', required=False, aliases=['l', 'local_addr'], | ||
description='The local address or interface to use.', | ||
), | ||
remote=dict( | ||
type='str', required=False, aliases=['r', 'remote_addr'], | ||
description='Peer address where encapsulated gre packets will be sent.', | ||
), | ||
tunnel_local=dict( | ||
type='str', required=False, aliases=['tl', 'tunnel_local_addr'], | ||
description='Local gre tunnel endpoint.', | ||
), | ||
tunnel_remote=dict( | ||
type='str', required=False, aliases=['tr', 'tunnel_remote_addr'], | ||
description='Remote gre tunnel endpoint.', | ||
), | ||
tunnel_remote_net=dict( | ||
type='int', required=False, default=32, | ||
description="Netmask 'ipv4' or prefix 'ipv6' to use for this tunnel", | ||
), | ||
**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, | ||
required_if=[ | ||
('state', 'present', ('local', 'remote', 'tunnel_local', 'tunnel_remote')), | ||
], | ||
) | ||
|
||
module_wrapper(Gre(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
Oops, something went wrong.