Skip to content

Commit

Permalink
Merge branch 'devel' into refactor/plugins/move-cv-client-to-pyavd
Browse files Browse the repository at this point in the history
  • Loading branch information
ClausHolbechArista authored Jun 20, 2024
2 parents 6be4aac + 5d6858b commit fd1af54
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ ACL has counting mode `counters per-entry` enabled!
| 10 | remark ACL to restrict access RFC1918 addresses |
| 20 | permit ip 10.0.0.0/8 any |
| 30 | permit ip 192.0.2.0/24 any |
| - | permit response traffic nat |

##### ACL-03

Expand Down Expand Up @@ -167,6 +168,7 @@ ip access-list ACL-02
10 remark ACL to restrict access RFC1918 addresses
20 permit ip 10.0.0.0/8 any
30 permit ip 192.0.2.0/24 any
permit response traffic nat
!
ip access-list ACL-03
10 remark ACL to restrict access RFC1918 addresses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ ip access-list ACL-02
10 remark ACL to restrict access RFC1918 addresses
20 permit ip 10.0.0.0/8 any
30 permit ip 192.0.2.0/24 any
permit response traffic nat
!
ip access-list ACL-03
10 remark ACL to restrict access RFC1918 addresses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ access_lists:
action: "permit ip 192.0.2.0/24 any"
- name: ACL-02
counters_per_entry: true
permit_response_traffic: nat
sequence_numbers:
- sequence: 10
action: "remark ACL to restrict access RFC1918 addresses"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@

__metaclass__ = type

from ansible.errors import AnsibleFilterError

from ansible_collections.arista.avd.plugins.plugin_utils.pyavd_wrappers import RaiseOnUse, wrap_filter

PLUGIN_NAME = "arista.avd.status_render"

try:
from pyavd.j2filters.status_render import status_render
except ImportError as e:
status_render = RaiseOnUse(
AnsibleFilterError(
f"The '{PLUGIN_NAME}' plugin requires the 'pyavd' Python library. Got import error",
orig_exc=e,
)
)

DOCUMENTATION = r"""
---
Expand Down Expand Up @@ -38,33 +53,6 @@


class FilterModule(object):
# STATIC EMOJI CODE
GH_CODE = {}
# Github MD code for Emoji checked box
GH_CODE["PASS"] = ":white_check_mark:"
# GH MD code for Emoji Fail
GH_CODE["FAIL"] = ":x:"

def status_render(self, state_string, rendering):
"""
status_render Convert Text to EMOJI code
Parameters
----------
state_string : str
Text to convert in EMOJI
rendering : string
Markdown Flavor to use for Emoji rendering.
Returns
-------
str
Value to render in markdown
"""
if rendering == "github":
return self.GH_CODE[state_string.upper()]
else:
return state_string

def filters(self):
return {"status_render": self.status_render}
return {"status_render": wrap_filter(PLUGIN_NAME)(status_render)}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
| [<samp>access_lists</samp>](## "access_lists") | List, items: Dictionary | | | | |
| [<samp>&nbsp;&nbsp;-&nbsp;name</samp>](## "access_lists.[].name") | String | Required, Unique | | | Access-list Name. |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;counters_per_entry</samp>](## "access_lists.[].counters_per_entry") | Boolean | | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;permit_response_traffic</samp>](## "access_lists.[].permit_response_traffic") | String | | | Valid Values:<br>- <code>nat</code> | Permit response traffic automatically based on NAT translations.<br>Minimum EOS version requirement 4.32.2F. |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;sequence_numbers</samp>](## "access_lists.[].sequence_numbers") | List, items: Dictionary | Required | | | |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;sequence</samp>](## "access_lists.[].sequence_numbers.[].sequence") | Integer | Required, Unique | | | Sequence ID. |
| [<samp>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;action</samp>](## "access_lists.[].sequence_numbers.[].action") | String | Required | | | Action as string.<br>Example: "deny ip any any"<br> |
Expand All @@ -22,6 +23,10 @@
# Access-list Name.
- name: <str; required; unique>
counters_per_entry: <bool>

# Permit response traffic automatically based on NAT translations.
# Minimum EOS version requirement 4.32.2F.
permit_response_traffic: <str; "nat">
sequence_numbers: # required

# Sequence ID.
Expand Down
12 changes: 0 additions & 12 deletions ansible_collections/arista/avd/tests/unit/filters/filter_utils.py

This file was deleted.

This file was deleted.

1 change: 1 addition & 0 deletions python-avd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ fix-libs: ## Fix/remove various Ansible specifics things from python files
find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.filter.generate_route_target/$(PYAVD_FILTER_IMPORT)\.generate_route_target/g' {} +
find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.filter.hide_passwords/$(PYAVD_FILTER_IMPORT)\.hide_passwords/g' {} +
find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.filter.list_compress/$(PYAVD_FILTER_IMPORT)\.list_compress/g' {} +
find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.filter.status_render/$(PYAVD_FILTER_IMPORT)\.status_render/g' {} +

find $(PACKAGE_DIR) -name '*.py' -exec sed -i -e 's/ansible_collections\.arista\.avd\.plugins\.filter/$(VENDOR_IMPORT)\.j2\.filter/g' {} +

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ ACL has counting mode `counters per-entry` enabled!
{% for sequence in access_list.sequence_numbers | arista.avd.natural_sort('sequence') %}
| {{ sequence.sequence }} | {{ sequence.action }} |
{% endfor %}
{% if access_list.permit_response_traffic is arista.avd.defined %}
| - | permit response traffic {{ access_list.permit_response_traffic }} |
{% endif %}

{% endfor %}
#### Extended Access-lists Device Configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ ip access-list {{ access_list.name }}
{{ sequence.sequence }} {{ sequence.action }}
{% endif %}
{% endfor %}
{% if access_list.permit_response_traffic is arista.avd.defined %}
permit response traffic {{ access_list.permit_response_traffic }}
{% endif %}
{% endfor %}
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,14 @@
"type": "boolean",
"title": "Counters Per Entry"
},
"permit_response_traffic": {
"type": "string",
"enum": [
"nat"
],
"description": "Permit response traffic automatically based on NAT translations.\nMinimum EOS version requirement 4.32.2F.",
"title": "Permit Response Traffic"
},
"sequence_numbers": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ keys:
- int
counters_per_entry:
type: bool
permit_response_traffic:
type: str
valid_values:
- nat
description: 'Permit response traffic automatically based on NAT translations.

Minimum EOS version requirement 4.32.2F.'
sequence_numbers:
type: list
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ keys:
convert_types: [ int ]
counters_per_entry:
type: bool
permit_response_traffic:
type: str
valid_values:
- nat
description: |-
Permit response traffic automatically based on NAT translations.
Minimum EOS version requirement 4.32.2F.
sequence_numbers:
type: list
required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18397,6 +18397,14 @@
"type": "boolean",
"title": "Counters Per Entry"
},
"permit_response_traffic": {
"type": "string",
"enum": [
"nat"
],
"description": "Permit response traffic automatically based on NAT translations.\nMinimum EOS version requirement 4.32.2F.",
"title": "Permit Response Traffic"
},
"sequence_numbers": {
"type": "array",
"items": {
Expand Down
32 changes: 32 additions & 0 deletions python-avd/pyavd/j2filters/status_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (c) 2023-2024 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 __future__ import annotations


def status_render(state_string, rendering):
"""
status_render Convert Text to EMOJI code
Parameters
----------
state_string : str
Text to convert in EMOJI
rendering : string
Markdown Flavor to use for Emoji rendering.
Returns
-------
str
Value to render in markdown
"""
# STATIC EMOJI CODE
GH_CODE = {}
# Github MD code for Emoji checked box
GH_CODE["PASS"] = ":white_check_mark:"
# GH MD code for Emoji Fail
GH_CODE["FAIL"] = ":x:"

if rendering == "github":
return GH_CODE[state_string.upper()]
return state_string
2 changes: 2 additions & 0 deletions python-avd/pyavd/templater.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def import_filters_and_tests(self) -> None:
from .j2filters.list_compress import list_compress
from .j2filters.natural_sort import natural_sort
from .j2filters.snmp_hash import snmp_hash
from .j2filters.status_render import status_render
from .j2tests.contains import contains
from .vendor.j2.filter.range_expand import range_expand
from .vendor.j2.test.defined import defined
Expand All @@ -101,6 +102,7 @@ def import_filters_and_tests(self) -> None:
"arista.avd.natural_sort": natural_sort,
"arista.avd.range_expand": range_expand,
"arista.avd.snmp_hash": snmp_hash,
"arista.avd.status_render": status_render,
}
)
self.environment.tests.update(
Expand Down
16 changes: 16 additions & 0 deletions python-avd/tests/pyavd/j2filters/test_status_render.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2023-2024 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 __future__ import annotations

import pytest
from pyavd.j2filters.status_render import status_render

STATE_STRINGS = [("PASS", "github", ":white_check_mark:"), ("fail", "github", ":x:"), ("FAIL", "test", "FAIL")]


class TestMarkdownRenderingFilter:
@pytest.mark.parametrize("state_string, rendering, markdown_code", STATE_STRINGS)
def test_status_render_valid(self, state_string, rendering, markdown_code):
resp = status_render(state_string, rendering)
assert resp == markdown_code

0 comments on commit fd1af54

Please sign in to comment.