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

Move to Python 3.10 #1

Merged
merged 8 commits into from
Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/python-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.9"] #, "3.10"]
python-version: ["3.10"] #, "3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -93,7 +93,7 @@ jobs:
files: |
./bin/${{ env.LINUX_AMD64_BINARY }}
./dist/*
./CHANGELOG.md
./build/x86_64-unknown-linux-gnu/release/install/COPYING.txt

- name: Release on PyPi
uses: pypa/gh-action-pypi-publish@release/v1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: true
matrix:
python-version: ["3.9", "3.10"]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
109 changes: 32 additions & 77 deletions netplanner/interfaces/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,90 +74,45 @@ def streamline_keys(
new_char=new_char,
ignore_levels=ignore_levels,
)
## Python 3.10 code
# match dictionary[key]:
# case dict():
# dictionary[sanitized_key] = BaseSerializer.streamline_keys(
# dictionary[key],
# level=level + 1,
# old_char=old_char,
# new_char=new_char,
# ignore_levels=ignore_levels,
# )
# case _:
# dictionary[sanitized_key] = dictionary.pop(key)
if isinstance(dictionary[key], dict):
dictionary[sanitized_key] = BaseSerializer.streamline_keys(
dictionary[key],
level=level + 1,
old_char=old_char,
new_char=new_char,
ignore_levels=ignore_levels,
)
else:
dictionary[sanitized_key] = dictionary.pop(key)
match dictionary[key]:
case dict():
dictionary[sanitized_key] = BaseSerializer.streamline_keys(
dictionary[key],
level=level + 1,
old_char=old_char,
new_char=new_char,
ignore_levels=ignore_levels,
)
case _:
dictionary[sanitized_key] = dictionary.pop(key)
return dictionary

@staticmethod
def to_serializable(value) -> Union[int, str]:
## Python 3.10 code
# match value:
# case Enum():
# return Base.to_serializable(value.value)
# case IPv4Network() | IPv6Network() | IPv4Interface() | IPv6Interface() | IPv4Address() | IPv6Address() | str():
# return str(value)
# case int():
# return int(value)
# case _:
# return value
if isinstance(value, Enum):
return Base.to_serializable(value.value)
elif isinstance(
value,
(
IPv4Network,
IPv6Network,
IPv4Interface,
IPv6Interface,
IPv4Address,
IPv6Address,
str,
),
):
return str(value)
elif isinstance(value, int):
return int(value)
else:
return value
match value:
case Enum():
return Base.to_serializable(value.value)
case IPv4Network() | IPv6Network() | IPv4Interface() | IPv6Interface() | IPv4Address() | IPv6Address() | str():
return str(value)
case int():
return int(value)
case _:
return value

@staticmethod
def to_complex_serializable(data) -> Union[list, dict, int, str]:
## Python 3.10 code
# match data:
# case list() | set():
# return [
# BaseSerializer.to_complex_serializable(item) for item in data
# ]
# case dict():
# return {
# BaseSerializer.to_serializable(
# key
# ): BaseSerializer.to_complex_serializable(val)
# for key, val in data.items()
# }
# case _:
# return BaseSerializer.to_serializable(data)
if isinstance(data, (list, set)):
return [BaseSerializer.to_complex_serializable(item) for item in data]
elif isinstance(data, dict):
return {
BaseSerializer.to_serializable(
key
): BaseSerializer.to_complex_serializable(val)
for key, val in data.items()
}
else:
return BaseSerializer.to_serializable(data)
match data:
case list() | set():
return [BaseSerializer.to_complex_serializable(item) for item in data]
case dict():
return {
BaseSerializer.to_serializable(
key
): BaseSerializer.to_complex_serializable(val)
for key, val in data.items()
}
case _:
return BaseSerializer.to_serializable(data)

@staticmethod
def dict_factory(data) -> dict[Union[str, int], Union[list, dict, int, str]]:
Expand Down
142 changes: 46 additions & 96 deletions netplanner/providers/networkd/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,44 +92,25 @@ def get_file_ending(data: list):

@staticmethod
def get_priority(interface_type: Base) -> int:
## Python 3.10 code
# match interface_type:
# case Ethernet():
# return 10
# case Bond():
# return 11
# case Dummy():
# return 11
# case VRF():
# return 12
# case Bridge():
# return 13
# case VXLAN():
# return 14
# case VLAN():
# return 15
# case Veth():
# return 16
# case _:
# return 17
if isinstance(interface_type, Ethernet):
return 10
elif isinstance(interface_type, Bond):
return 11
elif isinstance(interface_type, Dummy):
return 11
elif isinstance(interface_type, VRF):
return 12
elif isinstance(interface_type, Bridge):
return 13
elif isinstance(interface_type, VXLAN):
return 14
elif isinstance(interface_type, VLAN):
return 15
elif isinstance(interface_type, Veth):
return 16
else:
return 17
match interface_type:
case Ethernet():
return 10
case Bond():
return 11
case Dummy():
return 11
case VRF():
return 12
case Bridge():
return 13
case VXLAN():
return 14
case VLAN():
return 15
case Veth():
return 16
case _:
return 17

def __init__(self, config: NetplannerConfig, local=True, path: str = DEFAULT_PATH):
self.config: NetplannerConfig = config
Expand Down Expand Up @@ -161,64 +142,33 @@ def render_networks(self):
).items():
child_interfaces = {}
parent_interface = None
## Python 3.10 code
# match interface_config:
# case Bond():
# child_interfaces = {
# vlan_name: vlan_config
# for vlan_name, vlan_config in self.config.network.vlans.items()
# if interface_name == vlan_config.link
# }
# case Dummy():
# child_interfaces = {
# vxlan_name: vxlan_config
# for vxlan_name, vxlan_config in self.config.network.vxlans.items()
# if interface_name == vxlan_config.link
# }
# case VLAN() if interface_config.link is not None:
# parent_interface = self.config.network.lookup(
# interface_config.link
# )
# case Ethernet():
# parent_interface = {
# name: config
# for name, config in self.config.network.bonds.items()
# if interface_name in config.interfaces
# }
# case VXLAN():
# parent_interface = {
# name: config
# for name, config in self.config.network.bridges.items()
# if interface_name in config.interfaces
# }
if isinstance(interface_config, Bond):
child_interfaces = {
vlan_name: vlan_config
for vlan_name, vlan_config in self.config.network.vlans.items()
if interface_name == vlan_config.link
}
elif isinstance(interface_config, Dummy):
child_interfaces = {
vxlan_name: vxlan_config
for vxlan_name, vxlan_config in self.config.network.vxlans.items()
if interface_name == vxlan_config.link
}
elif (
isinstance(interface_config, VLAN) and interface_config.link is not None
):
parent_interface = self.config.network.lookup(interface_config.link)
elif isinstance(interface_config, Ethernet):
parent_interface = {
name: config
for name, config in self.config.network.bonds.items()
if interface_name in config.interfaces
}
elif isinstance(interface_config, VXLAN):
parent_interface = {
name: config
for name, config in self.config.network.bridges.items()
if interface_name in config.interfaces
}
match interface_config:
case Bond():
child_interfaces = {
vlan_name: vlan_config
for vlan_name, vlan_config in self.config.network.vlans.items()
if interface_name == vlan_config.link
}
case Dummy():
child_interfaces = {
vxlan_name: vxlan_config
for vxlan_name, vxlan_config in self.config.network.vxlans.items()
if interface_name == vxlan_config.link
}
case VLAN() if interface_config.link is not None:
parent_interface = self.config.network.lookup(interface_config.link)
case Ethernet():
parent_interface = {
name: config
for name, config in self.config.network.bonds.items()
if interface_name in config.interfaces
}
case VXLAN():
parent_interface = {
name: config
for name, config in self.config.network.bridges.items()
if interface_name in config.interfaces
}

if parent_interface is not None and len(parent_interface) > 1:
raise ValueError(
Expand Down
Loading