Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
update: data policy definition builder endpoints and models
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Sep 12, 2023
1 parent e1a53ed commit ed702f3
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 14 deletions.
12 changes: 7 additions & 5 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ PUT /v1/feature-profile/sdwan/system/{system_id}/aaa/{parcel_id}|>=20.9|[**Confi
POST /v1/config-group|>=20.9|[**ConfigurationGroup.create_config_group**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_group.py#L49)|[**ConfigGroupCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_group.py#L21)|[**ConfigGroupCreationResponse**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_group.py#L35)|
DELETE /v1/config-group/{config_group_id}|>=20.9|[**ConfigurationGroup.delete_config_group**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_group.py#L54)||None|
PUT /v1/config-group/{config_group_id}|>=20.9|[**ConfigurationGroup.edit_config_group**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_group.py#L59)|[**ConfigGroupEditPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_group.py#L28)|[**ConfigGroupEditResponse**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_group.py#L43)|
POST /template/policy/definition/data||[**ConfigurationPolicyDataDefinitionBuilder.create_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L32)|[**DataDefinitionCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L19)|[**PolicyDefinitionId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L11)|
GET /template/policy/definition/data||[**ConfigurationPolicyDataDefinitionBuilder.get_definitions**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L48)||DataSequence[[**DataDefinition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L27)]|
GET /template/policy/definition/data/{id}||[**ConfigurationPolicyDataDefinitionBuilder.get_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L53)||[**DataDefinition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L27)|
POST /template/policy/definition/data/preview||[**ConfigurationPolicyDataDefinitionBuilder.preview_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L57)|[**DataDefinitionCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L19)|[**PolicyDefinitionPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L42)|
GET /template/policy/definition/data/preview/{id}||[**ConfigurationPolicyDataDefinitionBuilder.preview_policy_definition_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L61)||[**PolicyDefinitionPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L42)|
POST /template/policy/definition/data||[**ConfigurationPolicyDataDefinitionBuilder.create_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L228)|[**DataDefinitionCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L215)|[**PolicyDefinitionId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L11)|
DELETE /template/policy/definition/data/{id}||[**ConfigurationPolicyDataDefinitionBuilder.delete_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L232)||None|
PUT /template/policy/definition/data/{id}||[**ConfigurationPolicyDataDefinitionBuilder.edit_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L240)|[**DataDefinitionEditPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L219)|[**PolicyDefinitionEditResponse**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L33)|
GET /template/policy/definition/data||[**ConfigurationPolicyDataDefinitionBuilder.get_definitions**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L244)||DataSequence[[**PolicyDefinition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L37)]|
GET /template/policy/definition/data/{id}||[**ConfigurationPolicyDataDefinitionBuilder.get_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L248)||[**DataDefinition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L223)|
POST /template/policy/definition/data/preview||[**ConfigurationPolicyDataDefinitionBuilder.preview_policy_definition**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L252)|[**DataDefinitionCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L215)|[**PolicyDefinitionPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L46)|
GET /template/policy/definition/data/preview/{id}||[**ConfigurationPolicyDataDefinitionBuilder.preview_policy_definition_by_id**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_definition_builder.py#L256)||[**PolicyDefinitionPreview**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_definition.py#L46)|
POST /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.create_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L43)|[**DataPrefixListCreationPayload**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L30)|[**PolicyListId**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/model/policy_list.py#L11)|
DELETE /template/policy/list/dataprefix/{id}||[**ConfigurationPolicyDataPrefixListBuilder.delete_policy_list**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L47)||None|
DELETE /template/policy/list/dataprefix||[**ConfigurationPolicyDataPrefixListBuilder.delete_policy_lists_with_info_tag**](https://github.com/CiscoDevNet/vManage-client/blob/main/vmngclient/endpoints/configuration_policy_data_prefix_list_builder.py#L51)||None|
Expand Down
213 changes: 204 additions & 9 deletions vmngclient/endpoints/configuration_policy_data_definition_builder.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,215 @@
# mypy: disable-error-code="empty-body"
from pydantic import BaseModel, Field
from enum import Enum
from typing import Any, List, Optional, Union

from vmngclient.endpoints import APIEndpoints, get, post
from pydantic import BaseModel, Field, IPvAnyNetwork
from typing_extensions import Annotated, Literal

from vmngclient.endpoints import APIEndpoints, delete, get, post, put
from vmngclient.model.policy_definition import (
PolicyDefinition,
PolicyDefinitionCreationPayload,
PolicyDefinitionEditPayload,
PolicyDefinitionEditResponse,
PolicyDefinitionId,
PolicyDefinitionPreview,
)
from vmngclient.typed_list import DataSequence

# TODO: add validators for custom strings (eg.: port ranges, space separated networks)
# TODO: model actions


class DefaultActionType(str, Enum):
DROP = "drop"
ACCEPT = "accept"


class PLPEntryValues(str, Enum):
LOW = "low"
HIGH = "high"


class DNSEntryValues(str, Enum):
REQUEST = "request"
RESPONSE = "response"


class TrafficToEntryValues(str, Enum):
ACCESS = "access"
CORE = "core"
SERVICE = "service"


class DestinationRegionEntryValues(str, Enum):
PRIMARY = "primary-region"
SECONDARY = "secondary-region"
OTHER = "other-region"


class SequenceIpType(str, Enum):
IPV4 = "ipv4"
IPV6 = "ipv6"
ALL = "all"


class BaseAction(str, Enum):
DROP = "drop"
ACCEPT = "accept"


class SequenceType(str, Enum):
APPLICATION_FIREWALL = "applicationFirewall"
DATA = "data"
SERVICE_CHAINING = "serviceChaining"
TRAFFIC_ENGINEERING = "trafficEngineering"
QOS = "qos"


class PacketLengthEntry(BaseModel):
field: Literal["packetLength"]
value: str = Field(description="0-65536 range or single number")


class PLPEntry(BaseModel):
field: Literal["plp"]
value: PLPEntryValues


class ProtocolEntry(BaseModel):
field: Literal["protocol"]
value: str = Field(description="0-255 single numbers separate by space")


class DSCPEntry(BaseModel):
field: Literal["dscp"]
value: str = Field(description="0-63 single numbers separate by space")


class SourceIPEntry(BaseModel):
field: Literal["sourceIp"]
value: str = Field(description="IP network specifier separate by space")


class SourcePortEntry(BaseModel):
field: Literal["sourcePort"]
value: str = Field(description="0-65535 range or separate by space")


class DestinationIPEntry(BaseModel):
field: Literal["destinationIp"]
value: IPvAnyNetwork


class DestinationPortEntry(BaseModel):
field: Literal["destinationPort"]
value: str = Field(description="0-65535 range or separate by space")


class TCPEntry(BaseModel):
field: Literal["tcp"]
value: Literal["syn"]


class DNSEntry(BaseModel):
field: Literal["dns"]
value: DNSEntryValues


class TrafficToEntry(BaseModel):
field: Literal["trafficTo"]
value: TrafficToEntryValues


class DestinationRegionEntry(BaseModel):
field: Literal["destinationRegion"]
value: DestinationRegionEntryValues


class SourceDataPrefixListEntry(BaseModel):
field: Literal["sourceDataPrefixList"]
ref: str


class DestinationDataPrefixListEntry(BaseModel):
field: Literal["destinationDataPrefixList"]
ref: str


class SourceDataIPv6PrefixListEntry(BaseModel):
field: Literal["sourceDataIpv6PrefixList"]
ref: str


class DestinationDataIPv6PrefixListEntry(BaseModel):
field: Literal["destinationDataIpv6PrefixList"]
ref: str


class DNSAppListEntry(BaseModel):
field: Literal["dnsAppList"]
ref: str


class AppListEntry(BaseModel):
field: Literal["appList"]
ref: str


Entry = Annotated[
Union[
PacketLengthEntry,
PLPEntry,
ProtocolEntry,
DSCPEntry,
SourceIPEntry,
SourcePortEntry,
DestinationIPEntry,
DestinationPortEntry,
TCPEntry,
DNSEntry,
TrafficToEntry,
SourceDataPrefixListEntry,
DestinationDataPrefixListEntry,
SourceDataIPv6PrefixListEntry,
DestinationDataIPv6PrefixListEntry,
DestinationRegionEntry,
DNSAppListEntry,
AppListEntry,
],
Field(discriminator="field"),
]


class Match(BaseModel):
entries: List[Entry]


class Action(BaseModel):
pass


class Sequence(BaseModel):
sequence_id: int = Field(alias="sequenceId")
sequence_name: str = Field(alias="sequenceName")
base_action: BaseAction = Field(alias="baseAction")
sequence_type: SequenceType = Field(alias="sequenceType")
sequence_ip_type: SequenceIpType = Field(alias="sequenceIpType")
match: Match
actions: List[Any]


class DefaultAction(BaseModel):
type: DefaultActionType


class Data(BaseModel):
type: str = Field(default="data", const=True)
default_action: Optional[DefaultAction] = Field(
default=DefaultAction(type=DefaultActionType.DROP), alias="defaultAction"
)
is_activated_by_vsmart: Optional[bool] = Field(default=False, alias="isActivatedByVsmart")
sequences: List[Sequence] = []


class DataDefinitionCreationPayload(Data, PolicyDefinitionCreationPayload):
Expand All @@ -33,21 +229,20 @@ class ConfigurationPolicyDataDefinitionBuilder(APIEndpoints):
def create_policy_definition(self, payload: DataDefinitionCreationPayload) -> PolicyDefinitionId:
...

def delete_policy_definition(self):
# DELETE /template/policy/definition/data/{id}
@delete("/template/policy/definition/data/{id}")
def delete_policy_definition(self, id: str) -> None:
...

def edit_multiple_policy_definition(self):
# PUT /template/policy/definition/data/multiple/{id}
...

def edit_policy_definition(self):
# PUT /template/policy/definition/data/{id}
@put("/template/policy/definition/data/{id}")
def edit_policy_definition(self, id: str, payload: DataDefinitionEditPayload) -> PolicyDefinitionEditResponse:
...

@get("/template/policy/definition/data", "data")
def get_definitions(self) -> DataSequence[DataDefinition]:
# GET /template/policy/definition/data
def get_definitions(self) -> DataSequence[PolicyDefinition]:
...

@get("/template/policy/definition/data/{id}")
Expand All @@ -62,6 +257,6 @@ def preview_policy_definition(self, payload: DataDefinitionCreationPayload) -> P
def preview_policy_definition_by_id(self, id: str) -> PolicyDefinitionPreview:
...

def save_policy_definition_in_bulk15(self):
def save_policy_definition_in_bulk(self):
# PUT /template/policy/definition/data/bulk
...
4 changes: 4 additions & 0 deletions vmngclient/model/policy_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class PolicyDefinitionEditPayload(PolicyDefinitionCreationPayload, PolicyDefinit
pass


class PolicyDefinitionEditResponse(BaseModel):
master_templates_affected: List[str] = Field(default=[], alias="masterTemplatesAffected")


class PolicyDefinition(PolicyDefinitionEditPayload, InfoTag):
last_updated: datetime.datetime = Field(alias="lastUpdated")
owner: str
Expand Down

0 comments on commit ed702f3

Please sign in to comment.