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

Commit

Permalink
all items working and reported
Browse files Browse the repository at this point in the history
  • Loading branch information
sbasan committed Jul 3, 2024
1 parent c8daa91 commit e57fef6
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 103 deletions.
19 changes: 13 additions & 6 deletions catalystwan/api/feature_profile_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from catalystwan.models.configuration.feature_profile.sdwan.routing import AnyRoutingParcel, RoutingBgpParcel
from catalystwan.models.configuration.feature_profile.sdwan.service import AnyServiceParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.multicast import MulticastParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.route_policy import RoutePolicyParcel
from catalystwan.models.configuration.feature_profile.sdwan.sig_security.sig_security import SIGParcel
from catalystwan.models.configuration.feature_profile.sdwan.topology import AnyTopologyParcel
from catalystwan.models.configuration.feature_profile.sdwan.topology.custom_control import CustomControlParcel
Expand Down Expand Up @@ -306,6 +307,12 @@ def get_parcel(self, profile_id: UUID, parcel_type: Type[Ipv4AclParcel], parcel_
def get_parcel(self, profile_id: UUID, parcel_type: Type[Ipv6AclParcel], parcel_id: UUID) -> Parcel[Ipv6AclParcel]:
...

@overload
def get_parcel(
self, profile_id: UUID, parcel_type: Type[RoutePolicyParcel], parcel_id: UUID
) -> Parcel[RoutePolicyParcel]:
...

def get_parcel(
self, profile_id: UUID, parcel_type: Type[Union[AnyTransportParcel, AnyRoutingParcel]], parcel_id: UUID
) -> Parcel:
Expand Down Expand Up @@ -431,21 +438,21 @@ def delete_all_profiles(self) -> None:
self.delete_profile(profile.profile_id)

def create_parcel(
self, profile_uuid: UUID, payload: AnyServiceParcel, vpn_uuid: Optional[UUID] = None
self, profile_id: UUID, payload: AnyServiceParcel, vpn_uuid: Optional[UUID] = None
) -> ParcelCreationResponse:
"""
Create Service Parcel for selected profile_id based on payload type
"""
if vpn_uuid is not None:
if isinstance(payload, MulticastParcel):
response = self.endpoint.create_service_parcel(profile_uuid, payload._get_parcel_type(), payload)
response = self.endpoint.create_service_parcel(profile_id, payload._get_parcel_type(), payload)
return self.endpoint.associate_parcel_with_vpn(
profile_uuid, vpn_uuid, payload._get_parcel_type(), ParcelAssociationPayload(parcel_id=response.id)
profile_id, vpn_uuid, payload._get_parcel_type(), ParcelAssociationPayload(parcel_id=response.id)
)
else:
parcel_type = payload._get_parcel_type().replace("lan/vpn/", "")
return self.endpoint.create_lan_vpn_sub_parcel(profile_uuid, vpn_uuid, parcel_type, payload)
return self.endpoint.create_service_parcel(profile_uuid, payload._get_parcel_type(), payload)
return self.endpoint.create_lan_vpn_sub_parcel(profile_id, vpn_uuid, parcel_type, payload)
return self.endpoint.create_service_parcel(profile_id, payload._get_parcel_type(), payload)

def delete_parcel(self, profile_uuid: UUID, parcel_type: Type[AnyServiceParcel], parcel_uuid: UUID) -> None:
"""
Expand Down Expand Up @@ -1194,7 +1201,7 @@ def get(
profile_id=profile_id, policy_object_list_type=policy_object_list_type, list_object_id=parcel_id
)

def create(self, profile_id: UUID, payload: AnyPolicyObjectParcel) -> ParcelCreationResponse:
def create_parcel(self, profile_id: UUID, payload: AnyPolicyObjectParcel) -> ParcelCreationResponse:
"""
Create Policy Object for selected profile_id based on payload type
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_create_extended_community_parcel(self):
ext.add_site_of_origin_community("1.2.3.4", 1000)
ext.add_site_of_origin_community("10.20.30.40", 3000)

self.created_id = self.policy_api.create(self.profile_uuid, ext).id
self.created_id = self.policy_api.create_parcel(self.profile_uuid, ext).id
parcel = self.policy_api.get(self.profile_uuid, ExtendedCommunityParcel, parcel_id=self.created_id)

assert parcel.payload.parcel_name == "ExampleTestName"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def test_create_ssl_decryption_parcel(self):
min_tls_ver="TLSv1.1",
)

self.created_id = self.policy_api.create(self.profile_uuid, ssl_decryption_parcel).id
self.created_id = self.policy_api.create_parcel(self.profile_uuid, ssl_decryption_parcel).id
read_parcel = self.policy_api.get(self.profile_uuid, SslDecryptionParcel, parcel_id=self.created_id)

assert read_parcel.payload.parcel_name == "test_ssl_profile"
Expand Down
11 changes: 6 additions & 5 deletions catalystwan/models/configuration/config_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,24 +270,25 @@ def list_transformed_parcels_with_origin(self, origin: Set[UUID]) -> List[Transf
return [p for p in self.profile_parcels if p.header.origin in origin]

def add_subelement_in_config_group(
self, profile_type: ProfileType, device_template_id: UUID, subelement: UUID
self, profile_types: List[ProfileType], device_template_id: UUID, subelement: UUID
) -> bool:
profile_ids: Set[UUID] = set()
added = False
for config_group in self.config_groups:
if config_group.header.origin == device_template_id:
profile_ids = config_group.header.subelements
break
if not profile_ids:
return False
return added
for feature_profile in self.feature_profiles:
if feature_profile.header.type == profile_type and feature_profile.header.origin in profile_ids:
if feature_profile.header.type in profile_types and feature_profile.header.origin in profile_ids:
head = feature_profile.header
if head.localized_policy_subelements is None:
head.localized_policy_subelements = {subelement}
else:
head.localized_policy_subelements.add(subelement)
return True
return False
added = True
return added


class ConfigTransformResult(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class MatchEntry(BaseModel):
packet_length: Optional[Global[Union[str, int]]] = Field(
default=None, validation_alias="packetLength", serialization_alias="packetLength"
)
source_data_prefix: Union[SourceDataPrefix, SourceDataPrefixList] = Field(
source_data_prefix: Union[SourceDataPrefix, SourceDataPrefixList, None] = Field(
default=None, validation_alias="sourceDataPrefix", serialization_alias="sourceDataPrefix"
)
source_ports: Optional[List[SourcePorts]] = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ class RoutePolicySequence(BaseModel):
)
base_action: Union[Global[AcceptRejectActionType], Default[AcceptRejectActionType]] = Field(
default=as_default("reject", AcceptRejectActionType),
serialization_alias="routePolicyActionType",
validation_alias="routePolicyActionType",
serialization_alias="baseAction",
validation_alias="baseAction",
description="Base Action",
)
protocol: Union[Global[Protocol], Default[Protocol]] = Field(
Expand Down Expand Up @@ -411,7 +411,7 @@ class RoutePolicyParcel(_ParcelBase):
)
default_action: Union[Global[AcceptRejectActionType], Default[AcceptRejectActionType]] = Field(
default=as_default("reject", AcceptRejectActionType),
validation_alias=AliasPath("data", "routePolicyActionType"),
validation_alias=AliasPath("data", "defaultAction"),
description="Default Action",
)
sequences: List[RoutePolicySequence] = Field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing_extensions import Annotated

from catalystwan.models.configuration.feature_profile.sdwan.acl import AnyAclParcel
from catalystwan.models.configuration.feature_profile.sdwan.service.route_policy import RoutePolicyParcel

from .cellular_controller import CellularControllerParcel
from .cellular_profile import CellularProfileParcel
Expand Down Expand Up @@ -65,6 +66,7 @@
AnyTransportVpnParcel,
AnyTransportVpnSubParcel,
AnyManagementVpnSubParcel,
RoutePolicyParcel,
],
Field(discriminator="type_"),
]
Expand Down
4 changes: 0 additions & 4 deletions catalystwan/models/policy/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ class PolicyCreationPayload(BaseModel):
default="default description", serialization_alias="policyDescription", validation_alias="policyDescription"
)
policy_type: str = Field(serialization_alias="policyType", validation_alias="policyType")
policy_definition: Union[PolicyDefinition, str] = Field(
serialization_alias="policyDefinition",
validation_alias="policyDefinition",
)
is_policy_activated: bool = Field(
default=False, serialization_alias="isPolicyActivated", validation_alias="isPolicyActivated"
)
Expand Down
4 changes: 2 additions & 2 deletions catalystwan/utils/config_migration/creators/config_pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
push_result=self._push_result,
push_context=self._push_context,
)
self._localized_policy_feature_updater = LocalizedPolicyPusher(
self._localized_policy_feature_pusher = LocalizedPolicyPusher(
ux2_config=ux2_config,
session=session,
progress=progress,
Expand Down Expand Up @@ -81,7 +81,7 @@ def push(self) -> UX2ConfigPushResult:
self._create_cloud_credentials()
self._create_config_groups()
self._groups_of_interests_pusher.push()
self._localized_policy_feature_updater.push()
self._localized_policy_feature_pusher.push()
self._security_policy_pusher.push()
self._create_topology_groups(
self._push_context.default_policy_object_profile_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def push(self) -> None:

try:
parcel = update_parcel_references(parcel, self.push_context.id_lookup)
parcel_id = self._policy_object_api.create(profile_id=profile_id, payload=parcel).id
parcel_id = self._policy_object_api.create_parcel(profile_id=profile_id, payload=parcel).id
profile_rollback.add_parcel(parcel.type_, parcel_id)
self._push_result.report.groups_of_interest.add_created(parcel.parcel_name, parcel_id)
self.push_context.id_lookup[transformed_parcel.header.origin] = parcel_id
Expand Down
Loading

0 comments on commit e57fef6

Please sign in to comment.