diff --git a/fim/__init__.py b/fim/__init__.py index 63c1827..08cb9bc 100644 --- a/fim/__init__.py +++ b/fim/__init__.py @@ -1,2 +1,2 @@ # -__VERSION__ = "1.0.5" +__VERSION__ = "1.0.7" diff --git a/fim/user/component.py b/fim/user/component.py index 7b2b451..a7c1e4a 100644 --- a/fim/user/component.py +++ b/fim/user/component.py @@ -115,7 +115,7 @@ def __init__(self, *, name: str, node_id: str = None, topo: Any, raise RuntimeError(f"Component with this id and name {name} doesn't exist") @property - def ctype(self): + def type(self): return self.get_property('type') if self.__dict__.get('topo', None) is not None else None @property diff --git a/fim/user/topology.py b/fim/user/topology.py index c87d4c0..2149896 100644 --- a/fim/user/topology.py +++ b/fim/user/topology.py @@ -111,8 +111,12 @@ def get_parent_element(self, e: ModelElement) -> ModelElement or None: parent=ABCPropertyGraph.CLASS_NetworkNode) if node_id is not None: return Node(name=node_name, node_id=node_id, topo=self) - else: - return None + + node_name, node_id = self.graph_model.get_parent(node_id=e.node_id, + rel=ABCPropertyGraph.REL_HAS, + parent=ABCPropertyGraph.CLASS_CompositeNode) + if node_id is not None: + return CompositeNode(name=node_name, node_id=node_id, topo=self) # interfaces have NSs as parents if isinstance(e, Interface): node_name, node_id = self.graph_model.get_parent(node_id=e.node_id, @@ -516,23 +520,23 @@ def __str__(self): """ lines = list() for n in self.nodes.values(): - lines.append(n.name + "[" + str(n.get_property("type")) + ", " + - str(n.get_property("site")) + "]: " + - self.__print_caplabs__(n.get_property("capacities"))) + lines.append(n.name + "[" + str(n.type) + ", " + + str(n.site) + "]: " + + self.__print_caplabs__(n.capacities)) for i in n.direct_interfaces.values(): - lines.append("\t\t" + i.name + ": " + str(i.get_property("type")) + " " + - self.__print_caplabs__(i.get_property("capacities")) + " " + - self.__print_caplabs__(i.get_property("labels"))) + lines.append("\t\t" + i.name + ": " + str(i.type) + " " + + self.__print_caplabs__(i.capacities) + " " + + self.__print_caplabs__(i.labels)) for c in n.components.values(): - lines.append("\t" + c.name + ": " + " " + str(c.get_property("type")) + " " + - c.get_property("model")) + lines.append("\t" + c.name + ": " + " " + str(c.type) + " " + + c.model) for i in c.interfaces.values(): - lines.append("\t\t" + i.name + ": " + str(i.get_property("type")) + " " + - self.__print_caplabs__(i.get_property("capacities"))) + lines.append("\t\t" + i.name + ": " + str(i.type) + " " + + self.__print_caplabs__(i.capacities)) lines.append("Links:") for l in self.links.values(): interface_names = [iff.name for iff in l.interface_list] - lines.append("\t" + l.name + "[" + str(l.get_property("type")) + "]: " + + lines.append("\t" + l.name + "[" + str(l.type) + "]: " + str(interface_names)) return "\n".join(lines) @@ -750,6 +754,14 @@ def __list_links(self) -> ViewOnlyDict: def sites(self): return self.__list_sites() + @property + def nodes(self): + """ + Same as sites property + :return: + """ + return self.__list_sites() + @property def links(self): return self.__list_links() @@ -841,28 +853,31 @@ def __str__(self): """ lines = list() for n in self.sites.values(): - tot_cap = n.get_property("capacities") - alloc_cap = n.get_property("capacity_allocations") - if tot_cap is not None and alloc_cap is not None: + tot_cap = n.capacities + alloc_cap = n.get_property('capacity_allocations') + if alloc_cap is None: + # if nothing is allocated, just zero out + alloc_cap = Capacities() + if tot_cap is not None: ncp = CapacityTuple(total=tot_cap, allocated=alloc_cap) lines.append(n.name + ": " + str(ncp)) else: lines.append(n.name) lines.append("\tComponents:") for c in n.components.values(): - ccp = CapacityTuple(total=c.get_property("capacities"), + ccp = CapacityTuple(total=c.capacities, allocated=c.get_property("capacity_allocations")) lines.append("\t\t" + c.name + ": " + " " + str(c.get_property("type")) + " " + - c.get_property("model") + " " + str(ccp)) + c.model + " " + str(ccp)) lines.append("\tSite Interfaces:") for i in n.interfaces.values(): - icp = CapacityTuple(total=i.get_property("capacities"), + icp = CapacityTuple(total=i.capacities, allocated=i.get_property("capacity_allocations")) lines.append("\t\t" + i.name + ": " + str(i.get_property("type")) + " " + str(icp)) lines.append("Links:") for l in self.links.values(): interface_names = [iff.name for iff in l.interface_list] - lines.append("\t" + l.name + "[" + str(l.get_property("type")) + "]: " + + lines.append("\t" + l.name + "[" + str(l.type) + "]: " + str(interface_names)) return "\n".join(lines) diff --git a/test/ad_topology_test.py b/test/ad_topology_test.py new file mode 100644 index 0000000..b6f82fe --- /dev/null +++ b/test/ad_topology_test.py @@ -0,0 +1,17 @@ +import unittest + +import fim.user as f + + +class SliceTest(unittest.TestCase): + + def setUp(self): + pass + + def tearDown(self) -> None: + pass + + def testAd(self) -> None: + self.topo = f.AdvertisedTopology(graph_file='test/models/advertised_topo.graphml') + self.assertEqual(self.topo.get_owner_node(self.topo.links['port+lbnl-data-sw:HundredGigE0/0/0/0.2401-link'].interface_list[0]).name, 'UKY') + diff --git a/test/models/advertised_topo.graphml b/test/models/advertised_topo.graphml new file mode 100644 index 0000000..baa7b5a --- /dev/null +++ b/test/models/advertised_topo.graphml @@ -0,0 +1,424 @@ + + + + + + + + + + + + + + + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + CompositeNode + 47d1647e-d2cf-479d-b529-3f28d6c03eea + UKY + Server + {"core": 192, "cpu": 6, "disk": 9600, "ram": 1536, "unit": 3} + false + UKY + {"postal": "301 Hilltop Ave Lexington, KY 40506"} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + NetworkService + d7dd4be8-8967-4609-b144-502f73362725 + UKY_ns + MPLS + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + d114cb1a-a27f-427f-a919-43c973edf1a6 + SmartNIC-ConnectX-6 + SmartNIC + ConnectX-6 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 97f54576-fb89-42de-b9f1-cf21964354ab + SmartNIC-ConnectX-5 + SmartNIC + ConnectX-5 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 5071670f-6de4-4b8d-968e-4ca2b0fce996 + NVME-P4510 + NVME + P4510 + {"disk": 10000, "unit": 10} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 49e79526-aff3-4854-8dfe-17e91b64c894 + GPU-Tesla T4 + GPU + Tesla T4 + {"unit": 4} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + ac4a947c-df9f-4d0f-9885-6ed91c29968c + GPU-RTX6000 + GPU + RTX6000 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 0b1cf83d-f9ef-4a65-804b-991748b9e3e0 + SharedNIC-ConnectX-6 + SharedNIC + ConnectX-6 + {"unit": 381} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + CompositeNode + 63490b14-132b-47c1-98c9-07dc19921d9e + LBNL + Server + {"core": 192, "cpu": 6, "disk": 9600, "ram": 1536, "unit": 3} + {"core": 2, "disk": 10, "ram": 6} + false + LBNL + {"postal": "1 Cyclotron Rd, Berkeley, CA 94720"} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + NetworkService + 19029356-785b-4a02-b322-411295c5e15a + LBNL_ns + MPLS + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + a9910828-3df3-4ea7-93b6-a85db8703747 + NVME-P4510 + NVME + P4510 + {"disk": 10000, "unit": 10} + {"disk": 1000, "unit": 1} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + b7b098a4-e018-4bfb-a333-bad39937ab99 + SharedNIC-ConnectX-6 + SharedNIC + ConnectX-6 + {"unit": 381} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 1dc2681e-aa7d-4209-a7a6-a6c2ea05aaca + GPU-RTX6000 + GPU + RTX6000 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 2eeaf48d-9cc0-4f49-abc6-8753a3172150 + GPU-Tesla T4 + GPU + Tesla T4 + {"unit": 4} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 615c01f1-be8d-4100-858a-e2c190d4a6ae + SmartNIC-ConnectX-6 + SmartNIC + ConnectX-6 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + c5f3c2d0-d1f2-40bc-8da5-f9d865a0b983 + SmartNIC-ConnectX-5 + SmartNIC + ConnectX-5 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + CompositeNode + 5fc69003-bfa0-4c3d-ae14-d1a4bc604583 + RENC + Server + {"core": 192, "cpu": 6, "disk": 14400, "ram": 1536, "unit": 3} + false + RENC + {"postal": "100 Europa Dr., Chapel Hill, NC 27517"} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + NetworkService + 4ff6c7b7-956f-4868-8d20-954af5dbb432 + RENC_ns + MPLS + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 6704ed7d-7454-41e8-9e37-c920d99da703 + SmartNIC-ConnectX-5 + SmartNIC + ConnectX-5 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 8862aaaa-a89e-4fdb-82b4-a63e5be455a3 + SmartNIC-ConnectX-6 + SmartNIC + ConnectX-6 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 85443ae4-7fd6-4513-9f07-1e7cd12def6f + NVME-P4510 + NVME + P4510 + {"disk": 10000, "unit": 10} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + d39c513b-726d-4c07-b70e-ffbd6e020232 + GPU-Tesla T4 + GPU + Tesla T4 + {"unit": 4} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + bbb11abc-04fc-413c-8671-1c4a597e6d84 + GPU-RTX6000 + GPU + RTX6000 + {"unit": 2} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Component + 843083ff-2d6b-4f4c-a60e-1741010b93b2 + SharedNIC-ConnectX-6 + SharedNIC + ConnectX-6 + {"unit": 381} + false + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + ConnectionPoint + c4b4fa05-2547-4889-a8d5-8eeef38cc659 + UKY_LBNL + TrunkPort + {"bw": 100} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + ConnectionPoint + 768fb884-1373-4f20-a31c-b7bb106b90b0 + LBNL_UKY + TrunkPort + {"bw": 100} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Link + link:local-port+lbnl-data-sw:HundredGigE0/0/0/0.2401:remote-port+uky-data-sw:HundredGigE0/0/0/0.851 + port+lbnl-data-sw:HundredGigE0/0/0/0.2401-link + L2Path + L2 + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + ConnectionPoint + 693ccd57-990e-47e6-91ae-70dd0478ffed + RENC_LBNL + TrunkPort + {"bw": 10} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + ConnectionPoint + d4740c0e-fa46-4aa1-be8c-88a99d781cbf + LBNL_RENC + TrunkPort + {"bw": 100} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Link + link:local-port+lbnl-data-sw:HundredGigE0/0/0/0.2400:remote-port+renc-data-sw:TenGigE0/0/0/2/0.3981 + port+lbnl-data-sw:HundredGigE0/0/0/0.2400-link + L2Path + L2 + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + ConnectionPoint + 353ee0e1-c160-48dd-baed-4d09da13507b + UKY_RENC + TrunkPort + {"bw": 100} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + ConnectionPoint + 0f7e8805-653d-46cc-846e-41de6679f594 + RENC_UKY + TrunkPort + {"bw": 10} + + + 785bdecd-2bac-49e2-8469-e652f5207e32 + Link + link:local-port+renc-data-sw:TenGigE0/0/0/2/0.3999:remote-port+uky-data-sw:HundredGigE0/0/0/0.859 + port+renc-data-sw:TenGigE0/0/0/2/0.3999-link + L2Path + L2 + + + has + + + has + + + has + + + has + + + has + + + has + + + has + + + connects + + + connects + + + has + + + has + + + has + + + has + + + has + + + has + + + has + + + connects + + + connects + + + has + + + has + + + has + + + has + + + has + + + has + + + has + + + connects + + + connects + + + connects + + + connects + + + connects + + + connects + + + connects + + + connects + + + \ No newline at end of file