Fix warnings reported by gen_doc.sh
[csit.git] / resources / libraries / python / topology.py
index 4ff68ec..2f4fd02 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (c) 2016 Cisco and/or its affiliates.
+# Copyright (c) 2018 Cisco and/or its affiliates.
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
 # You may obtain a copy of the License at:
@@ -21,7 +21,7 @@ from robot.api import logger
 from robot.libraries.BuiltIn import BuiltIn, RobotNotRunningError
 from robot.api.deco import keyword
 
-__all__ = ["DICT__nodes", 'Topology']
+__all__ = ["DICT__nodes", 'Topology', 'NodeType']
 
 
 def load_topo_from_yaml():
@@ -71,6 +71,7 @@ class Topology(object):
     "Active topology" contains initially data from the topology file and can be
     extended with additional data from the DUTs like internal interface indexes
     or names. Additional data which can be filled to the active topology are
+
         - additional internal representation (index, name, ...)
         - operational data (dynamic ports)
 
@@ -136,7 +137,7 @@ class Topology(object):
         :type nodes: dict
         :returns: Nothing
         """
-        port_types = ('subinterface', 'vlan_subif',  'memif', 'tap', 'vhost',
+        port_types = ('subinterface', 'vlan_subif', 'memif', 'tap', 'vhost',
                       'loopback', 'gre_tunnel', 'vxlan_tunnel')
 
         for node_data in nodes.values():
@@ -349,11 +350,11 @@ class Topology(object):
 
         :param node: The node topology directory.
         :param link_names: List of names of the link that a interface is
-        connected to.
+            connected to.
         :type node: dict
         :type link_names: list
         :returns: Dictionary of interface names that are connected to the given
-        links.
+            links.
         :rtype: dict
         """
         retval = {}
@@ -465,8 +466,7 @@ class Topology(object):
 
         :param node: Node in topology.
         :param interface: Name, sw_if_index, link name or key of an interface
-        on the node.
-        Valid formats are: sw_if_index, key, name.
+            on the node.
         :type node: dict
         :type interface: str or int
 
@@ -505,16 +505,14 @@ class Topology(object):
 
         :param node: Node in topology.
         :param interface: Name, sw_if_index, link name or key of an interface
-        on the node.
+            on the node.
         :param wanted_format: Format of return value wanted.
-        Valid options are: sw_if_index, key, name.
+            Valid options are: sw_if_index, key, name.
         :type node: dict
         :type interface: str or int
         :type wanted_format: str
-
         :returns: Interface name, interface key or sw_if_index.
         :rtype: str or int
-
         :raises TypeError, ValueError: If provided with invalid arguments.
         :raises RuntimeError: If the interface does not exist in topology.
         """
@@ -599,13 +597,28 @@ class Topology(object):
         except KeyError:
             return None
 
+    @staticmethod
+    def get_interface_ip4(node, iface_key):
+        """Get IP4 address for the interface.
+
+        :param node: Node to get interface mac on.
+        :param iface_key: Interface key from topology file.
+        :type node: dict
+        :type iface_key: str
+        :returns: Return IP4 or None if not found.
+        """
+        try:
+            return node['interfaces'][iface_key].get('ip4_address', None)
+        except KeyError:
+            return None
+
     @staticmethod
     def get_adjacent_node_and_interface(nodes_info, node, iface_key):
         """Get node and interface adjacent to specified interface
         on local network.
 
         :param nodes_info: Dictionary containing information on all nodes
-        in topology.
+            in topology.
         :param node: Node that contains specified interface.
         :param iface_key: Interface key from topology file.
         :type nodes_info: dict
@@ -771,7 +784,7 @@ class Topology(object):
         :type node2: dict
         :returns: Name of link connecting the two nodes together.
         :rtype: str
-        :raises: RuntimeError
+        :raises RuntimeError: If no links are found.
         """
         connecting_links = self.get_active_connecting_links(node1, node2)
         if len(connecting_links) == 0:
@@ -889,6 +902,22 @@ class Topology(object):
         """
         return node['host']
 
+    @staticmethod
+    def get_node_arch(node):
+        """Return arch of the node.
+           Default to x86_64 if no arch present
+
+        :param node: Node created from topology.
+        :type node: dict
+        :returns: Node architecture
+        :rtype: str
+        """
+        try:
+            return node['arch']
+        except KeyError:
+            node['arch'] = 'x86_64'
+            return 'x86_64'
+
     @staticmethod
     def get_cryptodev(node):
         """Return Crytodev configuration of the node.