Skip to content

Commit

Permalink
remove sub interface to not remove parent interface
Browse files Browse the repository at this point in the history
  • Loading branch information
kthare10 committed Jul 8, 2024
1 parent 3691413 commit a3c3ea8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
FABRIC Information Model library and utilities
"""
__VERSION__ = "1.7.0b12"
__VERSION__ = "1.7.0b14"
__version__ = __VERSION__
5 changes: 3 additions & 2 deletions fim/graph/abc_property_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,11 +1162,12 @@ def remove_ns_with_cps_and_links(self, node_id: str):
for iif in interfaces:
self.remove_cp_and_links(node_id=iif)

def remove_cp_and_links(self, node_id: str):
def remove_cp_and_links(self, node_id: str, delete_parent: bool = True):
"""
Remove ConnectionPoint and links. Parent ConnectionPoints and links are removed
if they have no other children or other connected connection points.
:param node_id: interface node id
:param delete_parent: flag indicating deletion of parent if parent have no other interfaces.
:return:
"""
# some interfaces may have parent interfaces, which can be deleted if they only have the
Expand All @@ -1180,7 +1181,7 @@ def remove_cp_and_links(self, node_id: str):
children = self.get_first_neighbor(node_id=parent,
rel=ABCPropertyGraph.REL_CONNECTS,
node_label=ABCPropertyGraph.CLASS_ConnectionPoint)
if len(children) == 1: # if only child, can delete parent
if len(children) == 1 and delete_parent: # if only child, can delete parent
interfaces_to_delete.add(parent)
# interfaces themselves and parent interfaces
# may be connected to links which can be deleted if nothing
Expand Down
2 changes: 1 addition & 1 deletion fim/user/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def remove_child_interface(self, *, name: str) -> None:
node_id = self.topo.graph_model.find_child_connection_point_by_name(parent_node_id=self.node_id,
iname=name)

self.topo.graph_model.remove_cp_and_links(node_id=node_id)
self.topo.graph_model.remove_cp_and_links(node_id=node_id, delete_parent=False)

def __list_interfaces(self) -> ViewOnlyDict:
"""
Expand Down
3 changes: 2 additions & 1 deletion test/slice_topology_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,8 @@ def test_SubInterface_NetworkX(self):

ch2 = n1_nic1_interface1.add_child_interface(name="child2", labels=f.Labels(vlan="200"))

t.add_network_service(name="net1", nstype=f.ServiceType.L2Bridge, interfaces=[ch1, ch2])
t.add_network_service(name="net1", nstype=f.ServiceType.L2Bridge, interfaces=[ch1])
t.network_services["net1"].connect_interface(ch2)

t.validate()
t.network_services["net1"].disconnect_interface(ch1)
Expand Down

0 comments on commit a3c3ea8

Please sign in to comment.