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

Commit

Permalink
Incorrect value for static IPv4 address after migration to ux2 #57
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrajewski committed Jul 11, 2024
1 parent ec92f80 commit c9208b5
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,6 @@ def parse_prefix(self, address: Optional[Union[Variable, Global[IPv4Interface]]]
return AddressWithMask(address=address, mask=address)

return AddressWithMask(
address=as_global(address.value.network.network_address),
address=as_global(address.value.ip),
mask=as_global(str(address.value.netmask)),
)
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def _set_summary_addresses(self, values: dict) -> List[SummaryAddress]:
def _set_summary_address(self, addr: dict) -> SummaryAddress:
return SummaryAddress(
prefix=AddressWithMask(
address=as_global(addr["prefix"].value.network.network_address),
address=as_global(addr["prefix"].value.ip),
mask=as_global(str(addr["prefix"].value.netmask)),
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def parse_address(self, data: dict) -> Optional[AddressWithMask]:
if not address:
return None
return AddressWithMask(
address=as_global(address.value.network.network_address),
address=as_global(address.value.ip),
mask=as_global(str(address.value.netmask)),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def configure_address(self, values: dict) -> None:
"Ipsec Address is required in UX2 parcel but in a Feature Template can be optional."
)
values["address"] = AddressWithMask(
address=as_global(str(address.value.network.network_address)),
address=as_global(str(address.value.ip)),
mask=as_global(str(address.value.network.netmask)),
)

Expand All @@ -85,7 +85,7 @@ def configure_tunnel_destination(self, values: dict) -> None:
if tunnel_destination := values.get("tunnel_destination"):
if isinstance(tunnel_destination.value, IPv4Interface):
values["tunnel_destination"] = AddressWithMask(
address=as_global(str(tunnel_destination.value.network.network_address)),
address=as_global(str(tunnel_destination.value.ip)),
mask=as_global(str(tunnel_destination.value.network.netmask)),
)
elif isinstance(tunnel_destination.value, IPv4Address):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _set_range(self, area_value: dict) -> Optional[List[SummaryRoute]]:
def _set_summary_prefix(self, range_: dict) -> None:
if address := range_.pop("address"):
range_["network"] = AddressWithMask(
address=as_global(str(address.value.network.network_address)),
address=as_global(str(address.value.ip)),
mask=as_global(str(address.value.netmask)),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def parse_route_ipv4(self, values: dict) -> Optional[List[Ipv4RouteItem]]:
if prefix.option_type == OptionType.GLOBAL:
ipv4route_item = Ipv4RouteItem(
prefix=TransportPrefix(
ip_address=as_global(prefix.value.network.network_address),
ip_address=as_global(prefix.value.ip),
subnet_mask=as_global(str(prefix.value.netmask), SubnetMask),
)
)
Expand Down Expand Up @@ -569,7 +569,7 @@ def parse_ipv4_route(self, values: dict) -> None:
if prefix.option_type == OptionType.GLOBAL:
interface = IPv4Interface(prefix.value)
route_prefix = RoutePrefix(
ip_address=as_global(interface.network.network_address),
ip_address=as_global(interface.ip),
subnet_mask=as_global(str(interface.netmask)),
)

Expand Down Expand Up @@ -637,7 +637,7 @@ def parse_ipv6_route(self, values: dict) -> None:
for route in ipv6_route:
ipv6_interface = IPv6Interface(route.get("prefix").value)
route_prefix = RoutePrefix(
ip_address=as_global(ipv6_interface.network.network_address),
ip_address=as_global(ipv6_interface.ip),
subnet_mask=as_global(str(ipv6_interface.netmask)),
)
if route_interface := route.pop("route_interface", []):
Expand Down Expand Up @@ -689,7 +689,7 @@ def _parse_prefix_entry(self, prefix_entry: dict, pydantic_field: OmpUX2Field) -
else:
ipv4_interface = IPv4Interface(prefix.value)
route_prefix = AddressWithMask(
address=as_global(ipv4_interface.network.network_address),
address=as_global(ipv4_interface.ip),
mask=as_global(str(ipv4_interface.netmask)),
)
return IPv4Prefix(prefix=route_prefix, aggregate_only=aggregate_only, region=region)
Expand Down Expand Up @@ -717,7 +717,7 @@ def _parse_route(
else:
ipv4_interface = IPv4Interface(route.get("prefix").value)
route_prefix = RoutePrefix(
ip_address=as_global(ipv4_interface.network.network_address),
ip_address=as_global(ipv4_interface.ip),
subnet_mask=as_global(str(ipv4_interface.netmask)),
)
route_item = pydantic_model(prefix=route_prefix)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates
from ipaddress import IPv4Interface
import logging
from copy import deepcopy
from typing import Dict, List, Optional, Union
Expand Down Expand Up @@ -137,18 +138,18 @@ def parse_interface_ip_address(self, data: Dict) -> Union[InterfaceDynamicIPv4Ad
return InterfaceDynamicIPv4Address(dynamic=DynamicDhcpDistance())

def get_static_ipv4_address(self, address_configuration: dict) -> StaticIPv4Address:
address = address_configuration["address"]
address: Union[Variable, Global[IPv4Interface]] = address_configuration["address"]

if isinstance(address, Variable):
return StaticIPv4Address(
ip_address=address,
subnet_mask=address,
)

static_network = address.value.network
interface = address.value
return StaticIPv4Address(
ip_address=as_global(value=static_network.network_address),
subnet_mask=as_global(value=str(static_network.netmask)),
ip_address=as_global(value=interface.ip),
subnet_mask=as_global(value=str(interface.netmask)),
)

def get_secondary_static_ipv4_address(self, address_configuration: dict) -> Optional[List[StaticIPv4Address]]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def parse_address(self, data: dict) -> AddressWithMask:
# TODO: Ask technitians if there can be default value for address
raise CatalystwanConverterCantConvertException("Address is required")
return AddressWithMask(
address=as_global(address.value.network.network_address),
address=as_global(address.value.ip),
mask=as_global(str(address.value.netmask)),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parse_address(self, data: dict) -> AddressWithMask:
if not address:
raise CatalystwanConverterCantConvertException("Interface address is required")
return AddressWithMask(
address=as_global(address.value.network.network_address),
address=as_global(address.value.ip),
mask=as_global(str(address.value.netmask)),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def parse_static_ip_address(self, interface: IPv4Interface) -> StaticIntfIpAddre
return StaticIntfIpAddress(
static=Static(
static_ip_v4=AddressWithMask(
address=as_global(interface.network.network_address),
address=as_global(interface.ip),
mask=as_global(str(interface.netmask)),
)
)
Expand Down

0 comments on commit c9208b5

Please sign in to comment.