Skip to content

Commit

Permalink
Feat(eos_designs): Add default_mgmt_method to be used later in new …
Browse files Browse the repository at this point in the history
…management settings. (aristanetworks#3328)

Co-authored-by: Carl Buchmann <[email protected]>
  • Loading branch information
2 people authored and jonxstill committed Nov 14, 2023
1 parent 73fd793 commit eb2499b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

| Variable | Type | Required | Default | Value Restrictions | Description |
| -------- | ---- | -------- | ------- | ------------------ | ----------- |
| [<samp>default_mgmt_method</samp>](## "default_mgmt_method") | String | | `oob` | Valid Values:<br>- oob<br>- inband<br>- none | `default_mgmt_method` controls the default VRF and source interface used for the following management and monitoring protocols configured with `eos_designs`:<br> - `cv_settings`<br> - `dns_settings`<br> - `ntp_settings`<br> - `sflow_settings`<br><br>`oob` means the protocols will be configured with the VRF set by `mgmt_interface_vrf` and `mgmt_interface` as the source interface.<br>`inband` means the protocols will be configured with the VRF set by `inband_mgmt_vrf` and `inband_mgmt_interface` as the source interface.<br>`none` means the VRF and or interface must be manually set for each protocol.<br>This can be overridden under the settings for each protocol.<br> |
| [<samp>mgmt_destination_networks</samp>](## "mgmt_destination_networks") | List, items: String | | | | List of IPv4 prefixes to configure as static routes towards the OOB Management interface gateway.<br>Replaces the default route. |
| [<samp>&nbsp;&nbsp;- &lt;str&gt;</samp>](## "mgmt_destination_networks.[].&lt;str&gt;") | String | | | | IPv4_address/Mask. |
| [<samp>mgmt_gateway</samp>](## "mgmt_gateway") | String | | | | OOB Management interface gateway in IPv4 format.<br>Used as next-hop for default gateway or static routes defined under 'mgmt_destination_networks'. |
Expand All @@ -18,6 +19,7 @@
=== "YAML"

```yaml
default_mgmt_method: <str>
mgmt_destination_networks:
- <str>
mgmt_gateway: <str>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit eb2499b

Please sign in to comment.