X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2Ftopology.py;h=13dbdddb07f0f6e29975073429669264fde56c5d;hp=4ff68ec43df07be95a53c7ed0f90e5603e387b25;hb=c7eb2002bcd007520309feb3e11a26ff847a4e05;hpb=7bfb36dfd9284bbca10881e31e14108c7d468b7c diff --git a/resources/libraries/python/topology.py b/resources/libraries/python/topology.py index 4ff68ec43d..13dbdddb07 100644 --- a/resources/libraries/python/topology.py +++ b/resources/libraries/python/topology.py @@ -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(): @@ -136,7 +136,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(): @@ -599,6 +599,21 @@ 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 @@ -889,6 +904,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.