Skip to content

Commit

Permalink
Add IPv4 DHCP option matcher, minor fixes (#300)
Browse files Browse the repository at this point in the history
* Fix typos in comment on IPsec policy "template" field

* Move IPv4 DHCP server API data next to other DHCP APIs

* Set default for "force" field on DHCP options

Without the default value removing it from the options after it's been
set once leads to an error:

> Key "force" cannot be removed for name="…"

* Add IPv4 DHCP option matcher

RouterOS 7.4 and newer implement matchers for the Vendor ID provided by
DHCP clients. RouterOS 7.16 will add a new `matching-type` property, but
it's not in a stable release yet.

Upstream documentation:
https://help.mikrotik.com/docs/display/ROS/DHCP#DHCP-Genericmatcher
  • Loading branch information
hansmi authored Jul 21, 2024
1 parent 5ee2af4 commit 8c62d46
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 33 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/300-add-ip-dhcp-server-matcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- api_info, api_modify - add support for the ``ip dhcp-server matcher`` path (https://github.com/ansible-collections/community.routeros/issues/300).
2 changes: 2 additions & 0 deletions changelogs/fragments/300-set-ip-dhcp-option-force-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- api_info, api_modify - set default for ``force`` in ``ip dhcp-server option`` to an explicit ``false`` (https://github.com/ansible-collections/community.routeros/issues/300).
84 changes: 51 additions & 33 deletions plugins/module_utils/_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,36 +774,6 @@ def join_path(path):
)),
],
),
('ip', 'dhcp-server'): APIData(
unversioned=VersionedAPIData(
fully_understood=True,
primary_keys=('name', ),
fields={
'address-pool': KeyInfo(default='static-only'),
'allow-dual-stack-queue': KeyInfo(can_disable=True, remove_value=True),
'always-broadcast': KeyInfo(can_disable=True, remove_value=False),
'authoritative': KeyInfo(default=True),
'bootp-lease-time': KeyInfo(default='forever'),
'bootp-support': KeyInfo(can_disable=True, remove_value='static'),
'client-mac-limit': KeyInfo(can_disable=True, remove_value='unlimited'),
'comment': KeyInfo(can_disable=True, remove_value=''),
'conflict-detection': KeyInfo(can_disable=True, remove_value=True),
'delay-threshold': KeyInfo(can_disable=True, remove_value='none'),
'dhcp-option-set': KeyInfo(can_disable=True, remove_value='none'),
'disabled': KeyInfo(default=False),
'insert-queue-before': KeyInfo(can_disable=True, remove_value='first'),
'interface': KeyInfo(required=True),
'lease-script': KeyInfo(default=''),
'lease-time': KeyInfo(default='10m'),
'name': KeyInfo(),
'parent-queue': KeyInfo(can_disable=True, remove_value='none'),
'relay': KeyInfo(can_disable=True, remove_value='0.0.0.0'),
'server-address': KeyInfo(can_disable=True, remove_value='0.0.0.0'),
'use-framed-as-classless': KeyInfo(can_disable=True, remove_value=True),
'use-radius': KeyInfo(default=False),
},
),
),
('routing', 'filter'): APIData(
versioned=[
('7', '<', VersionedAPIData(
Expand Down Expand Up @@ -2679,6 +2649,36 @@ def join_path(path):
},
),
),
('ip', 'dhcp-server'): APIData(
unversioned=VersionedAPIData(
fully_understood=True,
primary_keys=('name', ),
fields={
'address-pool': KeyInfo(default='static-only'),
'allow-dual-stack-queue': KeyInfo(can_disable=True, remove_value=True),
'always-broadcast': KeyInfo(can_disable=True, remove_value=False),
'authoritative': KeyInfo(default=True),
'bootp-lease-time': KeyInfo(default='forever'),
'bootp-support': KeyInfo(can_disable=True, remove_value='static'),
'client-mac-limit': KeyInfo(can_disable=True, remove_value='unlimited'),
'comment': KeyInfo(can_disable=True, remove_value=''),
'conflict-detection': KeyInfo(can_disable=True, remove_value=True),
'delay-threshold': KeyInfo(can_disable=True, remove_value='none'),
'dhcp-option-set': KeyInfo(can_disable=True, remove_value='none'),
'disabled': KeyInfo(default=False),
'insert-queue-before': KeyInfo(can_disable=True, remove_value='first'),
'interface': KeyInfo(required=True),
'lease-script': KeyInfo(default=''),
'lease-time': KeyInfo(default='10m'),
'name': KeyInfo(),
'parent-queue': KeyInfo(can_disable=True, remove_value='none'),
'relay': KeyInfo(can_disable=True, remove_value='0.0.0.0'),
'server-address': KeyInfo(can_disable=True, remove_value='0.0.0.0'),
'use-framed-as-classless': KeyInfo(can_disable=True, remove_value=True),
'use-radius': KeyInfo(default=False),
},
),
),
('ip', 'dhcp-server', 'config'): APIData(
unversioned=VersionedAPIData(
single_value=True,
Expand Down Expand Up @@ -2738,7 +2738,7 @@ def join_path(path):
'code': KeyInfo(required=True),
'name': KeyInfo(),
'value': KeyInfo(default=''),
'force': KeyInfo(),
'force': KeyInfo(default=False),
},
),
),
Expand All @@ -2752,6 +2752,23 @@ def join_path(path):
},
),
),
('ip', 'dhcp-server', 'matcher'): APIData(
versioned=[
('7.4', '>=', VersionedAPIData(
fully_understood=True,
primary_keys=('name', ),
fields={
'address-pool': KeyInfo(default='none'),
'code': KeyInfo(required=True),
'disabled': KeyInfo(default=False),
'name': KeyInfo(required=True),
'option-set': KeyInfo(),
'server': KeyInfo(default='all'),
'value': KeyInfo(required=True),
},
)),
],
),
('ip', 'dns'): APIData(
unversioned=VersionedAPIData(
single_value=True,
Expand Down Expand Up @@ -4966,9 +4983,10 @@ def join_path(path):
'protocol': KeyInfo(default='all'),
'src-address': KeyInfo(),
'src-port': KeyInfo(default='any'),
# The template field can't really be changed once the item is
# created. This config captures the behavior best as it can
# i.e. template=yes is shown, template=no is hidden.
'template': KeyInfo(can_disable=True, remove_value=False),
# the tepmlate field can't really be changed once the item is created. This config captures the behavior best as it can
# i.e. tepmplate=yes is shown, tepmlate=no is hidden
'tunnel': KeyInfo(default=False),
},
),
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
- ip dhcp-server
- ip dhcp-server config
- ip dhcp-server lease
- ip dhcp-server matcher
- ip dhcp-server network
- ip dhcp-server option
- ip dhcp-server option sets
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/api_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
- ip dhcp-server
- ip dhcp-server config
- ip dhcp-server lease
- ip dhcp-server matcher
- ip dhcp-server network
- ip dhcp-server option
- ip dhcp-server option sets
Expand Down

0 comments on commit 8c62d46

Please sign in to comment.