Skip to content

Commit

Permalink
Add vrfs model instead of structured config
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausHolbechArista committed Mar 14, 2024
1 parent d8c7912 commit c869503
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ sflow_settings:
- destination: 10.10.10.12
vrf: sflowvrf
port: 1234
structured_config:
vrfs:
- name: sflowvrf
source_interface: Loopback321
vrfs:
- name: sflowvrf
source_interface: Loopback321

fabric_sflow:
uplinks: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
| [<samp>&nbsp;&nbsp;destinations</samp>](## "sflow_settings.destinations") | List, items: Dictionary | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;destination</samp>](## "sflow_settings.destinations.[].destination") | String | Required | | | sFlow destination name or IP address. |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;port</samp>](## "sflow_settings.destinations.[].port") | Integer | | | Min: 1<br>Max: 65535 | UDP Port number. The default port number for sFlow is 6343. |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vrf</samp>](## "sflow_settings.destinations.[].vrf") | String | | | | If not set, the VRF is automatically picked up from the global setting `default_mgmt_method`.<br>The value of `vrf` will be interpreted according to these rules:<br>- `use_mgmt_interface_vrf` will configure the sFlow destination under the VRF set with `mgmt_interface_vrf` and set the `mgmt_interface` as sFlow source-interface.<br> An error will be raised if `mgmt_ip` or `ipv6_mgmt_ip` are not configured for the device.<br>- `use_inband_mgmt_vrf` will configure the sFlow destination under the VRF set with `inband_mgmt_vrf` and set the `inband_mgmt_interface` as sFlow source-interface.<br> An error will be raised if inband management is not configured for the device.<br>- Any other string will be used directly as the VRF name but source interface must be set with `sflow.structured_config` as needed. |
| [<samp>&nbsp;&nbsp;structured_config</samp>](## "sflow_settings.structured_config") | Dictionary | | | | Custom structured config added under `sflow` for `eos_cli_config_gen`. |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vrf</samp>](## "sflow_settings.destinations.[].vrf") | String | | | | If not set, the VRF is automatically picked up from the global setting `default_mgmt_method`.<br>The value of `vrf` will be interpreted according to these rules:<br>- `use_mgmt_interface_vrf` will configure the sFlow destination under the VRF set with `mgmt_interface_vrf` and set the `mgmt_interface` as sFlow source-interface.<br> An error will be raised if `mgmt_ip` or `ipv6_mgmt_ip` are not configured for the device.<br>- `use_inband_mgmt_vrf` will configure the sFlow destination under the VRF set with `inband_mgmt_vrf` and set the `inband_mgmt_interface` as sFlow source-interface.<br> An error will be raised if inband management is not configured for the device.<br>- Any other string will be used directly as the VRF name. Remember to set the `sflow_settings.vrfs[].source_interface` if needed. |
| [<samp>&nbsp;&nbsp;vrfs</samp>](## "sflow_settings.vrfs") | List, items: Dictionary | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;name</samp>](## "sflow_settings.vrfs.[].name") | String | Required, Unique | | | VRF name. |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;source_interface</samp>](## "sflow_settings.vrfs.[].source_interface") | String | | | | Source interface to use for sFlow destinations in this VRF.<br>If set for the VRFs defined by `mgmt_interface_vrf` or `inband_mgmt_vrf`, this setting will take precedence. |

=== "YAML"

Expand Down Expand Up @@ -65,9 +67,14 @@
# An error will be raised if `mgmt_ip` or `ipv6_mgmt_ip` are not configured for the device.
# - `use_inband_mgmt_vrf` will configure the sFlow destination under the VRF set with `inband_mgmt_vrf` and set the `inband_mgmt_interface` as sFlow source-interface.
# An error will be raised if inband management is not configured for the device.
# - Any other string will be used directly as the VRF name but source interface must be set with `sflow.structured_config` as needed.
# - Any other string will be used directly as the VRF name. Remember to set the `sflow_settings.vrfs[].source_interface` if needed.
vrf: <str>
vrfs:

# Custom structured config added under `sflow` for `eos_cli_config_gen`.
structured_config: <dict>
# VRF name.
- name: <str; required; unique>

# Source interface to use for sFlow destinations in this VRF.
# If set for the VRFs defined by `mgmt_interface_vrf` or `inband_mgmt_vrf`, this setting will take precedence.
source_interface: <str>
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 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.
from .avdstructuredconfig import AvdStructuredConfigSflow
from .avdstructuredconfig import AvdStructuredConfigFlows

__all__ = ["AvdStructuredConfigSflow"]
__all__ = ["AvdStructuredConfigFlows"]
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
from ansible_collections.arista.avd.plugins.plugin_utils.avdfacts import AvdFacts
from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdMissingVariableError
from ansible_collections.arista.avd.plugins.plugin_utils.strip_empties import strip_null_from_data
from ansible_collections.arista.avd.plugins.plugin_utils.utils import get
from ansible_collections.arista.avd.plugins.plugin_utils.utils import get, get_item


class AvdStructuredConfigSflow(AvdFacts):
class AvdStructuredConfigFlows(AvdFacts):
"""
This class must be rendered after all other eos_designs modules since it relies on
detecting sflow from the interface structured config generated by the other modules.
Expand Down Expand Up @@ -41,6 +41,8 @@ def sflow(self) -> dict | None:
# This cannot be implemented today since it would be breaking for already released support for sflow on interfaces.
return None

sflow_settings_vrfs = get(self._hostvars, "sflow_settings.vrfs", default=[])

# At this point we have at least one interface with sFlow enabled
# and at least one destination.
sflow = {"run": True}
Expand All @@ -61,7 +63,7 @@ def sflow(self) -> dict | None:
)

vrf = self.shared_utils.mgmt_interface_vrf
source_interface = self.shared_utils.mgmt_interface
source_interface = get(get_item(sflow_settings_vrfs, "name", vrf, default={}), "source_interface", default=self.shared_utils.mgmt_interface)

elif vrf == "use_inband_mgmt_vrf":
# Check for missing interface
Expand All @@ -72,7 +74,13 @@ def sflow(self) -> dict | None:

# self.shared_utils.inband_mgmt_vrf returns None for the default VRF, but here we need "default" to avoid duplicates.
vrf = self.shared_utils.inband_mgmt_vrf or "default"
source_interface = self.shared_utils.inband_mgmt_interface
source_interface = get(
get_item(sflow_settings_vrfs, "name", vrf, default={}), "source_interface", default=self.shared_utils.inband_mgmt_interface
)

else:
# Default is none, meaning we will not configure a source interface for this VRF.
source_interface = get(get_item(sflow_settings_vrfs, "name", vrf, default={}), "source_interface")

if vrf in [None, "default"]:
# Add destination without VRF field
Expand Down Expand Up @@ -100,20 +108,6 @@ def sflow(self) -> dict | None:

return strip_null_from_data(sflow)

@cached_property
def struct_cfgs(self) -> list[dict] | None:
"""
Various structured_config keys.
Covers:
- sflow_settings.structured_config inserted under sflow.*
"""
struct_cfgs = []
if (struct_cfg := get(self._hostvars, "sflow_settings.structured_config")) is not None:
struct_cfgs.append({"sflow": struct_cfg})

return struct_cfgs or None

@cached_property
def _enable_sflow(self) -> bool:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
from ..connected_endpoints import AvdStructuredConfigConnectedEndpoints
from ..core_interfaces_and_l3_edge import AvdStructuredConfigCoreInterfacesAndL3Edge
from ..custom_structured_configuration import AvdStructuredConfigCustomStructuredConfiguration
from ..flows import AvdStructuredConfigFlows
from ..inband_management import AvdStructuredConfigInbandManagement
from ..metadata import AvdStructuredConfigMetadata
from ..mlag import AvdStructuredConfigMlag
from ..network_services import AvdStructuredConfigNetworkServices
from ..overlay import AvdStructuredConfigOverlay
from ..sflow import AvdStructuredConfigSflow
from ..underlay import AvdStructuredConfigUnderlay

AVD_STRUCTURED_CONFIG_CLASSES = [
Expand All @@ -32,11 +32,11 @@
AvdStructuredConfigNetworkServices,
AvdStructuredConfigConnectedEndpoints,
AvdStructuredConfigInbandManagement,
# The sFlow module must be rendered after others contributing interfaces,
# since it parses those interfaces for sFlow config.
AvdStructuredConfigSflow,
# Metadata must be after anything else that can generate structured config, since CV tags can consume from structured config.
AvdStructuredConfigMetadata,
# The Flows module must be rendered after others contributing interfaces,
# since it parses those interfaces for sFlow or flow tracking (ipfix) config.
AvdStructuredConfigFlows,
# The Custom Structured Configuration module must be rendered last,
# since it parses all supported object looking for `struct_cfg`.
AvdStructuredConfigCustomStructuredConfiguration,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,22 @@ keys:
An error will be raised if `mgmt_ip` or `ipv6_mgmt_ip` are not configured for the device.
- `use_inband_mgmt_vrf` will configure the sFlow destination under the VRF set with `inband_mgmt_vrf` and set the `inband_mgmt_interface` as sFlow source-interface.
An error will be raised if inband management is not configured for the device.
- Any other string will be used directly as the VRF name but source interface must be set with `sflow.structured_config` as needed.
- Any other string will be used directly as the VRF name. Remember to set the `sflow_settings.vrfs[].source_interface` if needed.
convert_types:
- int
structured_config:
type: dict
description: Custom structured config added under `sflow` for `eos_cli_config_gen`.
vrfs:
type: list
primary_key: name
items:
type: dict
keys:
name:
type: str
convert_types:
- int
description: VRF name.
source_interface:
type: str
description: |-
Source interface to use for sFlow destinations in this VRF.
If set for the VRFs defined by `mgmt_interface_vrf` or `inband_mgmt_vrf`, this setting will take precedence.

0 comments on commit c869503

Please sign in to comment.