From eb2499b794f7da2efc637bf6d655688674303778 Mon Sep 17 00:00:00 2001 From: Claus Holbech Date: Thu, 9 Nov 2023 21:06:21 +0100 Subject: [PATCH] Feat(eos_designs): Add `default_mgmt_method` to be used later in new management settings. (#3328) Co-authored-by: Carl Buchmann --- .../eos_designs_shared_utils/mgmt.py | 43 +++++++++++++++++++ .../tables/management-interface-settings.md | 2 + .../schemas/eos_designs.jsonschema.json | 11 +++++ .../schemas/eos_designs.schema.yml | 17 ++++++++ .../default_mgmt_method.schema.yml | 28 ++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 ansible_collections/arista/avd/roles/eos_designs/schemas/schema_fragments/default_mgmt_method.schema.yml diff --git a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mgmt.py b/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mgmt.py index 0f0174d6aa5..545bb41c99e 100644 --- a/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mgmt.py +++ b/ansible_collections/arista/avd/plugins/plugin_utils/eos_designs_shared_utils/mgmt.py @@ -6,6 +6,7 @@ from functools import cached_property from typing import TYPE_CHECKING +from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdMissingVariableError from ansible_collections.arista.avd.plugins.plugin_utils.utils import default, get if TYPE_CHECKING: @@ -54,3 +55,45 @@ def mgmt_gateway(self: SharedUtils) -> str | None: @cached_property def ipv6_mgmt_gateway(self: SharedUtils) -> str | None: return get(self.hostvars, "ipv6_mgmt_gateway") + + @cached_property + def default_mgmt_method(self: SharedUtils) -> str | None: + """ + This is only executed if some protocol looks for the default value, so we can raise here to ensure a working config. + + The check for 'inband_mgmt_interface' relies on other indirect checks done in that code. + """ + default_mgmt_method = get(self.hostvars, "default_mgmt_method", default="oob") + if default_mgmt_method == "oob": + if (self.mgmt_ip is None) and (self.ipv6_mgmt_ip is None): + raise AristaAvdMissingVariableError("'default_mgmt_method: oob' requires either 'mgmt_ip' or 'ipv6_mgmt_ip' to bet set.") + + return default_mgmt_method + + elif default_mgmt_method == "inband": + # Check for missing interface + if self.inband_mgmt_interface is None: + raise AristaAvdMissingVariableError("'default_mgmt_method: inband' requires 'inband_mgmt_interface' to be set.") + + return default_mgmt_method + + return None + + @cached_property + def default_mgmt_protocol_vrf(self: SharedUtils) -> str | None: + if self.default_mgmt_method == "oob": + return self.mgmt_interface_vrf + elif self.default_mgmt_method == "inband": + # inband_mgmt_vrf returns None for vrf default. + return self.inband_mgmt_vrf or "default" + + return None + + @cached_property + def default_mgmt_protocol_interface(self: SharedUtils) -> str | None: + if self.default_mgmt_method == "oob": + return self.mgmt_interface + elif self.default_mgmt_method == "inband": + return self.inband_mgmt_interface + + return None diff --git a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/management-interface-settings.md b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/management-interface-settings.md index 71978ac57f9..3377dfa2e90 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/docs/tables/management-interface-settings.md +++ b/ansible_collections/arista/avd/roles/eos_designs/docs/tables/management-interface-settings.md @@ -7,6 +7,7 @@ | Variable | Type | Required | Default | Value Restrictions | Description | | -------- | ---- | -------- | ------- | ------------------ | ----------- | + | [default_mgmt_method](## "default_mgmt_method") | String | | `oob` | Valid Values:
- oob
- inband
- none | `default_mgmt_method` controls the default VRF and source interface used for the following management and monitoring protocols configured with `eos_designs`:
- `cv_settings`
- `dns_settings`
- `ntp_settings`
- `sflow_settings`

`oob` means the protocols will be configured with the VRF set by `mgmt_interface_vrf` and `mgmt_interface` as the source interface.
`inband` means the protocols will be configured with the VRF set by `inband_mgmt_vrf` and `inband_mgmt_interface` as the source interface.
`none` means the VRF and or interface must be manually set for each protocol.
This can be overridden under the settings for each protocol.
| | [mgmt_destination_networks](## "mgmt_destination_networks") | List, items: String | | | | List of IPv4 prefixes to configure as static routes towards the OOB Management interface gateway.
Replaces the default route. | | [  - <str>](## "mgmt_destination_networks.[].<str>") | String | | | | IPv4_address/Mask. | | [mgmt_gateway](## "mgmt_gateway") | String | | | | OOB Management interface gateway in IPv4 format.
Used as next-hop for default gateway or static routes defined under 'mgmt_destination_networks'. | @@ -18,6 +19,7 @@ === "YAML" ```yaml + default_mgmt_method: mgmt_destination_networks: - mgmt_gateway: diff --git a/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.jsonschema.json b/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.jsonschema.json index d2ab55364a4..6d94d438a72 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.jsonschema.json +++ b/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.jsonschema.json @@ -3079,6 +3079,17 @@ }, "title": "Default Interfaces" }, + "default_mgmt_method": { + "type": "string", + "description": "`default_mgmt_method` controls the default VRF and source interface used for the following management and monitoring protocols configured with `eos_designs`:\n - `cv_settings`\n - `dns_settings`\n - `ntp_settings`\n - `sflow_settings`\n\n`oob` means the protocols will be configured with the VRF set by `mgmt_interface_vrf` and `mgmt_interface` as the source interface.\n`inband` means the protocols will be configured with the VRF set by `inband_mgmt_vrf` and `inband_mgmt_interface` as the source interface.\n`none` means the VRF and or interface must be manually set for each protocol.\nThis can be overridden under the settings for each protocol.\n", + "enum": [ + "oob", + "inband", + "none" + ], + "default": "oob", + "title": "Default Management Method" + }, "default_node_types": { "type": "array", "description": "Uses hostname matches against a regular expression to determine the node type.", diff --git a/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.schema.yml b/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.schema.yml index ed70f803dd9..f5a21903dcf 100644 --- a/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.schema.yml +++ b/ansible_collections/arista/avd/roles/eos_designs/schemas/eos_designs.schema.yml @@ -635,6 +635,23 @@ keys: items: type: str description: Interface range or interface. + default_mgmt_method: + documentation_options: + table: management-interface-settings + type: str + description: "`default_mgmt_method` controls the default VRF and source interface + used for the following management and monitoring protocols configured with `eos_designs`:\n + \ - `cv_settings`\n - `dns_settings`\n - `ntp_settings`\n - `sflow_settings`\n\n`oob` + means the protocols will be configured with the VRF set by `mgmt_interface_vrf` + and `mgmt_interface` as the source interface.\n`inband` means the protocols + will be configured with the VRF set by `inband_mgmt_vrf` and `inband_mgmt_interface` + as the source interface.\n`none` means the VRF and or interface must be manually + set for each protocol.\nThis can be overridden under the settings for each protocol.\n" + valid_values: + - oob + - inband + - none + default: oob default_node_types: type: list primary_key: node_type diff --git a/ansible_collections/arista/avd/roles/eos_designs/schemas/schema_fragments/default_mgmt_method.schema.yml b/ansible_collections/arista/avd/roles/eos_designs/schemas/schema_fragments/default_mgmt_method.schema.yml new file mode 100644 index 00000000000..df0beb55ee4 --- /dev/null +++ b/ansible_collections/arista/avd/roles/eos_designs/schemas/schema_fragments/default_mgmt_method.schema.yml @@ -0,0 +1,28 @@ +# Copyright (c) 2023 Arista Networks, Inc. +# Use of this source code is governed by the Apache License 2.0 +# that can be found in the LICENSE file. +# yaml-language-server: $schema=../../../../plugins/plugin_utils/schema/avd_meta_schema.json +# Line above is used by RedHat's YAML Schema vscode extension +# Use Ctrl + Space to get suggestions for every field. Autocomplete will pop up after typing 2 letters. +type: dict +keys: + default_mgmt_method: + documentation_options: + table: management-interface-settings + type: str + description: | + `default_mgmt_method` controls the default VRF and source interface used for the following management and monitoring protocols configured with `eos_designs`: + - `cv_settings` + - `dns_settings` + - `ntp_settings` + - `sflow_settings` + + `oob` means the protocols will be configured with the VRF set by `mgmt_interface_vrf` and `mgmt_interface` as the source interface. + `inband` means the protocols will be configured with the VRF set by `inband_mgmt_vrf` and `inband_mgmt_interface` as the source interface. + `none` means the VRF and or interface must be manually set for each protocol. + This can be overridden under the settings for each protocol. + valid_values: + - oob + - inband + - none + default: oob