This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Feature Templates support. (#95)
* Add basic aaa templates * Add basic script * create radius j2 * radius tacacs scripts for aaa feature template * Fix User dataclass * Move configuration jinja files * created vpn * created vpn * Add TenantAPI. * working template * Add TenantAPI. * Rename template_api. * Rename template_api. * create dns for vpn * added mapping * Add TenantModel. * Add TenantModel. * Add AAAModel. * tojson * Add tenant payload * Align new model to pydantic. * adaptation to the new concept * changed names with vpn to cisco_vpn * added generate vpn id * added vpn ipv4routing next-hop * Finish Cisco VPN template * Add path as a abstract property. * Overload generate_payload. * Finish Tenant template. * Fix AAAModel. * Fix static typing. * Remove fr_templates.py * Revert changes. * Use double-quotes * Fix unittests. * fix test * Fix mocks order. * Fix mocks order. * Add TemplateAlreadyExistsError. * Return template_id. * Changed numeric value to enum * Update dependencies. Co-authored-by: Tomasz Zietkowski -X (tzietkow - CODILIME SP ZOO at Cisco) <[email protected]>
- Loading branch information
Showing
23 changed files
with
2,683 additions
and
799 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Contains a list of feature templates. | ||
These feature template models are used to create and modify the templates | ||
on the vManage server. | ||
In addition, they are used to convert CLI config into separate feature | ||
templates in vManage. | ||
""" | ||
|
||
# Basic FeatureTemplate class | ||
from vmngclient.api.templates.feature_template import FeatureTemplate | ||
|
||
# AAA Templates | ||
from vmngclient.api.templates.payloads.aaa.aaa_model import AAAModel | ||
|
||
# Cisco VPN Templates | ||
from vmngclient.api.templates.payloads.cisco_vpn.cisco_vpn_model import ( | ||
DNS, | ||
CiscoVPNModel, | ||
GatewayType, | ||
IPv4Route, | ||
IPv6Route, | ||
Mapping, | ||
NextHop, | ||
) | ||
|
||
# CEdge Templates | ||
from vmngclient.api.templates.payloads.tenant.tenant_model import TenantModel | ||
|
||
__all__ = [ | ||
"FeatureTemplate", | ||
"TenantModel", | ||
"AAAModel", | ||
"CiscoVPNModel", | ||
"DNS", | ||
"Mapping", | ||
"IPv4Route", | ||
"IPv6Route", | ||
"GatewayType", | ||
"NextHop", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from abc import ABC, abstractmethod | ||
from pathlib import Path | ||
|
||
from jinja2 import DebugUndefined, Environment, FileSystemLoader, meta # type: ignore | ||
from pydantic import BaseModel # type: ignore | ||
|
||
from vmngclient.session import vManageSession | ||
|
||
|
||
class FeatureTemplate(BaseModel, ABC): | ||
name: str | ||
description: str | ||
|
||
def generate_payload(self, session: vManageSession) -> str: | ||
env = Environment( | ||
loader=FileSystemLoader(self.payload_path.parent), | ||
trim_blocks=True, | ||
lstrip_blocks=True, | ||
undefined=DebugUndefined, | ||
) | ||
template = env.get_template(self.payload_path.name) | ||
output = template.render(self.dict()) | ||
|
||
ast = env.parse(output) | ||
if meta.find_undeclared_variables(ast): | ||
print(meta.find_undeclared_variables(ast)) | ||
raise Exception | ||
return output | ||
|
||
def generate_cli(self) -> str: | ||
raise NotImplementedError() | ||
|
||
@property | ||
@abstractmethod | ||
def payload_path(self) -> Path: | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
from __future__ import annotations | ||
|
||
from enum import Enum | ||
from pathlib import Path | ||
from typing import ClassVar, List, Optional | ||
|
||
from attr import define, field # type: ignore | ||
|
||
from vmngclient.api.templates.feature_template import FeatureTemplate | ||
from vmngclient.dataclasses import User | ||
|
||
|
||
class AuthenticationOrder(Enum): | ||
LOCAL = "local" | ||
RADIUS = "radius" | ||
TACACS = "tacacs" | ||
|
||
|
||
class TacacsAuthenticationMethod(Enum): | ||
PAP = "pap" | ||
|
||
|
||
class Action(Enum): | ||
ACCEPT = "accept" | ||
DENY = "deny" | ||
|
||
|
||
class VpnType(Enum): | ||
VPN_TRANSPORT = 0 | ||
VPN_MANAGMENT = 512 | ||
|
||
|
||
# from vmngclient.third_parties | ||
@define | ||
class TacacsServer: | ||
"""Default values from documentations.""" | ||
|
||
address: str | ||
auth_port: int = field(default=49) | ||
secret_key: Optional[str] = field(default=None) | ||
source_interface: Optional[str] = field(default=None) | ||
vpn: int = field(default=0) | ||
priority: int = field(default=0) | ||
|
||
|
||
@define | ||
class RadiusServer: | ||
"""Default values from documentations.""" | ||
|
||
address: str | ||
secret_key: Optional[str] = field(default=None) | ||
source_interface: Optional[str] = field(default=None) | ||
acct_port: int = field(default=1813) | ||
auth_port: int = field(default=1812) | ||
tag: Optional[str] = field(default=None) | ||
timeout: int = field(default=5) | ||
vpn: int = field(default=0) | ||
priority: int = field(default=0) | ||
|
||
|
||
@define | ||
class AuthTask: | ||
name: str | ||
default_action: Action = field(default=Action.ACCEPT) | ||
|
||
|
||
class AAAModel(FeatureTemplate): | ||
class Config: | ||
arbitrary_types_allowed = True | ||
|
||
payload_path: ClassVar[Path] = Path(__file__).parent / "feature" / "aaa.json.j2" | ||
|
||
auth_order: List[AuthenticationOrder] | ||
auth_fallback: bool | ||
auth_disable_audit_logs: bool | ||
auth_admin_order: bool | ||
auth_disable_netconf_logs: bool | ||
auth_radius_servers: List[str] = [] | ||
|
||
local_users: List[User] = [] | ||
|
||
accounting: bool = True | ||
|
||
tacacs_authentication: TacacsAuthenticationMethod = TacacsAuthenticationMethod.PAP | ||
tacacs_timeout: int = 5 | ||
tacacs_servers: List[TacacsServer] = [] | ||
radius_retransmit: int = 3 | ||
radius_timeout: int = 5 | ||
radius_servers: List[RadiusServer] = [] |
Oops, something went wrong.