Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Netplan state diff #386

Merged
merged 12 commits into from
Nov 29, 2023
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
1 change: 1 addition & 0 deletions netplan_cli/cli/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,7 @@ def __init__(self, subtree='all', rootdir='/'):

np_state = netplan.State()
np_state.import_parser_results(parser)
self.netdefs = np_state.netdefs

self.state = StringIO()

Expand Down
551 changes: 551 additions & 0 deletions netplan_cli/cli/state_diff.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions netplan_cli/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cli_sources = files(
'cli/core.py',
'cli/ovs.py',
'cli/state.py',
'cli/state_diff.py',
'cli/sriov.py',
'cli/utils.py')

Expand Down
21 changes: 20 additions & 1 deletion python-cffi/netplan/netdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def __next__(self):
return ffi.string(next_value).decode('utf-8')


@dataclass(unsafe_hash=True)
@dataclass
class NetplanRoute:
_METRIC_UNSPEC_ = lib.UINT_MAX
_TABLE_UNSPEC_ = 0
Expand Down Expand Up @@ -298,6 +298,25 @@ def to_dict(self):

return route

def __hash__(self):
return hash(
(self.to, self.via,
self.from_addr, self.table,
self.family, self.metric,
self.type, self.scope))

def __eq__(self, route):
slyon marked this conversation as resolved.
Show resolved Hide resolved
return (
self.to == route.to and
self.via == route.via and
self.from_addr == route.from_addr and
self.table == route.table and
self.family == route.family and
self.metric == route.metric and
self.type == route.type and
self.scope == route.scope
)


class _NetdefRouteIterator:
def __init__(self, netdef):
Expand Down
Loading
Loading